All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Paul Chaignon <paul.chaignon@gmail.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	John Fastabend <john.fastabend@gmail.com>
Subject: Re: [PATCH bpf-next v2 1/2] bpf: Reject narrower access to pointer ctx fields
Date: Wed, 23 Jul 2025 19:42:41 -0700	[thread overview]
Message-ID: <697adce5-2afe-45bb-9e01-1022efb94e39@linux.dev> (raw)
In-Reply-To: <aICZqWFT77dvmJqc@mail.gmail.com>

On 7/23/25 1:13 AM, Paul Chaignon wrote:
> On Tue, Jul 22, 2025 at 03:28:40PM -0700, Martin KaFai Lau wrote:
>> On 7/22/25 7:32 AM, Paul Chaignon wrote:
>>> The following BPF program, simplified from a syzkaller repro, causes a
>>> kernel warning:
>>>
>>>       r0 = *(u8 *)(r1 + 169);
>>>       exit;
>>>
>>> With pointer field sk being at offset 168 in __sk_buff. This access is
>>> detected as a narrower read in bpf_skb_is_valid_access because it
>>> doesn't match offsetof(struct __sk_buff, sk). It is therefore allowed
>>> and later proceeds to bpf_convert_ctx_access. At that point,
>>> target_size is null and the verifier errors with a kernel warning and:
>>
>> I think it meant target_size is 0. I suspect !cnt is the condition causing
>> the 'verifier bug: ...'. Please check. No need to resend. The patch lgtm.
> 
> I also initially though the error was triggered because cnt was 0, but
> it is not. In case of narrower load, the offset is aligned before
> calling convert_ctx_access, which means we match
> offsetof(struct __sk_buff, sk) in bpf_convert_ctx_access. An
> instruction is added and cnt is thus 1. target_size however stays 0 so
> we hit the verifier bug error.

Got it. I have added this details to the commit message. Applied. Thanks!

  reply	other threads:[~2025-07-24  2:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-22 14:32 [PATCH bpf-next v2 1/2] bpf: Reject narrower access to pointer ctx fields Paul Chaignon
2025-07-22 14:33 ` [PATCH bpf-next v2 2/2] selftests/bpf: Test invalid narrower ctx load Paul Chaignon
2025-07-22 21:38   ` Eduard Zingerman
2025-07-22 20:40 ` [PATCH bpf-next v2 1/2] bpf: Reject narrower access to pointer ctx fields Eduard Zingerman
2025-07-22 22:28 ` Martin KaFai Lau
2025-07-23  8:13   ` Paul Chaignon
2025-07-24  2:42     ` Martin KaFai Lau [this message]
2025-07-24  2:50 ` patchwork-bot+netdevbpf

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=697adce5-2afe-45bb-9e01-1022efb94e39@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=john.fastabend@gmail.com \
    --cc=paul.chaignon@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.