RFC compiler attribute: define __user as __attribute__((btf_type_tag("user")))
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v2 RFC Latest3 patches 0 repliesNew
- v1 RFC3 patches 0 repliesSuperseded
Changes in v2 from the cover letter
- kernel test bot reported a compilation error. Fix it.
Patches in v2 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | compiler_types: define __user as __attribute__((btf_type_tag("user")))include/ lib/ | +7 | 0 replies | |
| 2/3 | bpf: reject program if a __user tagged memory accessed in kernel wayinclude/ include/ include/ +2 more | +31 | 0 replies | |
| 3/3 | selftests/bpf: add a selftest with __user tagkernel/ tools/ tools/ +1 more | +57 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.
Cover letter [RFC PATCH bpf-next v2 0/3] compiler attribute: define __user as __attribute__((btf_type_tag("user")))
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/[email protected]/
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.
Changelog:
RFC v1 -> RFC v2:
- kernel test bot reported a compilation error. Fix it.
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 | 13 ++++++++-- kernel/bpf/verifier.c | 17 ++++++++++--- 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(+), 5 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/btf_type_tag_user.c
Signature · 1 line
2.30.2