All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shung-Hsi Yu <shung-hsi.yu@suse.com>
To: sun jian <sun.jian.kdev@gmail.com>,
	 Eduard Zingerman <eddyz87@gmail.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
	 john.fastabend@gmail.com, andrii@kernel.org, memxor@gmail.com,
	martin.lau@linux.dev,  song@kernel.org, yonghong.song@linux.dev,
	jolsa@kernel.org, emil@etsalapatis.com,  shuah@kernel.org,
	mmullins@fb.com, linux-kernel@vger.kernel.org,
	 linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf v4 1/2] bpf: Reject negative const offsets for buffer pointers
Date: Tue, 14 Jul 2026 13:01:32 +0800	[thread overview]
Message-ID: <alXBjNMotfDYXeNX@u94a> (raw)
In-Reply-To: <alWvvwpn3z9Nn0zw@u94a>

On Tue, Jul 14, 2026 at 12:31:38PM +0800, Shung-Hsi Yu wrote:
...
> > >	var_off = (s64)reg->var_off.value;
> > >	if (var_off >= BPF_MAX_VAR_OFF || var_off <= -BPF_MAX_VAR_OFF)
> > 
> > This should hold already.
> 
> FWIW, I had thought so, but after checking I realize that the verifier
> only ensure that
> 
>   -BPF_MAX_VAR_OFF < smin < BPF_MAX_VAR_OFF
> 
> holds true in check_reg_sane_offset_{scalar,ptr}(), and does not check
> smax, so technically var_off.value can be greater than BPF_MAX_VAR_OFF
> when we reach here...

Scratch that, it cannot. Below just shows that (var_off.value |
var_off.mask) can be greater than BPF_MAX_VAR_OFF, not var_off.value.

So what Eduard said is correct, and
  
  -BPF_MAX_VAR_OFF < var_off.value < BPF_MAX_VAR_OFF

does always hold.

> ..., just that it doesn't really matter much as it is
> rejected anyway. And if it is a constant then smin=smax, so for a
> constant value it does always falls between +-BPF_MAX_VAR_OFF.
> 
>   0: (79) r6 = *(u64 *)(r1 +0)          ; R1=ctx() R6=tp_buffer()
>   1: (85) call bpf_get_prandom_u32#7    ; R0=scalar()
>   2: (bf) r2 = r0                       ; R0=scalar(id=1) R2=scalar(id=1)
>   3: (67) r2 <<= 32                     ; R2=scalar(smax=0x7fffffff00000000,smin32=0,smax32=umax32=0,var_off=(0x0; 0xffffffff00000000))
>   4: (77) r2 >>= 32                     ; R2=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>   5: (07) r2 += 536870911               ; R2=scalar(smin=umin=0x1fffffff,smax=umax=0x11ffffffe,var_off=(0x0; 0x1ffffffff))
>                 /* r2 is now [2^29 - 1, 2^32 + 2^29 - 2] */
>   6: (0f) r6 += r2
>   7: R2=scalar(smin=umin=0x1fffffff,smax=umax=0x11ffffffe,var_off=(0x0; 0x1ffffffff)) R6=tp_buffer(smin=umin=0x1fffffff,smax=umax=0x11ffffffe,var_off=(0x0; 0x1ffffffff))
>   7: (79) r0 = *(u64 *)(r6 +0)
>   R6 invalid variable buffer offset: off=0, var_off=(0x0; 0x1ffffffff)
> 
[...]

  reply	other threads:[~2026-07-14  5:01 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08  9:01 [PATCH bpf v4 0/2] bpf: Reject negative const offsets for buffer pointers Sun Jian
2026-07-08  9:01 ` [PATCH bpf v4 1/2] " Sun Jian
2026-07-08 13:13   ` Shung-Hsi Yu
2026-07-08 14:11     ` sun jian
2026-07-09  6:47       ` Shung-Hsi Yu
2026-07-09 12:47         ` sun jian
2026-07-09 18:21         ` Eduard Zingerman
2026-07-10  5:52           ` sun jian
2026-07-10  6:23             ` Eduard Zingerman
2026-07-10  7:25               ` sun jian
2026-07-10  7:47                 ` Eduard Zingerman
2026-07-10  8:00             ` Shung-Hsi Yu
2026-07-10  8:10               ` Shung-Hsi Yu
2026-07-10 10:27               ` sun jian
2026-07-13  5:05                 ` Shung-Hsi Yu
2026-07-13 20:44                   ` Eduard Zingerman
2026-07-14  4:31                     ` Shung-Hsi Yu
2026-07-14  5:01                       ` Shung-Hsi Yu [this message]
2026-07-08  9:01 ` [PATCH bpf v4 2/2] selftests/bpf: Cover negative raw_tp writable buffer offsets Sun Jian
2026-07-09 16:59   ` 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=alXBjNMotfDYXeNX@u94a \
    --to=shung-hsi.yu@suse.com \
    --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=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=mmullins@fb.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=sun.jian.kdev@gmail.com \
    --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 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.