xattr: require inode owner or CAP_FOWNER to write user.* xattrs on sockets
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.
--- fs/xattr.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/xattr.c +5 -5
@@ -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
Quoted 17 lines · Dominik Maier
Commit
dc0876b9846d("xattr: support extended attributes on sockets") enabled user.* extended attributes onS_IFSOCKinodes so services can publish protocol discovery metadata (such as user.varlink=1 or/dev/logstructured logging support) on bound UNIX domain sockets.However, connecting to a path-based
AF_UNIXsocket requiresMAY_WRITEon the socket inode, so public system daemon sockets in /run and /dev are routinely created with mode 0666. Becausexattr_permission()allowsS_IFSOCKwrites without checkinginode_owner_or_capable(), any unprivileged local user who can connect to a 0666 socket can also callsetxattr()orremovexattr()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()usessimple_xattr_set()and charges each attribute against the superblock'ssbinfo->free_ispacepool, allowing an unprivileged user to exhaust /run inode space via a 0666 socket and cause-ENOSPCfor 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