From: Stephen Smalley <stephen.smalley.work@gmail.com>
To: KP Singh <kpsingh@chromium.org>
Cc: linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
Andrii Nakryiko <andriin@fb.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Paul Turner <pjt@google.com>, Jann Horn <jannh@google.com>,
Florent Revest <revest@chromium.org>,
Brendan Jackman <jackmanb@chromium.org>,
Paul Moore <paul@paul-moore.com>,
jmorris@namei.org
Subject: Re: [PATCH bpf-next v4 4/7] bpf: Attachment verification for BPF_MODIFY_RETURN
Date: Thu, 5 Mar 2020 08:43:11 -0500 [thread overview]
Message-ID: <CAEjxPJ4G4sp5_zHXxhe+crafNGV-oZZZ2YYbbMb61BZx0F_ujw@mail.gmail.com> (raw)
In-Reply-To: <20200304191853.1529-5-kpsingh@chromium.org>
On Wed, Mar 4, 2020 at 2:20 PM KP Singh <kpsingh@chromium.org> wrote:
>
> From: KP Singh <kpsingh@google.com>
>
> - Allow BPF_MODIFY_RETURN attachment only to functions that are:
>
> * Whitelisted for error injection by checking
> within_error_injection_list. Similar discussions happened for the
> bpf_override_return helper.
>
> * security hooks, this is expected to be cleaned up with the LSM
> changes after the KRSI patches introduce the LSM_HOOK macro:
>
> https://lore.kernel.org/bpf/20200220175250.10795-1-kpsingh@chromium.org/
>
> - The attachment is currently limited to functions that return an int.
> This can be extended later other types (e.g. PTR).
>
> Signed-off-by: KP Singh <kpsingh@google.com>
> Acked-by: Andrii Nakryiko <andriin@fb.com>
> ---
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 2460c8e6b5be..ae32517d4ccd 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -9800,6 +9801,33 @@ static int check_struct_ops_btf_id(struct bpf_verifier_env *env)
>
> return 0;
> }
> +#define SECURITY_PREFIX "security_"
> +
> +static int check_attach_modify_return(struct bpf_verifier_env *env)
> +{
> + struct bpf_prog *prog = env->prog;
> + unsigned long addr = (unsigned long) prog->aux->trampoline->func.addr;
> +
> + if (within_error_injection_list(addr))
> + return 0;
> +
> + /* This is expected to be cleaned up in the future with the KRSI effort
> + * introducing the LSM_HOOK macro for cleaning up lsm_hooks.h.
> + */
> + if (!strncmp(SECURITY_PREFIX, prog->aux->attach_func_name,
> + sizeof(SECURITY_PREFIX) - 1)) {
> +
> + if (!capable(CAP_MAC_ADMIN))
> + return -EPERM;
CAP_MAC_ADMIN was originally introduced for Smack and is not
all-powerful wrt SELinux, so this is not a sufficient check for
SELinux.
We would want an actual security hook called here so we can implement
a specific check over userspace
being able to attach BPF progs to LSM hooks. CAP_MAC_ADMIN has other
connotations to SELinux (presently the
ability to set/get file security labels that are not known to the
currently loaded policy).
next prev parent reply other threads:[~2020-03-05 13:42 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-04 19:18 [PATCH bpf-next v4 0/7] Introduce BPF_MODIFY_RET tracing progs KP Singh
2020-03-04 19:18 ` [PATCH bpf-next v4 1/7] bpf: Refactor trampoline update code KP Singh
2020-03-04 19:18 ` [PATCH bpf-next v4 2/7] bpf: JIT helpers for fmod_ret progs KP Singh
2020-03-04 19:18 ` [PATCH bpf-next v4 3/7] bpf: Introduce BPF_MODIFY_RETURN KP Singh
2020-03-05 13:51 ` Stephen Smalley
2020-03-05 15:54 ` KP Singh
2020-03-05 17:35 ` Casey Schaufler
2020-03-05 18:03 ` Stephen Smalley
2020-03-05 18:47 ` Casey Schaufler
2020-03-05 19:43 ` Stephen Smalley
2020-03-05 21:16 ` KP Singh
2020-03-04 19:18 ` [PATCH bpf-next v4 4/7] bpf: Attachment verification for BPF_MODIFY_RETURN KP Singh
2020-03-05 13:43 ` Stephen Smalley [this message]
2020-03-05 17:21 ` Alexei Starovoitov
2020-03-04 19:18 ` [PATCH bpf-next v4 5/7] tools/libbpf: Add support " KP Singh
2020-03-04 19:18 ` [PATCH bpf-next v4 6/7] bpf: Add test ops for BPF_PROG_TYPE_TRACING KP Singh
2020-03-04 19:18 ` [PATCH bpf-next v4 7/7] bpf: Add selftests for BPF_MODIFY_RETURN KP Singh
2020-03-04 22:17 ` [PATCH bpf-next v4 0/7] Introduce BPF_MODIFY_RET tracing progs Alexei Starovoitov
2020-03-05 17:43 ` KP Singh
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=CAEjxPJ4G4sp5_zHXxhe+crafNGV-oZZZ2YYbbMb61BZx0F_ujw@mail.gmail.com \
--to=stephen.smalley.work@gmail.com \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jackmanb@chromium.org \
--cc=jannh@google.com \
--cc=jmorris@namei.org \
--cc=kpsingh@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=pjt@google.com \
--cc=revest@chromium.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).