<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/kernel/bpf/verifier.c, branch v6.17</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v6.17</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v6.17'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2025-09-10T19:34:09Z</updated>
<entry>
<title>bpf: Reject bpf_timer for PREEMPT_RT</title>
<updated>2025-09-10T19:34:09Z</updated>
<author>
<name>Leon Hwang</name>
<email>leon.hwang@linux.dev</email>
</author>
<published>2025-09-10T12:57:39Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=e25ddfb388c8b7e5f20e3bf38d627fb485003781'/>
<id>urn:sha1:e25ddfb388c8b7e5f20e3bf38d627fb485003781</id>
<content type='text'>
When enable CONFIG_PREEMPT_RT, the kernel will warn when run timer
selftests by './test_progs -t timer':

BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:48

In order to avoid such warning, reject bpf_timer in verifier when
PREEMPT_RT is enabled.

Signed-off-by: Leon Hwang &lt;leon.hwang@linux.dev&gt;
Link: https://lore.kernel.org/r/20250910125740.52172-2-leon.hwang@linux.dev
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;

</content>
</entry>
<entry>
<title>bpf: Check the helper function is valid in get_helper_proto</title>
<updated>2025-08-15T09:16:56Z</updated>
<author>
<name>Jiri Olsa</name>
<email>olsajiri@gmail.com</email>
</author>
<published>2025-08-14T20:06:55Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=e4414b01c1cd9887bbde92f946c1ba94e40d6d64'/>
<id>urn:sha1:e4414b01c1cd9887bbde92f946c1ba94e40d6d64</id>
<content type='text'>
kernel test robot reported verifier bug [1] where the helper func
pointer could be NULL due to disabled config option.

As Alexei suggested we could check on that in get_helper_proto
directly. Marking tail_call helper func with BPF_PTR_POISON,
because it is unused by design.

  [1] https://lore.kernel.org/oe-lkp/202507160818.68358831-lkp@intel.com

Reported-by: kernel test robot &lt;oliver.sang@intel.com&gt;
Reported-by: syzbot+a9ed3d9132939852d0df@syzkaller.appspotmail.com
Suggested-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Signed-off-by: Jiri Olsa &lt;jolsa@kernel.org&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Acked-by: Paul Chaignon &lt;paul.chaignon@gmail.com&gt;
Acked-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Link: https://lore.kernel.org/bpf/20250814200655.945632-1-jolsa@kernel.org
Closes: https://lore.kernel.org/oe-lkp/202507160818.68358831-lkp@intel.com
</content>
</entry>
<entry>
<title>bpf: Fix memory leak of bpf_scc_info objects</title>
<updated>2025-08-02T16:04:57Z</updated>
<author>
<name>Eduard Zingerman</name>
<email>eddyz87@gmail.com</email>
</author>
<published>2025-08-01T23:23:30Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=1b30d44417278196a90c79244bb43e8428586345'/>
<id>urn:sha1:1b30d44417278196a90c79244bb43e8428586345</id>
<content type='text'>
env-&gt;scc_info array contains references to bpf_scc_info objects
allocated lazily in verifier.c:scc_visit_alloc().
env-&gt;scc_cnt was supposed to track env-&gt;scc_info array size
in order to free referenced objects in verifier.c:free_states().
Fix initialization of env-&gt;scc_cnt that was omitted in
verifier.c:compute_scc().

To reproduce the bug:
- build with CONFIG_DEBUG_KMEMLEAK
- boot and load bpf program with loops, e.g.:
  ./veristat -q pyperf180.bpf.o
- initiate memleak scan and check results:
  echo scan &gt; /sys/kernel/debug/kmemleak
  cat /sys/kernel/debug/kmemleak

Fixes: c9e31900b54c ("bpf: propagate read/precision marks over state graph backedges")
Reported-by: Jens Axboe &lt;axboe@kernel.dk&gt;
Closes: https://lore.kernel.org/bpf/CAADnVQKXUWg9uRCPD5ebRXwN4dmBCRUFFM7kN=GxymYz3zU25A@mail.gmail.com/T/
Suggested-by: Alexei Starovoitov &lt;alexei.starovoitov@gmail.com&gt;
Tested-by: Jens Axboe &lt;axboe@kernel.dk&gt;
Signed-off-by: Eduard Zingerman &lt;eddyz87@gmail.com&gt;
Link: https://lore.kernel.org/r/20250801232330.1800436-1-eddyz87@gmail.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpf: Improve ctx access verifier error message</title>
<updated>2025-08-01T16:22:44Z</updated>
<author>
<name>Paul Chaignon</name>
<email>paul.chaignon@gmail.com</email>
</author>
<published>2025-08-01T09:49:15Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=f914876eec9e72ae94b5cee81a9dc7935c255b2f'/>
<id>urn:sha1:f914876eec9e72ae94b5cee81a9dc7935c255b2f</id>
<content type='text'>
We've already had two "error during ctx access conversion" warnings
triggered by syzkaller. Let's improve the error message by dumping the
cnt variable so that we can more easily differentiate between the
different error cases.

Signed-off-by: Paul Chaignon &lt;paul.chaignon@gmail.com&gt;
Acked-by: Eduard Zingerman &lt;eddyz87@gmail.com&gt;
Link: https://lore.kernel.org/r/cc94316c30dd76fae4a75a664b61a2dbfe68e205.1754039605.git.paul.chaignon@gmail.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;

</content>
</entry>
<entry>
<title>bpf: Add log for attaching tracing programs to functions in deny list</title>
<updated>2025-07-29T02:39:29Z</updated>
<author>
<name>KaFai Wan</name>
<email>kafai.wan@linux.dev</email>
</author>
<published>2025-07-24T15:14:52Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=863aab3d4dcdfffa5cf0e0795c526dadca65be7a'/>
<id>urn:sha1:863aab3d4dcdfffa5cf0e0795c526dadca65be7a</id>
<content type='text'>
Show the rejected function name when attaching tracing programs to
functions in deny list.

With this change, we know why tracing programs can't attach to functions
like __rcu_read_lock() from log.

$ ./fentry
libbpf: prog '__rcu_read_lock': BPF program load failed: -EINVAL
libbpf: prog '__rcu_read_lock': -- BEGIN PROG LOAD LOG --
Attaching tracing programs to function '__rcu_read_lock' is rejected.

Suggested-by: Leon Hwang &lt;leon.hwang@linux.dev&gt;
Signed-off-by: KaFai Wan &lt;kafai.wan@linux.dev&gt;
Acked-by: Yafang Shao &lt;laoar.shao@gmail.com&gt;
Acked-by: Yonghong Song &lt;yonghong.song@linux.dev&gt;
Link: https://lore.kernel.org/r/20250724151454.499040-3-kafai.wan@linux.dev
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpf: Show precise rejected function when attaching fexit/fmod_ret to __noreturn functions</title>
<updated>2025-07-29T02:39:29Z</updated>
<author>
<name>KaFai Wan</name>
<email>kafai.wan@linux.dev</email>
</author>
<published>2025-07-24T15:14:51Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=a5a6b29a700fda1dd766cc42dde2cbba9b19f470'/>
<id>urn:sha1:a5a6b29a700fda1dd766cc42dde2cbba9b19f470</id>
<content type='text'>
With this change, we know the precise rejected function name when
attaching fexit/fmod_ret to __noreturn functions from log.

$ ./fexit
libbpf: prog 'fexit': BPF program load failed: -EINVAL
libbpf: prog 'fexit': -- BEGIN PROG LOAD LOG --
Attaching fexit/fmod_ret to __noreturn function 'do_exit' is rejected.

Suggested-by: Leon Hwang &lt;leon.hwang@linux.dev&gt;
Signed-off-by: KaFai Wan &lt;kafai.wan@linux.dev&gt;
Acked-by: Yafang Shao &lt;laoar.shao@gmail.com&gt;
Acked-by: Yonghong Song &lt;yonghong.song@linux.dev&gt;
Link: https://lore.kernel.org/r/20250724151454.499040-2-kafai.wan@linux.dev
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpf: Fix various typos in verifier.c comments</title>
<updated>2025-07-28T17:02:57Z</updated>
<author>
<name>Suchit Karunakaran</name>
<email>suchitkarunakaran@gmail.com</email>
</author>
<published>2025-07-27T08:17:54Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=5b4c54ac49af7f486806d79e3233fc8a9363961c'/>
<id>urn:sha1:5b4c54ac49af7f486806d79e3233fc8a9363961c</id>
<content type='text'>
This patch fixes several minor typos in comments within the BPF verifier.
No changes in functionality.

Signed-off-by: Suchit Karunakaran &lt;suchitkarunakaran@gmail.com&gt;
Link: https://lore.kernel.org/r/20250727081754.15986-1-suchitkarunakaran@gmail.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpf: Add third round of bounds deduction</title>
<updated>2025-07-28T17:02:13Z</updated>
<author>
<name>Paul Chaignon</name>
<email>paul.chaignon@gmail.com</email>
</author>
<published>2025-07-28T09:52:00Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=5dbb19b16ac498b0b7f3a8a85f9d25d6d8af397d'/>
<id>urn:sha1:5dbb19b16ac498b0b7f3a8a85f9d25d6d8af397d</id>
<content type='text'>
Commit d7f008738171 ("bpf: try harder to deduce register bounds from
different numeric domains") added a second call to __reg_deduce_bounds
in reg_bounds_sync because a single call wasn't enough to converge to a
fixed point in terms of register bounds.

With patch "bpf: Improve bounds when s64 crosses sign boundary" from
this series, Eduard noticed that calling __reg_deduce_bounds twice isn't
enough anymore to converge. The first selftest added in "selftests/bpf:
Test cross-sign 64bits range refinement" highlights the need for a third
call to __reg_deduce_bounds. After instruction 7, reg_bounds_sync
performs the following bounds deduction:

  reg_bounds_sync entry:          scalar(smin=-655,smax=0xeffffeee,smin32=-783,smax32=-146)
  __update_reg_bounds:            scalar(smin=-655,smax=0xeffffeee,smin32=-783,smax32=-146)
  __reg_deduce_bounds:
      __reg32_deduce_bounds:      scalar(smin=-655,smax=0xeffffeee,smin32=-783,smax32=-146,umin32=0xfffffcf1,umax32=0xffffff6e)
      __reg64_deduce_bounds:      scalar(smin=-655,smax=0xeffffeee,smin32=-783,smax32=-146,umin32=0xfffffcf1,umax32=0xffffff6e)
      __reg_deduce_mixed_bounds:  scalar(smin=-655,smax=0xeffffeee,umin=umin32=0xfffffcf1,umax=0xffffffffffffff6e,smin32=-783,smax32=-146,umax32=0xffffff6e)
  __reg_deduce_bounds:
      __reg32_deduce_bounds:      scalar(smin=-655,smax=0xeffffeee,umin=umin32=0xfffffcf1,umax=0xffffffffffffff6e,smin32=-783,smax32=-146,umax32=0xffffff6e)
      __reg64_deduce_bounds:      scalar(smin=-655,smax=smax32=-146,umin=0xfffffffffffffd71,umax=0xffffffffffffff6e,smin32=-783,umin32=0xfffffcf1,umax32=0xffffff6e)
      __reg_deduce_mixed_bounds:  scalar(smin=-655,smax=smax32=-146,umin=0xfffffffffffffd71,umax=0xffffffffffffff6e,smin32=-783,umin32=0xfffffcf1,umax32=0xffffff6e)
  __reg_bound_offset:             scalar(smin=-655,smax=smax32=-146,umin=0xfffffffffffffd71,umax=0xffffffffffffff6e,smin32=-783,umin32=0xfffffcf1,umax32=0xffffff6e,var_off=(0xfffffffffffffc00; 0x3ff))
  __update_reg_bounds:            scalar(smin=-655,smax=smax32=-146,umin=0xfffffffffffffd71,umax=0xffffffffffffff6e,smin32=-783,umin32=0xfffffcf1,umax32=0xffffff6e,var_off=(0xfffffffffffffc00; 0x3ff))

In particular, notice how:
1. In the first call to __reg_deduce_bounds, __reg32_deduce_bounds
   learns new u32 bounds.
2. __reg64_deduce_bounds is unable to improve bounds at this point.
3. __reg_deduce_mixed_bounds derives new u64 bounds from the u32 bounds.
4. In the second call to __reg_deduce_bounds, __reg64_deduce_bounds
   improves the smax and umin bounds thanks to patch "bpf: Improve
   bounds when s64 crosses sign boundary" from this series.
5. Subsequent functions are unable to improve the ranges further (only
   tnums). Yet, a better smin32 bound could be learned from the smin
   bound.

__reg32_deduce_bounds is able to improve smin32 from smin, but for that
we need a third call to __reg_deduce_bounds.

As discussed in [1], there may be a better way to organize the deduction
rules to learn the same information with less calls to the same
functions. Such an optimization requires further analysis and is
orthogonal to the present patchset.

Link: https://lore.kernel.org/bpf/aIKtSK9LjQXB8FLY@mail.gmail.com/ [1]
Acked-by: Eduard Zingerman &lt;eddyz87@gmail.com&gt;
Co-developed-by: Eduard Zingerman &lt;eddyz87@gmail.com&gt;
Signed-off-by: Eduard Zingerman &lt;eddyz87@gmail.com&gt;
Signed-off-by: Paul Chaignon &lt;paul.chaignon@gmail.com&gt;
Link: https://lore.kernel.org/r/79619d3b42e5525e0e174ed534b75879a5ba15de.1753695655.git.paul.chaignon@gmail.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpf: Improve bounds when s64 crosses sign boundary</title>
<updated>2025-07-28T17:02:12Z</updated>
<author>
<name>Paul Chaignon</name>
<email>paul.chaignon@gmail.com</email>
</author>
<published>2025-07-28T09:50:53Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=00bf8d0c6c9be0c481fc45a3f7d87c7f8812f229'/>
<id>urn:sha1:00bf8d0c6c9be0c481fc45a3f7d87c7f8812f229</id>
<content type='text'>
__reg64_deduce_bounds currently improves the s64 range using the u64
range and vice versa, but only if it doesn't cross the sign boundary.

This patch improves __reg64_deduce_bounds to cover the case where the
s64 range crosses the sign boundary but overlaps with the u64 range on
only one end. In that case, we can improve both ranges. Consider the
following example, with the s64 range crossing the sign boundary:

    0                                                   U64_MAX
    |  [xxxxxxxxxxxxxx u64 range xxxxxxxxxxxxxx]              |
    |----------------------------|----------------------------|
    |xxxxx s64 range xxxxxxxxx]                       [xxxxxxx|
    0                     S64_MAX S64_MIN                    -1

The u64 range overlaps only with positive portion of the s64 range. We
can thus derive the following new s64 and u64 ranges.

    0                                                   U64_MAX
    |  [xxxxxx u64 range xxxxx]                               |
    |----------------------------|----------------------------|
    |  [xxxxxx s64 range xxxxx]                               |
    0                     S64_MAX S64_MIN                    -1

The same logic can probably apply to the s32/u32 ranges, but this patch
doesn't implement that change.

In addition to the selftests, the __reg64_deduce_bounds change was
also tested with Agni, the formal verification tool for the range
analysis [1].

Link: https://github.com/bpfverif/agni [1]
Acked-by: Eduard Zingerman &lt;eddyz87@gmail.com&gt;
Acked-by: Shung-Hsi Yu &lt;shung-hsi.yu@suse.com&gt;
Signed-off-by: Paul Chaignon &lt;paul.chaignon@gmail.com&gt;
Link: https://lore.kernel.org/r/933bd9ce1f36ded5559f92fdc09e5dbc823fa245.1753695655.git.paul.chaignon@gmail.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpf: Simplify bounds refinement from s32</title>
<updated>2025-07-27T17:23:29Z</updated>
<author>
<name>Paul Chaignon</name>
<email>paul.chaignon@gmail.com</email>
</author>
<published>2025-07-24T17:42:52Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=5345e64760d37524d38ddfa7471f42ec64b0f289'/>
<id>urn:sha1:5345e64760d37524d38ddfa7471f42ec64b0f289</id>
<content type='text'>
During the bounds refinement, we improve the precision of various ranges
by looking at other ranges. Among others, we improve the following in
this order (other things happen between 1 and 2):

  1. Improve u32 from s32 in __reg32_deduce_bounds.
  2. Improve s/u64 from u32 in __reg_deduce_mixed_bounds.
  3. Improve s/u64 from s32 in __reg_deduce_mixed_bounds.

In particular, if the s32 range forms a valid u32 range, we will use it
to improve the u32 range in __reg32_deduce_bounds. In
__reg_deduce_mixed_bounds, under the same condition, we will use the s32
range to improve the s/u64 ranges.

If at (1) we were able to learn from s32 to improve u32, we'll then be
able to use that in (2) to improve s/u64. Hence, as (3) happens under
the same precondition as (1), it won't improve s/u64 ranges further than
(1)+(2) did. Thus, we can get rid of (3).

In addition to the extensive suite of selftests for bounds refinement,
this patch was also tested with the Agni formal verification tool [1].

Additionally, Eduard mentioned:

  The argument appears to be as follows:

  Under precondition `(u32)reg-&gt;s32_min &lt;= (u32)reg-&gt;s32_max`
  __reg32_deduce_bounds produces:

    reg-&gt;u32_min = max_t(u32, reg-&gt;s32_min, reg-&gt;u32_min);
    reg-&gt;u32_max = min_t(u32, reg-&gt;s32_max, reg-&gt;u32_max);

  And then first part of __reg_deduce_mixed_bounds assigns:

    a. reg-&gt;umin umax= (reg-&gt;umin &amp; ~0xffffffffULL) | max_t(u32, reg-&gt;s32_min, reg-&gt;u32_min);
    b. reg-&gt;umax umin= (reg-&gt;umax &amp; ~0xffffffffULL) | min_t(u32, reg-&gt;s32_max, reg-&gt;u32_max);

  And then second part of __reg_deduce_mixed_bounds assigns:

    c. reg-&gt;umin umax= (reg-&gt;umin &amp; ~0xffffffffULL) | (u32)reg-&gt;s32_min;
    d. reg-&gt;umax umin= (reg-&gt;umax &amp; ~0xffffffffULL) | (u32)reg-&gt;s32_max;

  But assignment (c) is a noop because:

     max_t(u32, reg-&gt;s32_min, reg-&gt;u32_min) &gt;= (u32)reg-&gt;s32_min

  Hence RHS(a) &gt;= RHS(c) and umin= does nothing.

  Also assignment (d) is a noop because:

    min_t(u32, reg-&gt;s32_max, reg-&gt;u32_max) &lt;= (u32)reg-&gt;s32_max

  Hence RHS(b) &lt;= RHS(d) and umin= does nothing.

  Plus the same reasoning for the part dealing with reg-&gt;s{min,max}_value:

    e. reg-&gt;smin_value smax= (reg-&gt;smin_value &amp; ~0xffffffffULL) | max_t(u32, reg-&gt;s32_min_value, reg-&gt;u32_min_value);
    f. reg-&gt;smax_value smin= (reg-&gt;smax_value &amp; ~0xffffffffULL) | min_t(u32, reg-&gt;s32_max_value, reg-&gt;u32_max_value);

      vs

    g. reg-&gt;smin_value smax= (reg-&gt;smin_value &amp; ~0xffffffffULL) | (u32)reg-&gt;s32_min_value;
    h. reg-&gt;smax_value smin= (reg-&gt;smax_value &amp; ~0xffffffffULL) | (u32)reg-&gt;s32_max_value;

      RHS(e) &gt;= RHS(g) and RHS(f) &lt;= RHS(h), hence smax=,smin= do nothing.

  This appears to be correct.

Also, Shung-Hsi:

  Beside going through the reasoning, I also played with CBMC a bit to
  double check that as far as a single run of __reg_deduce_bounds() is
  concerned (and that the register state matches certain handwavy
  expectations), the change indeed still preserve the original behavior.

Signed-off-by: Paul Chaignon &lt;paul.chaignon@gmail.com&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Reviewed-by: Shung-Hsi Yu &lt;shung-hsi.yu@suse.com&gt;
Acked-by: Eduard Zingerman &lt;eddyz87@gmail.com&gt;
Link: https://github.com/bpfverif/agni [1]
Link: https://lore.kernel.org/bpf/aIJwnFnFyUjNsCNa@mail.gmail.com
</content>
</entry>
</feed>
