BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v3 0/1] samples/bpf: syscall_tp_user: Refactor and fix array index out-of-bounds bug
@ 2023-09-27  4:50 ruowenq2
  2023-09-27  4:50 ` [PATCH bpf-next v3 1/1] samples/bpf: Add -fsanitize=bounds to userspace programs ruowenq2
  2023-09-28 16:40 ` [PATCH bpf-next v3 0/1] samples/bpf: syscall_tp_user: Refactor and fix array index out-of-bounds bug patchwork-bot+netdevbpf
  0 siblings, 2 replies; 8+ messages in thread
From: ruowenq2 @ 2023-09-27  4:50 UTC (permalink / raw)
  To: bpf; +Cc: ast, daniel, andrii, jinghao7, keescook, Ruowen Qin

From: Ruowen Qin <ruowenq2@illinois.edu>

Thanks to Alexei, patch 2/3 and 3/3 from v2 have been upstreamed. v3
primarily addresses scenarios where the compiler lacks ubsan support.

There are currently 6 BPF programs in syscall_tp_kern but the array to
hold the corresponding bpf_links in syscall_tp_user only has space for 4
programs, given the array size is hardcoded. This causes the sample
program to fail due to an out-of-bound access that corrupts other stack
variables:

  # ./syscall_tp
  prog #0: map ids 4 5
  verify map:4 val: 5
  map_lookup failed: Bad file descriptor

This patch series aims to solve this issue for now and for the future.
It first adds the -fsanitize=bounds flag to make similar bugs more
obvious at runtime. It then refactors syscall_tp_user to retrieve the
number of programs from the bpf_object and dynamically allocate the
array of bpf_links to avoid inconsistencies from hardcoding.

Changelog:
---
v2 -> v3
v2: https://lore.kernel.org/all/20230917214220.637721-1-jinghao7@illinois.edu/

* Address feddback from Alexei
  * Make the makefile smarter to detect the presence of ubsan in the compiler.

v1 -> v2
v1: https://lore.kernel.org/all/20230818164643.97782-1-jinghao@linux.ibm.com/

* Address feedback from Daniel
  * Add missing NULL check for calloc return value.
  * Remove the extra operation that sets links pointer to NULL after free.

Ruowen Qin (1):
  samples/bpf: Add -fsanitize=bounds to userspace programs

 samples/bpf/Makefile | 3 +++
 1 file changed, 3 insertions(+)

-- 
2.42.0


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

end of thread, other threads:[~2023-09-28 16:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-27  4:50 [PATCH bpf-next v3 0/1] samples/bpf: syscall_tp_user: Refactor and fix array index out-of-bounds bug ruowenq2
2023-09-27  4:50 ` [PATCH bpf-next v3 1/1] samples/bpf: Add -fsanitize=bounds to userspace programs ruowenq2
2023-09-27 11:03   ` Jiri Olsa
2023-09-27 23:19     ` ruowenq2
2023-09-28  8:15       ` Jiri Olsa
2023-09-28  9:19         ` Jinghao Jia
2023-09-28 14:03           ` Jiri Olsa
2023-09-28 16:40 ` [PATCH bpf-next v3 0/1] samples/bpf: syscall_tp_user: Refactor and fix array index out-of-bounds bug 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