Skip to content

xattr: rework simple xattrs and support user.* xattrs on sockets

Christian Brauner linux-fsdevel linux-mm lkml netdev 1 version In review

Get series with b4
b4 am [email protected] change-id 20260211-work-xattr-socket-c85f4d3b8847

Versions newest first

  1. v1 Latest14 patches 23 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/14xattr: add rcu_head and rhash_head to struct simple_xattrfs/xattr.c include/linux/xattr.h+27 -01 reply
2/14xattr: add rhashtable-based simple_xattr infrastructurefs/xattr.c include/linux/xattr.h mm/shmem.c+357 -1091 reply
3/14shmem: adapt to rhashtable-based simple_xattrs with lazy allocationfs/xattr.c include/linux/shmem_fs.h include/linux/xattr.h +1 more+47 -291 reply
4/14kernfs: adapt to rhashtable-based simple_xattrs with lazy allocationfs/kernfs/dir.c fs/kernfs/inode.c fs/kernfs/kernfs-internal.h+37 -142 replies
5/14pidfs: adapt to rhashtable-based simple_xattrsfs/pidfs.c+41 -243 replies
6/14xattr: remove rbtree-based simple_xattr infrastructurefs/xattr.c include/linux/xattr.h+103 -2961 reply
7/14xattr: add xattr_permission_error()fs/xattr.c+9 -21 reply
8/14xattr: switch xattr_permission() to switch statementfs/xattr.c+13 -51 reply
9/14xattr: move user limits for xattrs to generic infrafs/kernfs/inode.c fs/kernfs/kernfs-internal.h fs/xattr.c +2 more+87 -763 replies
10/14xattr,net: support limited amount of extended attributes on sockfs socketsnet/socket.c+92 -271 reply
11/14xattr: support extended attributes on socketsfs/xattr.c+2 -01 reply
12/14selftests/xattr: path-based AF_UNIX socket xattr teststools/testing/selftests/filesystems/xattr/.gitignore tools/testing/selftests/filesystems/xattr/Makefile tools/testing/selftests/filesystems/xattr/xattr_socket_test.c+477 -01 reply
13/14selftests/xattr: sockfs socket xattr teststools/testing/selftests/filesystems/xattr/.gitignore tools/testing/selftests/filesystems/xattr/Makefile tools/testing/selftests/filesystems/xattr/xattr_sockfs_test.c+365 -11 reply
14/14selftests/xattr: test xattrs on various socket familiestools/testing/selftests/filesystems/xattr/.gitignore tools/testing/selftests/filesystems/xattr/Makefile tools/testing/selftests/filesystems/xattr/xattr_socket_types_test.c+179 -11 reply

Reviews trailers per patch

All 14 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchDarrick J. WongJan KaraJeff Layton
SeriesA-b A-b R-b
1/14R-b
2/14R-b
3/14R-b
4/14R-b
5/14R-b
6/14R-b
7/14R-b
8/14R-b
9/14R-b
10/14R-b
11/14R-b
12/14R-b
13/14R-b
14/14R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v1 thread

Cover letter [PATCH 00/14] xattr: rework simple xattrs and support user.* xattrs on sockets

Hey,

This reworks the simple_xattr infrastructure and adds support for user.* extended attributes on sockets.

The simple_xattr subsystem currently uses an rbtree protected by a reader-writer spinlock. This series replaces the rbtree with an rhashtable giving O(1) average-case lookup with RCU-based lockless reads. This sped up concurrent access patterns on tmpfs quite a bit and it's an overall easy enough conversion to do and gets rid or rwlock_t.

The conversion is done incrementally: a new rhashtable path is added alongside the existing rbtree, consumers are migrated one at a time (shmem, kernfs, pidfs), and then the rbtree code is removed. All three consumers switch from embedded structs to pointer-based lazy allocation so the rhashtable overhead is only paid for inodes that actually use xattrs.

With this infrastructure in place the series adds support for user.* xattrs on sockets. Path-based AF_UNIX sockets inherit xattr support from the underlying filesystem (e.g. tmpfs) but sockets in sockfs - that is everything created via socket() including abstract namespace AF_UNIX sockets - had no xattr support at all.

The xattr_permission() checks are reworked to allow user.* xattrs on S_IFSOCK inodes. Sockfs sockets get per-inode limits of 128 xattrs and 128KB total value size matching the limits already in use for kernfs.

The practical motivation comes from several directions. systemd and GNOME are expanding their use of Varlink as an IPC mechanism. For D-Bus there are tools like dbus-monitor that can observe IPC traffic across the system but this only works because D-Bus has a central broker. For Varlink there is no broker and there is currently no way to identify which sockets speak Varlink. With user.* xattrs on sockets a service can label its socket with the IPC protocol it speaks (e.g., user.varlink=1) and an eBPF program can then selectively capture traffic on those sockets. Enumerating bound sockets via netlink combined with these xattr labels gives a way to discover all Varlink IPC entrypoints for debugging and introspection.

Similarly, systemd-journald wants to use xattrs on the /dev/log socket for protocol negotiation to indicate whether RFC 5424 structured syslog is supported or whether only the legacy RFC 3164 format should be used.

In containers these labels are particularly useful as high-privilege or more complicated solutions for socket identification aren't available.

The series comes with comprehensive selftests covering path-based AF_UNIX sockets, sockfs socket operations, per-inode limit enforcement, and xattr operations across multiple address families (AF_INET, AF_INET6, AF_NETLINK, AF_PACKET).

Christian

---
Christian Brauner (14):
xattr: add rcu_head and rhash_head to struct simple_xattr
xattr: add rhashtable-based simple_xattr infrastructure
shmem: adapt to rhashtable-based simple_xattrs with lazy allocation
kernfs: adapt to rhashtable-based simple_xattrs with lazy allocation
pidfs: adapt to rhashtable-based simple_xattrs
xattr: remove rbtree-based simple_xattr infrastructure
xattr: add xattr_permission_error()
xattr: switch xattr_permission() to switch statement
xattr: move user limits for xattrs to generic infra xattr,net: support limited amount of extended attributes on sockfs sockets
xattr: support extended attributes on sockets selftests/xattr: path-based AF_UNIX socket xattr tests selftests/xattr: sockfs socket xattr tests
selftests/xattr: test xattrs on various socket families

 fs/kernfs/dir.c                                    |  15 +-
 fs/kernfs/inode.c                                  |  99 +----
 fs/kernfs/kernfs-internal.h                        |   5 +-
 fs/pidfs.c                                         |  65 +--
 fs/xattr.c                                         | 423 +++++++++++++------
 include/linux/kernfs.h                             |   2 -
 include/linux/shmem_fs.h                           |   2 +-
 include/linux/xattr.h                              |  47 ++-
 mm/shmem.c                                         |  46 +-
 net/socket.c                                       | 119 ++++--
 .../testing/selftests/filesystems/xattr/.gitignore |   3 +
 tools/testing/selftests/filesystems/xattr/Makefile |   6 +
 .../filesystems/xattr/xattr_socket_test.c          | 470 +++++++++++++++++++++
 .../filesystems/xattr/xattr_socket_types_test.c    | 177 ++++++++
 .../filesystems/xattr/xattr_sockfs_test.c          | 363 ++++++++++++++++
 15 files changed, 1547 insertions(+), 295 deletions(-)

---
base-commit: 72c395024dac5e215136cbff793455f065603b06
change-id: 20260211-work-xattr-socket-c85f4d3b8847