public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Chenbo Feng <chenbofeng.kernel@gmail•com>
To: netdev@vger•kernel.org, ast@kernel•org
Cc: Jeffrey Vander Stoep <jeffv@google•com>,
	lorenzo@google•com, Daniel Borkmann <daniel@iogearbox•net>,
	Chenbo Feng <fengc@google•com>
Subject: [PATCH bpf-next] bpf: skip unnecessary capability check
Date: Mon, 19 Mar 2018 17:57:27 -0700	[thread overview]
Message-ID: <20180320005727.197544-1-chenbofeng.kernel@gmail.com> (raw)

From: Chenbo Feng <fengc@google•com>

The current check statement in BPF syscall will do a capability check
for CAP_SYS_ADMIN before checking sysctl_unprivileged_bpf_disabled. This
code path will trigger unnecessary security hooks on capability checking
and cause false alarms on unprivileged process trying to get CAP_SYS_ADMIN
access. This can be resolved by simply switch the order of the statement
and CAP_SYS_ADMIN is not required anyway if unprivileged bpf syscall is
allowed.

Signed-off-by: Chenbo Feng <fengc@google•com>
---
 kernel/bpf/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index e24aa3241387..43f95d190eea 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -1845,7 +1845,7 @@ SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, siz
 	union bpf_attr attr = {};
 	int err;
 
-	if (!capable(CAP_SYS_ADMIN) && sysctl_unprivileged_bpf_disabled)
+	if (sysctl_unprivileged_bpf_disabled && !capable(CAP_SYS_ADMIN))
 		return -EPERM;
 
 	err = check_uarg_tail_zero(uattr, sizeof(attr), size);
-- 
2.16.2.804.g6dcf76e118-goog

             reply	other threads:[~2018-03-20  0:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-20  0:57 Chenbo Feng [this message]
2018-03-20 11:37 ` [PATCH bpf-next] bpf: skip unnecessary capability check Lorenzo Colitti
2018-03-20 22:55   ` Daniel Borkmann

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=20180320005727.197544-1-chenbofeng.kernel@gmail.com \
    --to=chenbofeng.kernel@gmail$(echo .)com \
    --cc=ast@kernel$(echo .)org \
    --cc=daniel@iogearbox$(echo .)net \
    --cc=fengc@google$(echo .)com \
    --cc=jeffv@google$(echo .)com \
    --cc=lorenzo@google$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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