BPF List
 help / color / mirror / Atom feed
* [RFC PATCH bpf-next 0/3] compiler attribute: define __user as __attribute__((btf_type_tag("user")))
@ 2021-11-17 20:39 Yonghong Song
  2021-11-17 20:39 ` [RFC PATCH bpf-next 1/3] compiler_types: " Yonghong Song
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yonghong Song @ 2021-11-17 20:39 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, bpf
  Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Jose E . Marchesi, kernel-team

Latest clang compiler supports a type attribute like
  __attribute__((btf_type_tag("<arbitrary string>")))
which can be used in places like __user/__rcu.
With the above attribute, clang was able to preserve the "<arbitrary string>"
info in dwarf and subsequently BTF. For example __user/__rcu
attribute can be preserved in BTF, which currently is loaded inside
the kernel. Such information can then be used by verifier to check
bpf program memory access conforms to the access attribute.
Please see Patches 1 and 2 for details.

This is a RFC patch as it depends on pahole patch and
a new pahole version. The following is pahole patch link:
  https://lore.kernel.org/bpf/20211117202214.3268824-1-yhs@fb.com/
Second, for bpf verifier use of this new __user tag information,
I only implemented support to check function parameter
dereference. More work will be needed to check other
non function parameter memory accesses.

Yonghong Song (3):
  compiler_types: define __user as __attribute__((btf_type_tag("user")))
  bpf: reject program if a __user tagged memory accessed in kernel way
  selftests/bpf: add a selftest with __user tag

 include/linux/bpf.h                           |  1 +
 include/linux/bpf_verifier.h                  |  1 +
 include/linux/btf.h                           |  5 ++++
 include/linux/compiler_types.h                |  2 ++
 kernel/bpf/btf.c                              | 15 +++++++++---
 kernel/bpf/verifier.c                         | 16 ++++++++++---
 lib/Kconfig.debug                             |  5 ++++
 .../selftests/bpf/bpf_testmod/bpf_testmod.c   |  9 +++++++
 .../selftests/bpf/prog_tests/btf_tag.c        | 23 ++++++++++++++++++
 .../selftests/bpf/progs/btf_type_tag_user.c   | 24 +++++++++++++++++++
 10 files changed, 95 insertions(+), 6 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/btf_type_tag_user.c

-- 
2.30.2


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

end of thread, other threads:[~2021-11-17 20:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-17 20:39 [RFC PATCH bpf-next 0/3] compiler attribute: define __user as __attribute__((btf_type_tag("user"))) Yonghong Song
2021-11-17 20:39 ` [RFC PATCH bpf-next 1/3] compiler_types: " Yonghong Song
2021-11-17 20:39 ` [RFC PATCH bpf-next 2/3] bpf: reject program if a __user tagged memory accessed in kernel way Yonghong Song
2021-11-17 20:39 ` [RFC PATCH bpf-next 3/3] selftests/bpf: add a selftest with __user tag Yonghong Song

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