lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250822233642.69d25aa9@gandalf.local.home>
Date: Fri, 22 Aug 2025 23:36:42 -0400
From: Steven Rostedt <rostedt@...dmis.org>
To: LKML <linux-kernel@...r.kernel.org>
Cc: Masami Hiramatsu <mhiramat@...nel.org>, Mathieu Desnoyers
 <mathieu.desnoyers@...icios.com>, Tengda Wu <wutengda@...weicloud.com>,
 Nathan Chancellor <nathan@...nel.org>
Subject: [for-linus][PATCH] ftrace: Also allocate and copy hash for reading
 of filter files


  git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
trace/fixes

Head SHA1: bfb336cf97df7b37b2b2edec0f69773e06d11955


Steven Rostedt (1):
      ftrace: Also allocate and copy hash for reading of filter files

----
 kernel/trace/ftrace.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
---------------------------
commit bfb336cf97df7b37b2b2edec0f69773e06d11955
Author: Steven Rostedt <rostedt@...dmis.org>
Date:   Fri Aug 22 18:36:06 2025 -0400

    ftrace: Also allocate and copy hash for reading of filter files
    
    Currently the reader of set_ftrace_filter and set_ftrace_notrace just adds
    the pointer to the global tracer hash to its iterator. Unlike the writer
    that allocates a copy of the hash, the reader keeps the pointer to the
    filter hashes. This is problematic because this pointer is static across
    function calls that release the locks that can update the global tracer
    hashes. This can cause UAF and similar bugs.
    
    Allocate and copy the hash for reading the filter files like it is done
    for the writers. This not only fixes UAF bugs, but also makes the code a
    bit simpler as it doesn't have to differentiate when to free the
    iterator's hash between writers and readers.
    
    Cc: stable@...r.kernel.org
    Cc: Masami Hiramatsu <mhiramat@...nel.org>
    Cc: Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
    Cc: Nathan Chancellor <nathan@...nel.org>
    Cc: Linus Torvalds <torvalds@...ux-foundation.org>
    Link: https://lore.kernel.org/20250822183606.12962cc3@batman.local.home
    Fixes: c20489dad156 ("ftrace: Assign iter->hash to filter or notrace hashes on seq read")
    Closes: https://lore.kernel.org/all/20250813023044.2121943-1-wutengda@huaweicloud.com/
    Closes: https://lore.kernel.org/all/20250822192437.GA458494@ax162/
    Reported-by: Tengda Wu <wutengda@...weicloud.com>
    Tested-by: Tengda Wu <wutengda@...weicloud.com>
    Tested-by: Nathan Chancellor <nathan@...nel.org>
    Signed-off-by: Steven Rostedt (Google) <rostedt@...dmis.org>

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 00b76d450a89..a69067367c29 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -4661,13 +4661,17 @@ ftrace_regex_open(struct ftrace_ops *ops, int flag,
 	        } else {
 			iter->hash = alloc_and_copy_ftrace_hash(size_bits, hash);
 		}
+	} else {
+		if (hash)
+			iter->hash = alloc_and_copy_ftrace_hash(hash->size_bits, hash);
+		else
+			iter->hash = EMPTY_HASH;
+	}
 
-		if (!iter->hash) {
-			trace_parser_put(&iter->parser);
-			goto out_unlock;
-		}
-	} else
-		iter->hash = hash;
+	if (!iter->hash) {
+		trace_parser_put(&iter->parser);
+		goto out_unlock;
+	}
 
 	ret = 0;
 
@@ -6543,9 +6547,6 @@ int ftrace_regex_release(struct inode *inode, struct file *file)
 		ftrace_hash_move_and_update_ops(iter->ops, orig_hash,
 						      iter->hash, filter_hash);
 		mutex_unlock(&ftrace_lock);
-	} else {
-		/* For read only, the hash is the ops hash */
-		iter->hash = NULL;
 	}
 
 	mutex_unlock(&iter->ops->func_hash->regex_lock);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ