All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Subject: [PATCH 0/3] fuse: kill suid/sgid on fallocate, copy_file_range and passthrough writes with KILLPRIV_V2
@ 2026-11-22 13:24 Han-Wen Nienhuys
  2026-11-22 13:24 ` [PATCH 1/2] fuse: kill suid/sgid on fallocate and copy_file_range " Han-Wen Nienhuys
  2026-11-22 13:24 ` [PATCH 2/2] fuse: bump protocol minor version to 48 Han-Wen Nienhuys
  0 siblings, 2 replies; 3+ messages in thread
From: Han-Wen Nienhuys @ 2026-11-22 13:24 UTC (permalink / raw)
  To: amir73il, miklos
  Cc: fuse-devel, linux-fsdevel, mmitar, bernd, Han-Wen Nienhuys

With FUSE_HANDLE_KILLPRIV_V2, an unprivileged fallocate(),
copy_file_range() or passthrough write leaves the suid/sgid bits set,
because the kernel never asks the server to clear them. Mitar reported
this in [1], and Bernd posted a fix in [2].

Patch 1 is Bernd's fix, rebased on the most recent pull of FUSE
fixes[3] in Linus' tree, otherwise unchanged.

Patch 2 bumps the FUSE protocol minor version to 48, so a server can
tell whether the kernel has the fix before it asks for
FUSE_HANDLE_KILLPRIV_V2.

Patch 3 adds a selftest. It runs a raw /dev/fuse server and checks
which kill requests reach it.

[1] https://lore.kernel.org/fuse-devel/CAKLmikMhOYpGEw6uCqX_Bm0JPEg-4FhdJMNa9+tgtw3-Kf+eZg@mail.gmail.com/
[2] https://lore.kernel.org/fuse-devel/e75cf549-07a6-4095-bbf8-8caff7a3338b@bsbernd.com/
[3] https://lore.kernel.org/fuse-devel/179520930874.792202.7768867709024262369.pr-tracker-bot@kernel.org/

Bernd Schubert (1):
  fuse: kill suid/sgid on fallocate and copy_file_range with KILLPRIV_V2

Han-Wen Nienhuys (1):
  fuse: bump protocol minor version to 48

 fs/fuse/dir.c             | 13 +++++++++++--
 fs/fuse/file.c            |  3 ++-
 fs/fuse/fuse_i.h          |  2 +-
 include/uapi/linux/fuse.h |  6 +++++-
 4 files changed, 19 insertions(+), 5 deletions(-)

-- 
2.56.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] fuse: kill suid/sgid on fallocate and copy_file_range with KILLPRIV_V2
  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
  2026-11-22 13:24 ` [PATCH 2/2] fuse: bump protocol minor version to 48 Han-Wen Nienhuys
  1 sibling, 0 replies; 3+ messages in thread
From: Han-Wen Nienhuys @ 2026-11-22 13:24 UTC (permalink / raw)
  To: amir73il, miklos
  Cc: fuse-devel, linux-fsdevel, mmitar, bernd, Han-Wen Nienhuys

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] fuse: bump protocol minor version to 48
  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 ` [PATCH 1/2] fuse: kill suid/sgid on fallocate and copy_file_range " Han-Wen Nienhuys
@ 2026-11-22 13:24 ` Han-Wen Nienhuys
  1 sibling, 0 replies; 3+ messages in thread
From: Han-Wen Nienhuys @ 2026-11-22 13:24 UTC (permalink / raw)
  To: amir73il, miklos
  Cc: fuse-devel, linux-fsdevel, mmitar, bernd, Han-Wen Nienhuys

The commit "fuse: kill suid/sgid on fallocate and copy_file_range with
KILLPRIV_V2" fixes a bug with FUSE_HANDLE_KILLPRIV_V2: the kernel did
not tell the server to clear suid/sgid after fallocate,
copy_file_range and passthrough writes.

A server cannot detect this bug by itself. All it sees is an empty
FUSE_SETATTR, and the kernel also sends one when only
security.capability must be removed.

Bump the minor version, so a server can check whether the kernel has
the fix before it asks for FUSE_HANDLE_KILLPRIV_V2, for example when
it also uses passthrough.

This is not meant for stable. On older kernels, a FUSE server should
use a workaround instead.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Han-Wen Nienhuys <hanwenn@gmail.com>
---
 include/uapi/linux/fuse.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
index cb9e9554f0ef..6f6baded766b 100644
--- a/include/uapi/linux/fuse.h
+++ b/include/uapi/linux/fuse.h
@@ -258,6 +258,10 @@
  *  - add FUSE_NOTIFY_BACKING_MAP, fuse_notify_backing_map_out, fuse_extent
  *  - add FUSE_BACKING_MAP_CREATE, FUSE_BACKING_MAP_CYCLIC
  *  - extend the meaning of FUSE_HAS_INODE_DAX and FUSE_ATTR_DAX
+ *
+ *  7.48
+ *  - with FUSE_HANDLE_KILLPRIV_V2, send FATTR_KILL_SUIDGID in the SETATTR
+ *    that precedes fallocate, copy_file_range and passthrough writes
  */
 
 #ifndef _LINUX_FUSE_H
@@ -293,7 +297,7 @@
 #define FUSE_KERNEL_VERSION 7
 
 /** Minor version number of this interface */
-#define FUSE_KERNEL_MINOR_VERSION 47
+#define FUSE_KERNEL_MINOR_VERSION 48
 
 /** The node ID of the root inode */
 #define FUSE_ROOT_ID 1
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-22 13:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 1/2] fuse: kill suid/sgid on fallocate and copy_file_range " Han-Wen Nienhuys
2026-11-22 13:24 ` [PATCH 2/2] fuse: bump protocol minor version to 48 Han-Wen Nienhuys

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.