From: Han-Wen Nienhuys <hanwenn@gmail.com>
To: amir73il@gmail.com, miklos@szeredi.hu
Cc: fuse-devel@lists.linux.dev, linux-fsdevel@lists.linux.dev,
mmitar@gmail.com, bernd@bsbernd.com,
Han-Wen Nienhuys <hanwenn@gmail.com>
Subject: [PATCH 1/2] fuse: kill suid/sgid on fallocate and copy_file_range with KILLPRIV_V2
Date: Sun, 22 Nov 2026 14:24:53 +0100 [thread overview]
Message-ID: <20261122132454.18764-2-hanwenn@gmail.com> (raw)
In-Reply-To: <20261122132454.18764-1-hanwenn@gmail.com>
From: Bernd Schubert <bernd@bsbernd.com>
With FUSE_HANDLE_KILLPRIV_V2, fuse_setattr() drops the mode change that
file_remove_privs() asks for and relies on the server to clear the bits
when it handles the following WRITE request (FUSE_WRITE_KILL_SUIDGID).
fallocate() and copy_file_range() send no WRITE, and the SETATTR sent
from file_modified() carries no kill flag. A caller without CAP_FSETID
can therefore change the contents of a setuid file while the setuid bit
stays set; write() on the same file clears it.
Send FATTR_KILL_SUIDGID in that SETATTR. The VFS sets ATTR_KILL_SUID and
ATTR_KILL_SGID only after its own CAP_FSETID check, so capable() is not
tested again.
This affects every caller of file_remove_privs() and kiocb_modified(),
not only fallocate and copy_file_range: passthrough writes
(backing_file_write_iter()), ext_map writes, DAX writes, and ordinary
cached writes (fuse_perform_write()). Before, their SETATTRs went out
with valid == 0, so no requests are added. On an ordinary write the
server is now asked twice, in the SETATTR and again by
FUSE_WRITE_KILL_SUIDGID on the WRITE, which then finds the bits
already cleared. This happens once: the SETATTR reply updates the
cached mode, so later writes find nothing to kill.
[HWN: rebased onto v7.4-rc3, extended the commit message]
Fixes: 8981bdfda744 ("fuse: don't send ATTR_MODE to kill suid/sgid for handle_killpriv_v2")
Reported-by: Mitar <mmitar@gmail.com>
Closes: https://lore.kernel.org/fuse-devel/CAKLmikMhOYpGEw6uCqX_Bm0JPEg-4FhdJMNa9+tgtw3-Kf+eZg@mail.gmail.com/
Signed-off-by: Bernd Schubert <bernd@bsbernd.com>
Link: https://lore.kernel.org/fuse-devel/e75cf549-07a6-4095-bbf8-8caff7a3338b@bsbernd.com/
Signed-off-by: Han-Wen Nienhuys <hanwenn@gmail.com>
---
fs/fuse/dir.c | 13 +++++++++++--
fs/fuse/file.c | 3 ++-
fs/fuse/fuse_i.h | 2 +-
3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index a04d93d5fc44..ae62b975a1bc 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -2148,7 +2148,7 @@ int fuse_flush_times(struct inode *inode, struct fuse_file *ff)
* and the actual truncation by hand.
*/
int fuse_do_setattr(const struct mnt_idmap *idmap, struct dentry *dentry,
- struct iattr *attr, struct file *file)
+ struct iattr *attr, struct file *file, bool kill_suidgid)
{
struct inode *inode = d_inode(dentry);
struct fuse_mount *fm = get_fuse_mount(inode);
@@ -2241,6 +2241,13 @@ int fuse_do_setattr(const struct mnt_idmap *idmap, struct dentry *dentry,
attr->ia_valid & (ATTR_UID | ATTR_GID))
inarg.valid |= FATTR_KILL_SUIDGID;
+ /*
+ * fuse_setattr() dropped the mode change for the kill request. The VFS
+ * already applied the CAP_FSETID rule, so no capable() test here.
+ */
+ if (fc->handle_killpriv_v2 && kill_suidgid)
+ inarg.valid |= FATTR_KILL_SUIDGID;
+
if (attr->ia_valid & ATTR_SIZE) {
/* For mandatory locking in truncate */
inarg.valid |= FATTR_LOCKOWNER;
@@ -2337,6 +2344,7 @@ static int fuse_setattr(const struct mnt_idmap *idmap, struct dentry *entry,
struct inode *inode = d_inode(entry);
struct fuse_conn *fc = get_fuse_conn(inode);
struct file *file = (attr->ia_valid & ATTR_FILE) ? attr->ia_file : NULL;
+ bool kill_suidgid = false;
int ret;
if (fuse_is_bad(inode))
@@ -2346,6 +2354,7 @@ static int fuse_setattr(const struct mnt_idmap *idmap, struct dentry *entry,
return -EACCES;
if (attr->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) {
+ kill_suidgid = true;
attr->ia_valid &= ~(ATTR_KILL_SUID | ATTR_KILL_SGID |
ATTR_MODE);
@@ -2378,7 +2387,7 @@ static int fuse_setattr(const struct mnt_idmap *idmap, struct dentry *entry,
if (!attr->ia_valid)
return 0;
- ret = fuse_do_setattr(idmap, entry, attr, file);
+ ret = fuse_do_setattr(idmap, entry, attr, file, kill_suidgid);
if (!ret) {
/*
* If filesystem supports acls it may have updated acl xattrs in
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 993a1d2b3151..efd35218f613 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -2766,7 +2766,8 @@ static void fuse_do_truncate(struct file *file)
attr.ia_file = file;
attr.ia_valid |= ATTR_FILE;
- fuse_do_setattr(file_mnt_idmap(file), file_dentry(file), &attr, file);
+ fuse_do_setattr(file_mnt_idmap(file), file_dentry(file), &attr, file,
+ false);
}
static inline loff_t fuse_round_up(struct fuse_conn *fc, loff_t off)
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index e0992fcbcc55..6ed2d71dc9d1 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1250,7 +1250,7 @@ int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
int fuse_do_setattr(const struct mnt_idmap *idmap, struct dentry *dentry,
- struct iattr *attr, struct file *file);
+ struct iattr *attr, struct file *file, bool kill_suidgid);
void fuse_unlock_inode(struct inode *inode, bool locked);
bool fuse_lock_inode(struct inode *inode);
--
2.56.1
next prev parent reply other threads:[~2026-11-22 13:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 13:24 [PATCH 0/2] Subject: [PATCH 0/3] fuse: kill suid/sgid on fallocate, copy_file_range and passthrough writes with KILLPRIV_V2 Han-Wen Nienhuys
2026-11-22 13:24 ` Han-Wen Nienhuys [this message]
2026-11-22 13:24 ` [PATCH 2/2] fuse: bump protocol minor version to 48 Han-Wen Nienhuys
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=20261122132454.18764-2-hanwenn@gmail.com \
--to=hanwenn@gmail.com \
--cc=amir73il@gmail.com \
--cc=bernd@bsbernd.com \
--cc=fuse-devel@lists.linux.dev \
--cc=linux-fsdevel@lists.linux.dev \
--cc=miklos@szeredi.hu \
--cc=mmitar@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.