mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Nuoqi Gui" <gnq25@mails.tsinghua.edu.cn>
To: "Eduard Zingerman" <eddyz87@gmail.com>
Cc: "Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	"Song Liu" <song@kernel.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"Hao Luo" <haoluo@google.com>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	"Shuah Khan" <shuah@kernel.org>,
	bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: Re: [PATCH bpf-next 1/2] bpf: Require CAP_BPF for pseudo-BTF ksym loads
Date: Sat, 20 Jun 2026 23:34:38 +0800 (GMT+08:00)	[thread overview]
Message-ID: <7f299d22.8290e.19ee5ab7010.Coremail.gnq25@mails.tsinghua.edu.cn> (raw)
In-Reply-To: <a15079723c8834a2baf3f35c6a8ed52c63addeb9.camel@gmail.com>




> -----Original Messages-----
> From: "Eduard Zingerman" <eddyz87@gmail.com>
> Send time:Saturday, 20/06/2026 04:05:22
> To: "Nuoqi Gui" <gnq25@mails.tsinghua.edu.cn>, "Alexei Starovoitov" <ast@kernel.org>, "Daniel Borkmann" <daniel@iogearbox.net>, "Andrii Nakryiko" <andrii@kernel.org>, "Kumar Kartikeya Dwivedi" <memxor@gmail.com>, "Song Liu" <song@kernel.org>, "Yonghong Song" <yonghong.song@linux.dev>, "Jiri Olsa" <jolsa@kernel.org>, "Emil Tsalapatis" <emil@etsalapatis.com>, "Hao Luo" <haoluo@google.com>
> Cc: "John Fastabend" <john.fastabend@gmail.com>, "Martin KaFai Lau" <martin.lau@linux.dev>, "Shuah Khan" <shuah@kernel.org>, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
> Subject: Re: [PATCH bpf-next 1/2] bpf: Require CAP_BPF for pseudo-BTF ksym loads
> 
> On Sat, 2026-06-20 at 00:04 +0800, Nuoqi Gui wrote:
> > BPF_PSEUDO_BTF_ID is resolved before the main verifier pass. The resolver
> > looks up the referenced kernel symbol through kallsyms and rewrites the
> > ldimm64 immediate to the concrete address that later becomes verifier
> > state.
> > 
> > Require CAP_BPF before doing that materialization. This keeps typed ksym
> > address resolution on the privileged side and prevents loaders without
> > CAP_BPF from receiving a verifier log that contains the resolved address.
> > 
> > Fixes: 4976b718c3551 ("bpf: Introduce pseudo_btf_id")
> > Signed-off-by: Nuoqi Gui <gnq25@mails.tsinghua.edu.cn>
> > ---
> >  kernel/bpf/verifier.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> > 
> > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > index ed7ba0e6a9ce..dbf5df995fc2 100644
> > --- a/kernel/bpf/verifier.c
> > +++ b/kernel/bpf/verifier.c
> > @@ -17639,6 +17639,11 @@ static int check_pseudo_btf_id(struct bpf_verifier_env *env,
> >  	int btf_fd;
> >  	int err;
> >  
> > +	if (!env->bpf_capable) {
> > +		verbose(env, "BPF_PSEUDO_BTF_ID loads require CAP_BPF\n");
> > +		return -EACCES;
> > +	}
> > +
> 
> Thank you for identifying this issue.
> I think the correct way to fix it is to extend the `is_ptr && !allow_ptr_leaks`
> logic in kernel/bpf/disasm.c:print_bpf_insn().
> Note that it seems there are additional cases that are not covered,
> something like below seem warranted:
> 
> 
>   bool is_ptr = insn->src_reg == BPF_PSEUDO_MAP_FD    ||
>                 insn->src_reg == BPF_PSEUDO_MAP_VALUE  ||
>                 insn->src_reg == BPF_PSEUDO_MAP_IDX    ||
>                 insn->src_reg == BPF_PSEUDO_MAP_IDX_VALUE ||
>                 insn->src_reg == BPF_PSEUDO_BTF_ID;
> 
> Could you please double check?
> 
> >  	btf_fd = insn[1].imm;
> >  	if (btf_fd) {
> >  		btf = btf_get_by_fd(btf_fd);

Thanks for the guidance.  I'll rework this to extend the pointer-like 
ldimm64 sanitization in print_bpf_insn().

  reply	other threads:[~2026-06-20 15:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-19 16:04 [PATCH bpf-next 0/2] " Nuoqi Gui
2026-06-19 16:04 ` [PATCH bpf-next 1/2] " Nuoqi Gui
2026-06-19 20:05   ` Eduard Zingerman
2026-06-20 15:34     ` Nuoqi Gui [this message]
2026-06-19 16:04 ` [PATCH bpf-next 2/2] selftests/bpf: Cover pseudo-BTF ksym load capability Nuoqi Gui

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=7f299d22.8290e.19ee5ab7010.Coremail.gnq25@mails.tsinghua.edu.cn \
    --to=gnq25@mails.tsinghua.edu.cn \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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

all inboxes | Powered by JetHome®