From: Yonghong Song <yhs@fb.com>
To: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>, <bpf@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
"Jose E . Marchesi" <jose.marchesi@oracle.com>,
<kernel-team@fb.com>
Subject: [RFC PATCH bpf-next 0/3] compiler attribute: define __user as __attribute__((btf_type_tag("user")))
Date: Wed, 17 Nov 2021 12:39:14 -0800 [thread overview]
Message-ID: <20211117203914.3355618-1-yhs@fb.com> (raw)
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
next reply other threads:[~2021-11-17 20:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-17 20:39 Yonghong Song [this message]
2021-11-17 20:39 ` [RFC PATCH bpf-next 1/3] compiler_types: define __user as __attribute__((btf_type_tag("user"))) 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211117203914.3355618-1-yhs@fb.com \
--to=yhs@fb.com \
--cc=andrii@kernel.org \
--cc=arnaldo.melo@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jose.marchesi@oracle.com \
--cc=kernel-team@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox