BPF List
 help / color / mirror / Atom feed
* [PATCH v3 bpf-next 00/10] BPF verifier retval logic fixes
@ 2023-11-30  0:03 Andrii Nakryiko
  2023-11-30  0:03 ` [PATCH v3 bpf-next 01/10] bpf: provide correct register name for exception callback retval check Andrii Nakryiko
                   ` (9 more replies)
  0 siblings, 10 replies; 20+ messages in thread
From: Andrii Nakryiko @ 2023-11-30  0:03 UTC (permalink / raw)
  To: bpf, ast, daniel, martin.lau; +Cc: andrii, kernel-team

This patch set fixes BPF verifier logic around validating and enforcing return
values for BPF programs that have specific range of expected return values.
Both sync and async callbacks have similar logic and are fixes as well.
A few tests are added that would fail without the fixes in this patch set.

Also, while at it, we update retval checking logic to use smin/smax range
instead of tnum, avoiding future potential issues if expected range cannot be
represented precisely by tnum (e.g., [0, 2] is not representable by tnum and
is treated as [0, 3]).

There is a little bit of refactoring to unify async callback and program exit
logic to avoid duplication of checks as much as possible.

v2->v3:
  - more carefullly switch from umin/umax to smin/smax;
v1->v2:
  - drop tnum from retval checks (Eduard);
  - use smin/smax instead of umin/umax (Alexei).

Andrii Nakryiko (10):
  bpf: provide correct register name for exception callback retval check
  bpf: enforce precision of R0 on callback return
  bpf: enforce exact retval range on subprog/callback exit
  selftests/bpf: add selftest validating callback result is enforced
  bpf: enforce precise retval range on program exit
  bpf: unify async callback and program retval checks
  bpf: enforce precision of R0 on program/async callback return
  selftests/bpf: validate async callback return value check correctness
  selftests/bpf: adjust global_func15 test to validate prog exit
    precision
  bpf: simplify tnum output if a fully known constant

 include/linux/bpf_verifier.h                  |   7 +-
 kernel/bpf/log.c                              |  13 ++
 kernel/bpf/tnum.c                             |   6 -
 kernel/bpf/verifier.c                         | 120 ++++++++++--------
 .../selftests/bpf/progs/exceptions_assert.c   |   2 +-
 .../selftests/bpf/progs/exceptions_fail.c     |   2 +-
 .../selftests/bpf/progs/test_global_func15.c  |  34 ++++-
 .../selftests/bpf/progs/timer_failure.c       |  36 ++++--
 .../selftests/bpf/progs/user_ringbuf_fail.c   |   2 +-
 .../bpf/progs/verifier_cgroup_inv_retcode.c   |   8 +-
 .../bpf/progs/verifier_direct_packet_access.c |   2 +-
 .../selftests/bpf/progs/verifier_int_ptr.c    |   2 +-
 .../bpf/progs/verifier_netfilter_retcode.c    |   2 +-
 .../selftests/bpf/progs/verifier_stack_ptr.c  |   4 +-
 .../bpf/progs/verifier_subprog_precision.c    |  50 ++++++++
 15 files changed, 211 insertions(+), 79 deletions(-)

-- 
2.34.1


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

end of thread, other threads:[~2023-11-30  6:41 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-30  0:03 [PATCH v3 bpf-next 00/10] BPF verifier retval logic fixes Andrii Nakryiko
2023-11-30  0:03 ` [PATCH v3 bpf-next 01/10] bpf: provide correct register name for exception callback retval check Andrii Nakryiko
2023-11-30  5:41   ` Shung-Hsi Yu
2023-11-30  0:03 ` [PATCH v3 bpf-next 02/10] bpf: enforce precision of R0 on callback return Andrii Nakryiko
2023-11-30  5:43   ` Shung-Hsi Yu
2023-11-30  0:03 ` [PATCH v3 bpf-next 03/10] bpf: enforce exact retval range on subprog/callback exit Andrii Nakryiko
2023-11-30  5:49   ` Shung-Hsi Yu
2023-11-30  0:04 ` [PATCH v3 bpf-next 04/10] selftests/bpf: add selftest validating callback result is enforced Andrii Nakryiko
2023-11-30  5:52   ` Shung-Hsi Yu
2023-11-30  0:04 ` [PATCH v3 bpf-next 05/10] bpf: enforce precise retval range on program exit Andrii Nakryiko
2023-11-30  5:54   ` Shung-Hsi Yu
2023-11-30  0:04 ` [PATCH v3 bpf-next 06/10] bpf: unify async callback and program retval checks Andrii Nakryiko
2023-11-30  5:56   ` Shung-Hsi Yu
2023-11-30  0:04 ` [PATCH v3 bpf-next 07/10] bpf: enforce precision of R0 on program/async callback return Andrii Nakryiko
2023-11-30  6:33   ` Shung-Hsi Yu
2023-11-30  6:41     ` Andrii Nakryiko
2023-11-30  0:04 ` [PATCH v3 bpf-next 08/10] selftests/bpf: validate async callback return value check correctness Andrii Nakryiko
2023-11-30  0:04 ` [PATCH v3 bpf-next 09/10] selftests/bpf: adjust global_func15 test to validate prog exit precision Andrii Nakryiko
2023-11-30  0:04 ` [PATCH v3 bpf-next 10/10] bpf: simplify tnum output if a fully known constant Andrii Nakryiko
2023-11-30  6:34   ` Shung-Hsi Yu

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