bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	Barret Rhoden <brho@google.com>,
	Matt Bobrowski <mattbobrowski@google.com>,
	kkd@meta.com, kernel-team@meta.com
Subject: [PATCH bpf-next v2 04/11] bpf: Hold RCU read lock in bpf_prog_ksym_find
Date: Fri, 23 May 2025 18:18:42 -0700	[thread overview]
Message-ID: <20250524011849.681425-5-memxor@gmail.com> (raw)
In-Reply-To: <20250524011849.681425-1-memxor@gmail.com>

The bpf_ksym_find must be called with RCU read protection, wrap the call
to bpf_ksym_find in bpf_prog_ksym_find with RCU read lock so that
callers do not have to care about holding it specifically.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
 kernel/bpf/core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 8d381ca9f2fa..959538f91c60 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -782,7 +782,11 @@ bool is_bpf_text_address(unsigned long addr)
 
 struct bpf_prog *bpf_prog_ksym_find(unsigned long addr)
 {
-	struct bpf_ksym *ksym = bpf_ksym_find(addr);
+	struct bpf_ksym *ksym;
+
+	rcu_read_lock();
+	ksym = bpf_ksym_find(addr);
+	rcu_read_unlock();
 
 	return ksym && ksym->prog ?
 	       container_of(ksym, struct bpf_prog_aux, ksym)->prog :
-- 
2.47.1


  parent reply	other threads:[~2025-05-24  1:18 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-24  1:18 [PATCH bpf-next v2 00/11] BPF Standard Streams Kumar Kartikeya Dwivedi
2025-05-24  1:18 ` [PATCH bpf-next v2 01/11] bpf: Introduce BPF standard streams Kumar Kartikeya Dwivedi
2025-05-27 23:47   ` Eduard Zingerman
2025-05-27 23:55     ` Kumar Kartikeya Dwivedi
2025-05-28  0:23       ` Eduard Zingerman
2025-05-28  0:30         ` Kumar Kartikeya Dwivedi
2025-06-02 20:07   ` Alexei Starovoitov
2025-06-02 20:31     ` Kumar Kartikeya Dwivedi
2025-05-24  1:18 ` [PATCH bpf-next v2 02/11] bpf: Add function to extract program source info Kumar Kartikeya Dwivedi
2025-06-02 20:18   ` Alexei Starovoitov
2025-06-02 20:21     ` Kumar Kartikeya Dwivedi
2025-06-02 20:25       ` Alexei Starovoitov
2025-06-02 20:31         ` Kumar Kartikeya Dwivedi
2025-05-24  1:18 ` [PATCH bpf-next v2 03/11] bpf: Add function to find program from stack trace Kumar Kartikeya Dwivedi
2025-05-24  1:18 ` Kumar Kartikeya Dwivedi [this message]
2025-05-24  4:41   ` [PATCH bpf-next v2 04/11] bpf: Hold RCU read lock in bpf_prog_ksym_find Kumar Kartikeya Dwivedi
2025-05-28  0:15     ` Eduard Zingerman
2025-05-28  0:27       ` Kumar Kartikeya Dwivedi
2025-05-28  0:33         ` Eduard Zingerman
2025-05-24  1:18 ` [PATCH bpf-next v2 05/11] bpf: Add dump_stack() analogue to print to BPF stderr Kumar Kartikeya Dwivedi
2025-05-28  0:45   ` Eduard Zingerman
2025-05-28  0:58     ` Kumar Kartikeya Dwivedi
2025-05-28  6:03       ` Eduard Zingerman
2025-05-24  1:18 ` [PATCH bpf-next v2 06/11] bpf: Report may_goto timeout " Kumar Kartikeya Dwivedi
2025-06-02 22:27   ` Alexei Starovoitov
2025-06-03  1:55     ` Kumar Kartikeya Dwivedi
2025-05-24  1:18 ` [PATCH bpf-next v2 07/11] bpf: Report rqspinlock deadlocks/timeout " Kumar Kartikeya Dwivedi
2025-06-02 22:32   ` Alexei Starovoitov
2025-06-03  2:06     ` Kumar Kartikeya Dwivedi
2025-05-24  1:18 ` [PATCH bpf-next v2 08/11] libbpf: Add bpf_stream_printk() macro Kumar Kartikeya Dwivedi
2025-05-28  6:12   ` Eduard Zingerman
2025-05-28 10:09     ` Kumar Kartikeya Dwivedi
2025-05-24  1:18 ` [PATCH bpf-next v2 09/11] libbpf: Introduce bpf_prog_stream_read() API Kumar Kartikeya Dwivedi
2025-05-28 18:02   ` Eduard Zingerman
2025-05-29 15:36     ` Kumar Kartikeya Dwivedi
2025-06-05 20:06   ` Andrii Nakryiko
2025-05-24  1:18 ` [PATCH bpf-next v2 10/11] bpftool: Add support for dumping streams Kumar Kartikeya Dwivedi
2025-05-27 10:20   ` Quentin Monnet
2025-05-27 14:51     ` Kumar Kartikeya Dwivedi
2025-05-24  1:18 ` [PATCH bpf-next v2 11/11] selftests/bpf: Add tests for prog streams Kumar Kartikeya Dwivedi
2025-05-28 17:04   ` Eduard Zingerman
2025-05-29 14:57     ` Kumar Kartikeya Dwivedi
2025-05-29 16:28       ` Eduard Zingerman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250524011849.681425-5-memxor@gmail.com \
    --to=memxor@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brho@google.com \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=kernel-team@meta.com \
    --cc=kkd@meta.com \
    --cc=martin.lau@kernel.org \
    --cc=mattbobrowski@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).