BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v3 0/3] Use overflow.h helpers to check for overflows
@ 2024-07-12  8:01 Shung-Hsi Yu
  2024-07-12  8:01 ` [PATCH bpf-next v3 1/3] bpf: fix overflow check in adjust_jmp_off() Shung-Hsi Yu
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Shung-Hsi Yu @ 2024-07-12  8:01 UTC (permalink / raw)
  To: bpf, Alexei Starovoitov, Jiri Olsa
  Cc: Daniel Borkmann, John Fastabend, Andrii Nakryiko,
	Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
	KP Singh, Stanislav Fomichev, Hao Luo, Shung-Hsi Yu

This patch set refactors kernel/bpf/verifier.c to use type-agnostic, generic
overflow-check helpers defined in include/linux/overflow.h to check for addition
and subtraction overflow, and drop the signed_*_overflows() helpers we currently
have in kernel/bpf/verifier.c; with a fix for overflow check in adjust_jmp_off()
in patch 1.

There should be no functional change in how the verifier works and  the main
motivation is to make future refactoring[1] easier.

While check_mul_overflow() also exists and could potentially replace what
we have in scalar*_min_max_mul(), it does not help with refactoring and
would either change how the verifier works (e.g. lifting restriction on
umax<=U32_MAX and u32_max<=U16_MAX) or make the code slightly harder to
read, so it is left for future endeavour.

Changes from v2 <https://lore.kernel.org/r/20240701055907.82481-1-shung-hsi.yu@suse.com>
- add fix for 5337ac4c9b80 ("bpf: Fix the corner case with may_goto and jump to
  the 1st insn.") to correct the overflow check for general jump instructions
- adapt to changes in commit 5337ac4c9b80 ("bpf: Fix the corner case with
  may_goto and jump to the 1st insn.")
  - refactor in adjust_jmp_off() as well and remove signed_add16_overflow()

Changes from v1 <https://lore.kernel.org/r/20240623070324.12634-1-shung-hsi.yu@suse.com>:
- use pointers to values in dst_reg directly as the sum/diff pointer and
  remove the else branch (Jiri)
- change local variables to be dst_reg pointers instead of src_reg values
- include comparison of generated assembly before & after the change
  (Alexei)

1: https://github.com/kernel-patches/bpf/pull/7205/commits


Shung-Hsi Yu (3):
  bpf: fix overflow check in adjust_jmp_off()
  bpf: use check_add_overflow() to check for addition overflows
  bpf: use check_sub_overflow() to check for subtraction overflows

 kernel/bpf/verifier.c | 171 ++++++++++++------------------------------
 1 file changed, 48 insertions(+), 123 deletions(-)

-- 
2.45.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-07-12 16:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-12  8:01 [PATCH bpf-next v3 0/3] Use overflow.h helpers to check for overflows Shung-Hsi Yu
2024-07-12  8:01 ` [PATCH bpf-next v3 1/3] bpf: fix overflow check in adjust_jmp_off() Shung-Hsi Yu
2024-07-12  8:01 ` [PATCH bpf-next v3 2/3] bpf: use check_add_overflow() to check for addition overflows Shung-Hsi Yu
2024-07-12  8:01 ` [PATCH bpf-next v3 3/3] bpf: use check_sub_overflow() to check for subtraction overflows Shung-Hsi Yu
2024-07-12 16:00 ` [PATCH bpf-next v3 0/3] Use overflow.h helpers to check for overflows patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox