From nobody Sun Dec 14 12:18:19 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B65C4224894 for ; Fri, 18 Apr 2025 18:33:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745001226; cv=none; b=PKyoLHK1sAg8I9xB545s9TsD854ENaSvlaC+X8bJI2yZmF/ox9iq4kMqkpsGIYq6oi5P5MR9zrE+geB4yoDkYrfWjdwSTla3uFO4Q4pKVaDFtiUVyOu8hKb62tlC54hN9KzI6BId3SmFBhet1QpdSvmVARr4cavIqNc6FOtvz0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745001226; c=relaxed/simple; bh=S6+Kixs9MzJQRJqyOL1vA5/PhSdO6rHl/th6ek9UFsE=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=TmbBi8SQJj6o3FFk9GkJg/UH0+Il+TJ22eDM+yazKp235vPxDS6b4DWWR3L+Ns2ebPzUUmUDRq15ZfIcIO3Lana1/p1SB09l77+MYVF4t694B3z2ApwtQkXG3uG8EzmifN82MxFLZkpaPW9RH2x5iTLj3spmfFfE81JEXJRwWuM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4707DC4CEEA; Fri, 18 Apr 2025 18:33:46 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1u5qYi-0000000Db7E-1AHc; Fri, 18 Apr 2025 14:35:28 -0400 Message-ID: <20250418183528.128091434@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 18 Apr 2025 14:34:47 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Venkat Rao Bagalkote Subject: [for-linus][PATCH 1/7] ftrace: Initialize variables for ftrace_startup/shutdown_subops() References: <20250418183446.383784216@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The reworking to fix and simplify the ftrace_startup_subops() and the ftrace_shutdown_subops() made it possible for the filter_hash and notrace_hash variables to be used uninitialized in a way that the compiler did not catch it. Initialize both filter_hash and notrace_hash to the EMPTY_HASH as that is what they should be if they never are used. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Link: https://lore.kernel.org/20250417104017.3aea66c2@gandalf.local.home Reported-by: Venkat Rao Bagalkote Tested-by: Venkat Rao Bagalkote Fixes: 0ae6b8ce200d ("ftrace: Fix accounting of subop hashes") Closes: https://lore.kernel.org/all/1db64a42-626d-4b3a-be08-c65e47333ce2@li= nux.ibm.com/ Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index a8a02868b435..43394445390c 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -3490,8 +3490,8 @@ static int add_next_hash(struct ftrace_hash **filter_= hash, struct ftrace_hash ** */ int ftrace_startup_subops(struct ftrace_ops *ops, struct ftrace_ops *subop= s, int command) { - struct ftrace_hash *filter_hash; - struct ftrace_hash *notrace_hash; + struct ftrace_hash *filter_hash =3D EMPTY_HASH; + struct ftrace_hash *notrace_hash =3D EMPTY_HASH; struct ftrace_hash *save_filter_hash; struct ftrace_hash *save_notrace_hash; int ret; @@ -3625,8 +3625,8 @@ static int rebuild_hashes(struct ftrace_hash **filter= _hash, struct ftrace_hash * */ int ftrace_shutdown_subops(struct ftrace_ops *ops, struct ftrace_ops *subo= ps, int command) { - struct ftrace_hash *filter_hash; - struct ftrace_hash *notrace_hash; + struct ftrace_hash *filter_hash =3D EMPTY_HASH; + struct ftrace_hash *notrace_hash =3D EMPTY_HASH; int ret; =20 if (unlikely(ftrace_disabled)) --=20 2.47.2 From nobody Sun Dec 14 12:18:19 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6510215F48 for ; Fri, 18 Apr 2025 18:33:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745001226; cv=none; b=rP461nh2QzoisnJ4IvVOBXsX3v0Xsot+BGjlBdwIe3dmyC8w/g9RyhOcqEHf45d+Y2vgdikvzUKvy+QaF88qDz9cGWQdNDqS2o5E+cGBzOFHiFBwYk2Pkgai8T/Oz5NTI7Nmx2HQd45rxvuJXers8Q6bWI/GBUME0VamOilMoAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745001226; c=relaxed/simple; bh=EBaTiX+dfxsPN83en/R/JsxwKPbYDZy60fWfphErIg8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=BHNDjuaR4WA+jX0QhT3r5y5Kl5ASeFV4eGk8WlEeTzBEXH0tIb3P30Blag08BTrvpEkn1j5YCco5aH4cyyR3/m0Zxk1fSWqLqMCtWqaYaqUFiWYZkPO1p/SIHWiefvdMRrkcGloR1+fj+OhiBvnw2c/bIqc6G/kSEdFxeyvexWs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66953C4CEEE; Fri, 18 Apr 2025 18:33:46 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1u5qYi-0000000Db7i-1sTw; Fri, 18 Apr 2025 14:35:28 -0400 Message-ID: <20250418183528.298934811@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 18 Apr 2025 14:34:48 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-linus][PATCH 2/7] ftrace: Reinitialize hash to EMPTY_HASH after freeing References: <20250418183446.383784216@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt There's several locations that free a ftrace hash pointer but may be referenced again. Reset them to EMPTY_HASH so that a u-a-f bug doesn't happen. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Link: https://lore.kernel.org/20250417110933.20ab718b@gandalf.local.home Fixes: 0ae6b8ce200d ("ftrace: Fix accounting of subop hashes") Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 43394445390c..d0e4a902bb40 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -1297,6 +1297,8 @@ void ftrace_free_filter(struct ftrace_ops *ops) return; free_ftrace_hash(ops->func_hash->filter_hash); free_ftrace_hash(ops->func_hash->notrace_hash); + ops->func_hash->filter_hash =3D EMPTY_HASH; + ops->func_hash->notrace_hash =3D EMPTY_HASH; } EXPORT_SYMBOL_GPL(ftrace_free_filter); =20 @@ -3443,6 +3445,7 @@ static int add_next_hash(struct ftrace_hash **filter_= hash, struct ftrace_hash ** size_bits); if (ret < 0) { free_ftrace_hash(*filter_hash); + *filter_hash =3D EMPTY_HASH; return ret; } } @@ -3472,6 +3475,7 @@ static int add_next_hash(struct ftrace_hash **filter_= hash, struct ftrace_hash ** subops_hash->notrace_hash); if (ret < 0) { free_ftrace_hash(*notrace_hash); + *notrace_hash =3D EMPTY_HASH; return ret; } } --=20 2.47.2 From nobody Sun Dec 14 12:18:19 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13308225A40 for ; Fri, 18 Apr 2025 18:33:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745001227; cv=none; b=Cg4d+D+h2QOLoKR9H+T/E4BLqYqIO/H2oERtPsm873MiYC5TwrNHr5FwW1cpQwCB2CwKS7ARJi54AMMADVvy0BGv2IR7aFFgQlVbUnVJDqzm1Ilqa/IclzcEB86uxF0NkRp4DeKoYt/YvsTda8AZ5LWZjyic3y77fMtdphff/gE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745001227; c=relaxed/simple; bh=uhtNNEK3AzOJ+nkTlNvjXHmDg+41VU+N5ya7K2e9R9Y=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=biDQ4BIJjQzDFSkPFl5te6u1TFRyJjUd6iGlE3j0xRdG65g2YgNhELB3G1WE/BK1o086ixCP/lrekzD8ftV8HHVGFOmCYG4Zfyggg2O1Z/Wdz1Xtt7IahdXzkP89ZVpK0iuoou2QLWw/zMxCAAqbYj8GuUt6t07/BvEbjuF++ZY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5C5FC4CEF0; Fri, 18 Apr 2025 18:33:46 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1u5qYi-0000000Db8C-2bP4; Fri, 18 Apr 2025 14:35:28 -0400 Message-ID: <20250418183528.469164383@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 18 Apr 2025 14:34:49 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-linus][PATCH 3/7] ftrace: Free ftrace hashes after they are replaced in the subops code References: <20250418183446.383784216@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The subops processing creates new hashes when adding and removing subops. There were some places that the old hashes that were replaced were not freed and this caused some memory leaks. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Link: https://lore.kernel.org/20250417135939.245b128d@gandalf.local.home Fixes: 0ae6b8ce200d ("ftrace: Fix accounting of subop hashes") Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index d0e4a902bb40..41dcfcf8b40a 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -3609,6 +3609,9 @@ static int rebuild_hashes(struct ftrace_hash **filter= _hash, struct ftrace_hash * } } =20 + free_ftrace_hash(temp_hash.filter_hash); + free_ftrace_hash(temp_hash.notrace_hash); + temp_hash.filter_hash =3D *filter_hash; temp_hash.notrace_hash =3D *notrace_hash; } @@ -3703,8 +3706,11 @@ static int ftrace_hash_move_and_update_subops(struct= ftrace_ops *subops, } =20 ret =3D rebuild_hashes(&filter_hash, ¬race_hash, ops); - if (!ret) + if (!ret) { ret =3D ftrace_update_ops(ops, filter_hash, notrace_hash); + free_ftrace_hash(filter_hash); + free_ftrace_hash(notrace_hash); + } =20 if (ret) { /* Put back the original hash */ --=20 2.47.2 From nobody Sun Dec 14 12:18:19 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D3E522655E for ; Fri, 18 Apr 2025 18:33:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745001227; cv=none; b=K/3qi+A8OcupLJtxAbc+dCYzaKsCO4pWcFwYSEYz3OowhPV9oIk06JHncxLuWwwR8eL22GStuUwMyo01YaeCstRv847FwOREppHVtEvva/svTZeNTUkIjPMR39hf6N6r3frpyYMf9d/+514QL+kDp7ULI0LqcFH/n6A45xdfaPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745001227; c=relaxed/simple; bh=jf0DU+6h9rnSZB7DYtznNBJdGDCP6iBZN4msHkgK7vE=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=HxAoSgrn4+UAh5OTvEOLBNDRUcoffJvR2iHABVkdc3oBR669fZAlRjir5WDgJBLxZWdQCirrMVXul2Ffql6deMe8JtQQjAedilQ6VeBSiQMdNjM6czqlhZfSlpwP9EDph/nOUZqsW9E2vIRDv7ylG857YOWmf/pm1VE0REVMUqo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C737DC4CEED; Fri, 18 Apr 2025 18:33:46 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1u5qYi-0000000Db8g-3KMX; Fri, 18 Apr 2025 14:35:28 -0400 Message-ID: <20250418183528.642049027@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 18 Apr 2025 14:34:50 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Menglong Dong Subject: [for-linus][PATCH 4/7] ftrace: fix incorrect hash size in register_ftrace_direct() References: <20250418183446.383784216@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Menglong Dong The maximum of the ftrace hash bits is made fls(32) in register_ftrace_direct(), which seems illogical. So, we fix it by making the max hash bits FTRACE_HASH_MAX_BITS instead. Link: https://lore.kernel.org/20250413014444.36724-1-dongml2@chinatelecom.cn Fixes: d05cb470663a ("ftrace: Fix modification of direct_function hash whil= e in use") Signed-off-by: Menglong Dong Acked-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 41dcfcf8b40a..61130bb34d6c 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -5964,9 +5964,10 @@ int register_ftrace_direct(struct ftrace_ops *ops, u= nsigned long addr) =20 /* Make a copy hash to place the new and the old entries in */ size =3D hash->count + direct_functions->count; - if (size > 32) - size =3D 32; - new_hash =3D alloc_ftrace_hash(fls(size)); + size =3D fls(size); + if (size > FTRACE_HASH_MAX_BITS) + size =3D FTRACE_HASH_MAX_BITS; + new_hash =3D alloc_ftrace_hash(size); if (!new_hash) goto out_unlock; =20 --=20 2.47.2 From nobody Sun Dec 14 12:18:19 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5126C226CF9 for ; Fri, 18 Apr 2025 18:33:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745001227; cv=none; b=TpPugmnte3y6oCIENMgdP5T0iGF2QuqdmrIUp9RkAc98o/QEDkszpyTKRJ3azBwQjCxvybQYP/RqbStiwDr2XQGBGSsXiDS8Js+2ArQEg28e412z7nnrmOgoc2523xB7zv/slC3DiyXZtn1lfw56S34wO24umQ/a33fAGUtxsaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745001227; c=relaxed/simple; bh=kc4nvELlaIu42Fc/h5Y58hmSnnLBUd+sg2L+gOeJlXc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=qkEu87a4foo9x1Zwg/6bXnBJIYolncGa5YyQGB2Qbi97CxPRtZ4MOBHgjn7nyAOyskzjgGJ9f5LyuAWJ7ouICsV9H4mRzSpokMOnbFTtdWQjc4KSsXkCRKC+4htRPqaw5Dfysw7iHrgj1003en6ZhALmqAy0/bIag+1Np4yxO18= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0031BC4CEEA; Fri, 18 Apr 2025 18:33:46 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1u5qYi-0000000Db9A-43qB; Fri, 18 Apr 2025 14:35:28 -0400 Message-ID: <20250418183528.814181179@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 18 Apr 2025 14:34:51 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Sven Schnelle , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Ilya Leoshkevich Subject: [for-linus][PATCH 5/7] ftrace: Fix type of ftrace_graph_ent_entry.depth References: <20250418183446.383784216@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ilya Leoshkevich ftrace_graph_ent.depth is int, but ftrace_graph_ent_entry.depth is unsigned long. This confuses trace-cmd on 64-bit big-endian systems and makes it print a huge amount of spaces. Fix this by using unsigned int, which has a matching size, instead. Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Sven Schnelle Cc: Heiko Carstens Cc: Vasily Gorbik Cc: Alexander Gordeev Link: https://lore.kernel.org/20250412221847.17310-2-iii@linux.ibm.com Fixes: ff5c9c576e75 ("ftrace: Add support for function argument to graph tr= acer") Signed-off-by: Ilya Leoshkevich Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_entries.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_entries.h b/kernel/trace/trace_entries.h index ee40d4e6ad1c..4ef4df6623a8 100644 --- a/kernel/trace/trace_entries.h +++ b/kernel/trace/trace_entries.h @@ -80,11 +80,11 @@ FTRACE_ENTRY(funcgraph_entry, ftrace_graph_ent_entry, F_STRUCT( __field_struct( struct ftrace_graph_ent, graph_ent ) __field_packed( unsigned long, graph_ent, func ) - __field_packed( unsigned long, graph_ent, depth ) + __field_packed( unsigned int, graph_ent, depth ) __dynamic_array(unsigned long, args ) ), =20 - F_printk("--> %ps (%lu)", (void *)__entry->func, __entry->depth) + F_printk("--> %ps (%u)", (void *)__entry->func, __entry->depth) ); =20 #ifdef CONFIG_FUNCTION_GRAPH_RETADDR --=20 2.47.2 From nobody Sun Dec 14 12:18:19 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 512C8226CFC; Fri, 18 Apr 2025 18:33:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745001227; cv=none; b=QwR5KN/abgqQpnxdFjEhAVuUgWPk8lTJWiK5LlC7Nxy/ZF2pLTrH6h2I475VNQUUd9Vlth1r8X8+S3DmBEg77kGBxc4blvm5tTfnDy7O9HTEZnueWr9m/zzZdzpXZdjaRVNH8u9h7VRrWAvb/DwO7+sDhMfeajzd2J6CU1spiQ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745001227; c=relaxed/simple; bh=mAHbmri/ydJCCCNyZ8TtbhRs/REQDtNLw4Sz7n+2K7k=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Ju3kEU0UkIHv9mcx3leeUdcltyiceYPdPkjrRQW1rIBSWS0F4D/zGSRjiG55Ga55ob2FypQBPu5wqleJXnY9xilfXixAYpzYI3L08WXoWv7/m4hnrc9IOV+NBV4jwL5Yray0TKyJTGarpNTAFpKxzWKmKEoyEzOKQps/GvLQKmI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11BFCC4CEEF; Fri, 18 Apr 2025 18:33:47 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1u5qYj-0000000Db9e-0agq; Fri, 18 Apr 2025 14:35:29 -0400 Message-ID: <20250418183528.990167813@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 18 Apr 2025 14:34:52 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Andrii Nakryiko , Mykyta Yatsenko Subject: [for-linus][PATCH 6/7] tracing: Fix filter string testing References: <20250418183446.383784216@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The filter string testing uses strncpy_from_kernel/user_nofault() to retrieve the string to test the filter against. The if() statement was incorrect as it considered 0 as a fault, when it is only negative that it faulted. Running the following commands: # cd /sys/kernel/tracing # echo "filename.ustring ~ \"/proc*\"" > events/syscalls/sys_enter_openat= /filter # echo 1 > events/syscalls/sys_enter_openat/enable # ls /proc/$$/maps # cat trace Would produce nothing, but with the fix it will produce something like: ls-1192 [007] ..... 8169.828333: sys_openat(dfd: ffffffffffffff9c= , filename: 7efc18359904, flags: 80000, mode: 0) Link: https://lore.kernel.org/all/CAEf4BzbVPQ=3DBjWztmEwBPRKHUwNfKBkS3kce-R= zka6zvbQeVpg@mail.gmail.com/ Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Andrew Morton Link: https://lore.kernel.org/20250417183003.505835fb@gandalf.local.home Fixes: 77360f9bbc7e5 ("tracing: Add test for user space strings when filter= ing on string pointers") Reported-by: Andrii Nakryiko Reported-by: Mykyta Yatsenko Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_filter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events= _filter.c index 0993dfc1c5c1..2048560264bb 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -808,7 +808,7 @@ static __always_inline char *test_string(char *str) kstr =3D ubuf->buffer; =20 /* For safety, do not trust the string pointer */ - if (!strncpy_from_kernel_nofault(kstr, str, USTRING_BUF_SIZE)) + if (strncpy_from_kernel_nofault(kstr, str, USTRING_BUF_SIZE) < 0) return NULL; return kstr; } @@ -827,7 +827,7 @@ static __always_inline char *test_ustring(char *str) =20 /* user space address? */ ustr =3D (char __user *)str; - if (!strncpy_from_user_nofault(kstr, ustr, USTRING_BUF_SIZE)) + if (strncpy_from_user_nofault(kstr, ustr, USTRING_BUF_SIZE) < 0) return NULL; =20 return kstr; --=20 2.47.2 From nobody Sun Dec 14 12:18:19 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6698E226D0C for ; Fri, 18 Apr 2025 18:33:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745001227; cv=none; b=t0Qfc+g2tSqfNSUXg5mrE60RXy7cfG4DsMEhiI4cShW+AXmpvoyno9tuOtk75WyVCXCBGWM9evnKly09jC6TiF7CgNzrgIMJKDD2iy9EkztB9yanqgJbpLf9ni6QnpG6nwr/Ai8RN5Vxrir5LE3YxiEVQixhl9vatYOcGz4nZGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745001227; c=relaxed/simple; bh=OKDiqgB2pHuTCBxmEQy3/PZJ7f0jyGYq49naXeGmkh4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=eDq2Ru5m+37M/78N3uTLM/eaRGs+qPZEjdfClU7EablJK1+6soOtVrCbjFnhxuRIYOQoMNitfu7V0Fn9RMhW2EvC8dKArc/wwhczFE5vgayOpZoLZTQLEY6EyasWrd0C5vu0xUzykjKU1T7OLnY8PJaGCbwmpLTWOD/kyeLwTqU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DFF7C4CEEC; Fri, 18 Apr 2025 18:33:47 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1u5qYj-0000000DbA9-1Jes; Fri, 18 Apr 2025 14:35:29 -0400 Message-ID: <20250418183529.162957172@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 18 Apr 2025 14:34:53 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Shuah Khan Subject: [for-linus][PATCH 7/7] tracing: selftests: Add testing a user string to filters References: <20250418183446.383784216@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt Running the following commands was broken: # cd /sys/kernel/tracing # echo "filename.ustring ~ \"/proc*\"" > events/syscalls/sys_enter_openat= /filter # echo 1 > events/syscalls/sys_enter_openat/enable # ls /proc/$$/maps # cat trace And would produce nothing when it should have produced something like: ls-1192 [007] ..... 8169.828333: sys_openat(dfd: ffffffffffffff9c= , filename: 7efc18359904, flags: 80000, mode: 0) Add a test to check this case so that it will be caught if it breaks again. Link: https://lore.kernel.org/linux-trace-kernel/20250417183003.505835fb@ga= ndalf.local.home/ Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Shuah Khan Link: https://lore.kernel.org/20250418101208.38dc81f5@gandalf.local.home Signed-off-by: Steven Rostedt (Google) --- .../test.d/filter/event-filter-function.tc | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/testing/selftests/ftrace/test.d/filter/event-filter-func= tion.tc b/tools/testing/selftests/ftrace/test.d/filter/event-filter-functio= n.tc index 118247b8dd84..c62165fabd0c 100644 --- a/tools/testing/selftests/ftrace/test.d/filter/event-filter-function.tc +++ b/tools/testing/selftests/ftrace/test.d/filter/event-filter-function.tc @@ -80,6 +80,26 @@ if [ $misscnt -gt 0 ]; then exit_fail fi =20 +# Check strings too +if [ -f events/syscalls/sys_enter_openat/filter ]; then + DIRNAME=3D`basename $TMPDIR` + echo "filename.ustring ~ \"*$DIRNAME*\"" > events/syscalls/sys_enter_open= at/filter + echo 1 > events/syscalls/sys_enter_openat/enable + echo 1 > tracing_on + ls /bin/sh + nocnt=3D`grep openat trace | wc -l` + ls $TMPDIR + echo 0 > tracing_on + hitcnt=3D`grep openat trace | wc -l`; + echo 0 > events/syscalls/sys_enter_openat/enable + if [ $nocnt -gt 0 ]; then + exit_fail + fi + if [ $hitcnt -eq 0 ]; then + exit_fail + fi +fi + reset_events_filter =20 exit 0 --=20 2.47.2