From: Yonghong Song <yhs@fb.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>, <bpf@vger.kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Linus Torvalds <torvalds@linux-foundation.org>,
Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>,
"Jose E . Marchesi" <jose.marchesi@oracle.com>,
<kernel-team@fb.com>, Masami Hiramatsu <mhiramat@kernel.org>
Subject: Re: [PATCH bpf-next 4/5] selftests/bpf: add a selftest with __user tag
Date: Sun, 19 Dec 2021 19:51:52 -0800 [thread overview]
Message-ID: <fb5fffd0-0cd8-893b-67cd-f419f591736c@fb.com> (raw)
In-Reply-To: <20211220015110.3rqxk5qwub3pa2gh@ast-mbp.dhcp.thefacebook.com>
On 12/19/21 5:51 PM, Alexei Starovoitov wrote:
> On Thu, Dec 09, 2021 at 09:35:59AM -0800, Yonghong Song wrote:
>> Added a selftest with two __user usages: a __user pointer-type argument
>> and a __user pointer-type struct member. In both cases,
>> directly accessing the user memory will result verification failure.
> ...
>> diff --git a/tools/testing/selftests/bpf/progs/btf_type_tag_user.c b/tools/testing/selftests/bpf/progs/btf_type_tag_user.c
>> new file mode 100644
>> index 000000000000..e149854f42dd
>> --- /dev/null
>> +++ b/tools/testing/selftests/bpf/progs/btf_type_tag_user.c
>> @@ -0,0 +1,29 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/* Copyright (c) 2021 Facebook */
>> +#include "vmlinux.h"
>> +#include <bpf/bpf_helpers.h>
>> +#include <bpf/bpf_tracing.h>
>> +
>> +struct bpf_testmod_btf_type_tag_1 {
>> + int a;
>> +};
>> +
>> +struct bpf_testmod_btf_type_tag_2 {
>> + struct bpf_testmod_btf_type_tag_1 *p;
>> +};
>> +
>> +int g;
>> +
>> +SEC("fentry/bpf_testmod_test_btf_type_tag_user_1")
>> +int BPF_PROG(test_user1, struct bpf_testmod_btf_type_tag_1 *arg)
>> +{
>> + g = arg->a;
>> + return 0;
>> +}
>> +
>> +SEC("fentry/bpf_testmod_test_btf_type_tag_user_2")
>> +int BPF_PROG(test_user2, struct bpf_testmod_btf_type_tag_2 *arg)
>> +{
>> + g = arg->p->a;
>> + return 0;
>> +}
>
> This is a targeted synthetic test. Great, but can you add one
> that probes real kernel function like:
> getsockname(int fd, struct sockaddr __user *usockaddr
> or
> getpeername(int fd, struct sockaddr __user *usockaddr > and the bpf prog tries to deref usockaddr ?
Ack. Will do.
next prev parent reply other threads:[~2021-12-20 3:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-09 17:35 bpf: add __user tagging support in vmlinux BTF Yonghong Song
2021-12-09 17:35 ` [PATCH bpf-next 1/5] compiler_types: define __user as __attribute__((btf_type_tag("user"))) Yonghong Song
2021-12-09 17:35 ` [PATCH bpf-next 2/5] bpf: reject program if a __user tagged memory accessed in kernel way Yonghong Song
2021-12-20 1:45 ` Alexei Starovoitov
2021-12-20 3:51 ` Yonghong Song
2021-12-09 17:35 ` [PATCH bpf-next 3/5] selftests/bpf: rename btf_decl_tag.c to test_btf_decl_tag.c Yonghong Song
2021-12-09 17:35 ` [PATCH bpf-next 4/5] selftests/bpf: add a selftest with __user tag Yonghong Song
2021-12-20 1:51 ` Alexei Starovoitov
2021-12-20 3:51 ` Yonghong Song [this message]
2021-12-09 17:36 ` [PATCH bpf-next 5/5] selftests/bpf: specify pahole version requirement for btf_tag test 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=fb5fffd0-0cd8-893b-67cd-f419f591736c@fb.com \
--to=yhs@fb.com \
--cc=alexei.starovoitov@gmail.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 \
--cc=mhiramat@kernel.org \
--cc=torvalds@linux-foundation.org \
/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