From: Dave Marchevsky <davemarchevsky@fb.com>
To: <linux-fsdevel@vger.kernel.org>
Cc: Miklos Szeredi <miklos@szeredi.hu>,
kernel-team <kernel-team@fb.com>,
Dave Marchevsky <davemarchevsky@fb.com>,
Andrii Nakryiko <andrii@kernel.org>,
Christian Brauner <brauner@kernel.org>
Subject: [PATCH v2] fuse: Rearrange fuse_allow_current_process checks
Date: Thu, 20 Oct 2022 13:14:09 -0700 [thread overview]
Message-ID: <20221020201409.1815316-1-davemarchevsky@fb.com> (raw)
This is a followup to a previous commit of mine [0], which added the
allow_sys_admin_access && capable(CAP_SYS_ADMIN) check. This patch
rearranges the order of checks in fuse_allow_current_process without
changing functionality.
[0] added allow_sys_admin_access && capable(CAP_SYS_ADMIN) check to the
beginning of the function, with the reasoning that
allow_sys_admin_access should be an 'escape hatch' for users with
CAP_SYS_ADMIN, allowing them to skip any subsequent checks.
However, placing this new check first results in many capable() calls when
allow_sys_admin_access is set, where another check would've also
returned 1. This can be problematic when a BPF program is tracing
capable() calls.
At Meta we ran into such a scenario recently. On a host where
allow_sys_admin_access is set but most of the FUSE access is from
processes which would pass other checks - i.e. they don't need
CAP_SYS_ADMIN 'escape hatch' - this results in an unnecessary capable()
call for each fs op. We also have a daemon tracing capable() with BPF and
doing some data collection, so tracing these extraneous capable() calls
has the potential to regress performance for an application doing many
FUSE ops.
So rearrange the order of these checks such that CAP_SYS_ADMIN 'escape
hatch' is checked last. Previously, if allow_other is set on the
fuse_conn, uid/gid checking doesn't happen as current_in_userns result
is returned. It's necessary to add a 'goto' here to skip past uid/gid
check to maintain those semantics here.
[0]: commit 9ccf47b26b73 ("fuse: Add module param for CAP_SYS_ADMIN access bypassing allow_other")
Signed-off-by: Dave Marchevsky <davemarchevsky@fb.com>
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Cc: Christian Brauner <brauner@kernel.org>
---
v1 -> v2: lore.kernel.org/linux-fsdevel/20221020183830.1077143-1-davemarchevsky@fb.com
* Add missing brackets to allow_other if statement (Andrii)
fs/fuse/dir.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 2c4b08a6ec81..2f14e90907a2 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -1254,11 +1254,11 @@ int fuse_allow_current_process(struct fuse_conn *fc)
{
const struct cred *cred;
- if (allow_sys_admin_access && capable(CAP_SYS_ADMIN))
- return 1;
-
- if (fc->allow_other)
- return current_in_userns(fc->user_ns);
+ if (fc->allow_other) {
+ if (current_in_userns(fc->user_ns))
+ return 1;
+ goto skip_cred_check;
+ }
cred = current_cred();
if (uid_eq(cred->euid, fc->user_id) &&
@@ -1269,6 +1269,10 @@ int fuse_allow_current_process(struct fuse_conn *fc)
gid_eq(cred->gid, fc->group_id))
return 1;
+skip_cred_check:
+ if (allow_sys_admin_access && capable(CAP_SYS_ADMIN))
+ return 1;
+
return 0;
}
--
2.30.2
next reply other threads:[~2022-10-20 20:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-20 20:14 Dave Marchevsky [this message]
2022-10-21 8:09 ` [PATCH v2] fuse: Rearrange fuse_allow_current_process checks Christian Brauner
2022-10-21 16:02 ` Andrii Nakryiko
2022-10-22 13:30 ` Christian Brauner
2022-10-24 16:53 ` Andrii Nakryiko
2022-10-21 16:05 ` Andrii Nakryiko
2022-10-22 13:22 ` Christian Brauner
2022-10-24 13:44 ` Seth Forshee
2022-10-24 16:52 ` Andrii Nakryiko
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=20221020201409.1815316-1-davemarchevsky@fb.com \
--to=davemarchevsky@fb.com \
--cc=andrii@kernel.org \
--cc=brauner@kernel.org \
--cc=kernel-team@fb.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=miklos@szeredi.hu \
/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