Skip to contentSkip to conversation

xattr: require inode owner or CAP_FOWNER to write user.* xattrs on sockets

PATCH Applied Dominik Maier 2 participants 2 messages Nov 19 – Nov 20 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xattr: require inode owner or CAP_FOWNER to write user.* xattrs on sockets

Commit dc0876b9846d ("xattr: support extended attributes on sockets") enabled user.* extended attributes on S_IFSOCK inodes so services can publish protocol discovery metadata (such as user.varlink=1 or /dev/log structured logging support) on bound UNIX domain sockets.

However, connecting to a path-based AF_UNIX socket requires MAY_WRITE on the socket inode, so public system daemon sockets in /run and /dev are routinely created with mode 0666. Because xattr_permission() allows S_IFSOCK writes without checking inode_owner_or_capable(), any unprivileged local user who can connect to a 0666 socket can also call setxattr() or removexattr() to overwrite or delete the daemon's user.* attributes. Moreover, on tmpfs mounts such as /run (where unprivileged users normally cannot create files), shmem_xattr_handler_set() uses simple_xattr_set() and charges each attribute against the superblock's sbinfo->free_ispace pool, allowing an unprivileged user to exhaust /run inode space via a 0666 socket and cause -ENOSPC for privileged daemons.

Require inode_owner_or_capable(idmap, inode) when mask & MAY_WRITE is requested for user.* extended attributes on S_IFSOCK inodes, matching sticky directories while keeping unprivileged MAY_READ discovery intact.

This issue was discovered with an AI-assisted code review tool (ARTIST) and reproduced in QEMU/KVM on an unmodified v7.4-rc3 kernel without kernel modifications or error injection; a standalone reproducer is available upon maintainers' request. The fix was compile-tested with -Werror and checked with checkpatch.pl --strict; an equivalent fix was verified against the reproducer in QEMU/KVM.

Fixes dc0876b9846d ("xattr: support extended attributes on sockets")
---
 fs/xattr.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
fs/xattr.c +5 -5
index 0705801..0acea1a 100644
@@ -152,9 +152,9 @@ xattr_permission(const struct mnt_idmap *idmap, struct inode *inode,
 	}
 
 	/*
-	 * In the user.* namespace, only regular files and directories can have
-	 * extended attributes. For sticky directories, only the owner and
-	 * privileged users can write attributes.
+	 * In the user.* namespace, only regular files, directories, and
+	 * sockets can have extended attributes. For sticky directories and
+	 * sockets, only the owner and privileged users can write attributes.
 	 */
 	if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
 		switch (inode->i_mode & S_IFMT) {
@@ -163,13 +163,13 @@ xattr_permission(const struct mnt_idmap *idmap, struct inode *inode,
 		case S_IFDIR:
 			if (!(inode->i_mode & S_ISVTX))
 				break;
+			fallthrough;
+		case S_IFSOCK:
 			if (!(mask & MAY_WRITE))
 				break;
 			if (inode_owner_or_capable(idmap, inode))
 				break;
 			return -EPERM;
-		case S_IFSOCK:
-			break;
 		default:
 			return xattr_permission_error(mask);
 		}
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
maintainer Applied
#1 lore raw
Quoted 17 lines · Dominik Maier

Commit dc0876b9846d ("xattr: support extended attributes on sockets") enabled user.* extended attributes on S_IFSOCK inodes so services can publish protocol discovery metadata (such as user.varlink=1 or /dev/log structured logging support) on bound UNIX domain sockets.

However, connecting to a path-based AF_UNIX socket requires MAY_WRITE on the socket inode, so public system daemon sockets in /run and /dev are routinely created with mode 0666. Because xattr_permission() allows S_IFSOCK writes without checking inode_owner_or_capable(), any unprivileged local user who can connect to a 0666 socket can also call setxattr() or removexattr() to overwrite or delete the daemon's user.* attributes. Moreover, on tmpfs mounts such as /run (where unprivileged users normally cannot create files), shmem_xattr_handler_set() uses simple_xattr_set() and charges each attribute against the superblock's sbinfo->free_ispace pool, allowing an unprivileged user to exhaust /run inode space via a 0666 socket and cause -ENOSPC for privileged daemons.

Quoted 1 line

[...]

Yup, that looks good. Thanks!

---

Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/1] xattr: require inode owner or CAP_FOWNER to write user.* xattrs on sockets

      https://git.kernel.org/vfs/vfs/c/f1d026b55bb2