From: Song Liu <songliubraving@fb.com>
To: Alexei Starovoitov <ast@kernel.org>
Cc: Andy Lutomirski <luto@amacapital.net>,
"davem@davemloft.net" <davem@davemloft.net>,
"peterz@infradead.org" <peterz@infradead.org>,
"rostedt@goodmis.org" <rostedt@goodmis.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
Kernel Team <Kernel-team@fb.com>,
"linux-api@vger.kernel.org" <linux-api@vger.kernel.org>
Subject: Re: [PATCH v2 bpf-next 2/3] bpf: implement CAP_BPF
Date: Thu, 29 Aug 2019 06:04:42 +0000 [thread overview]
Message-ID: <B28631A9-BB92-404A-BD58-7A737BCF10C9@fb.com> (raw)
In-Reply-To: <20190829051253.1927291-2-ast@kernel.org>
> On Aug 28, 2019, at 10:12 PM, Alexei Starovoitov <ast@kernel.org> wrote:
>
[...]
> diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
> index 44e2d640b088..91a7f25512ca 100644
> --- a/tools/testing/selftests/bpf/test_verifier.c
> +++ b/tools/testing/selftests/bpf/test_verifier.c
> @@ -805,10 +805,20 @@ static void do_test_fixup(struct bpf_test *test, enum bpf_prog_type prog_type,
> }
> }
>
> +struct libcap {
> + struct __user_cap_header_struct hdr;
> + struct __user_cap_data_struct data[2];
> +};
> +
I am confused by struct libcap. Why do we need it?
> static int set_admin(bool admin)
> {
> cap_t caps;
> - const cap_value_t cap_val = CAP_SYS_ADMIN;
> + /* need CAP_BPF to load progs and CAP_NET_ADMIN to run networking progs,
> + * and CAP_TRACING to create stackmap
> + */
> + const cap_value_t cap_net_admin = CAP_NET_ADMIN;
> + const cap_value_t cap_sys_admin = CAP_SYS_ADMIN;
> + struct libcap *cap;
> int ret = -1;
>
> caps = cap_get_proc();
> @@ -816,11 +826,26 @@ static int set_admin(bool admin)
> perror("cap_get_proc");
> return -1;
> }
> - if (cap_set_flag(caps, CAP_EFFECTIVE, 1, &cap_val,
> + cap = (struct libcap *)caps;
> + if (cap_set_flag(caps, CAP_EFFECTIVE, 1, &cap_sys_admin, CAP_CLEAR)) {
> + perror("cap_set_flag clear admin");
> + goto out;
> + }
> + if (cap_set_flag(caps, CAP_EFFECTIVE, 1, &cap_net_admin,
> admin ? CAP_SET : CAP_CLEAR)) {
> - perror("cap_set_flag");
> + perror("cap_set_flag set_or_clear net");
> goto out;
> }
> + /* libcap is likely old and simply ignores CAP_BPF and CAP_TRACING,
> + * so update effective bits manually
> + */
> + if (admin) {
> + cap->data[1].effective |= 1 << (38 /* CAP_BPF */ - 32);
> + cap->data[1].effective |= 1 << (39 /* CAP_TRACING */ - 32);
> + } else {
> + cap->data[1].effective &= ~(1 << (38 - 32));
> + cap->data[1].effective &= ~(1 << (39 - 32));
> + }
And why we do not need cap->data[0]?
Thanks,
Song
next prev parent reply other threads:[~2019-08-29 6:05 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-29 5:12 [PATCH v2 bpf-next 1/3] capability: introduce CAP_BPF and CAP_TRACING Alexei Starovoitov
2019-08-29 5:12 ` [PATCH v2 bpf-next 2/3] bpf: implement CAP_BPF Alexei Starovoitov
2019-08-29 6:04 ` Song Liu [this message]
2019-08-29 17:28 ` Alexei Starovoitov
2019-08-29 15:32 ` Daniel Borkmann
2019-08-29 17:30 ` Alexei Starovoitov
2019-08-30 15:19 ` Nicolas Dichtel
2019-09-04 1:39 ` Alexei Starovoitov
2019-09-04 15:16 ` Daniel Borkmann
2019-09-04 15:21 ` Alexei Starovoitov
2019-09-05 8:37 ` Daniel Borkmann
2019-09-05 22:00 ` Alexei Starovoitov
2019-08-29 5:12 ` [PATCH v2 bpf-next 3/3] perf: implement CAP_TRACING Alexei Starovoitov
2019-08-29 6:06 ` Song Liu
2019-08-29 6:00 ` [PATCH v2 bpf-next 1/3] capability: introduce CAP_BPF and CAP_TRACING Song Liu
2019-08-29 7:44 ` Toke Høiland-Jørgensen
2019-08-29 17:24 ` Alexei Starovoitov
2019-08-29 18:05 ` Toke Høiland-Jørgensen
2019-08-29 20:25 ` Jesper Dangaard Brouer
2019-08-29 21:10 ` Alexei Starovoitov
2019-08-29 13:36 ` Nicolas Dichtel
2019-08-29 17:25 ` Alexei Starovoitov
2019-08-29 15:47 ` Daniel Borkmann
2019-08-29 16:28 ` Andy Lutomirski
2019-08-30 4:16 ` Alexei Starovoitov
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=B28631A9-BB92-404A-BD58-7A737BCF10C9@fb.com \
--to=songliubraving@fb.com \
--cc=Kernel-team@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=linux-api@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.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;
as well as URLs for NNTP newsgroup(s).