Skip to contentSkip to conversation

UUID and GUID user and group ids (*_r system calls)

RFC PATCH In review Jan Koester 3 participants 15 messages Oct 18 – Oct 19

Subsystems (55)
lore
Share & tools
lore
#2 lore raw

RFC PATCH 2/41 uapi: add <linux/uidgid_r.h> for 128 bit capable user and group ids

In reply to Jan Koester

User and group ids are 32 bit numbers. Identities that come from elsewhere -- UUIDs handed out by a directory service, or the GUIDs of a Windows domain -- have to be squeezed into that range through mapping tables kept in userspace, and the kernel never sees who a process really is.

Add a tagged id for a new family of system calls (named after the classic ones with an _r suffix): a classic 32 bit id, an RFC 9562 version 4 UUID, or a Microsoft GUID in the byte order Windows stores it in. Type 0 is "no id", so a zero-initialized id is never root, and lets the set*id_r() calls express "unchanged" without a magic number.

The struct has no 64 bit members and the same layout on all ABIs, so none of the new calls needs a compat entry point.

Assisted-by Claude:claude-opus-5-5
---
 include/uapi/linux/uidgid_r.h | 45 +++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 include/uapi/linux/uidgid_r.h
include/uapi/linux/uidgid_r.h new file +45 -0
new file mode 100644
index 0000000000..c3b1cb2ae2
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * User and group ids for the *_r system calls: a classic 32 bit id, a
+ * UUID or a Microsoft GUID.
+ *
+ * The classic system calls (getuid(), chown(), ...) keep their 32 bit
+ * ids; for an id that has no 32 bit form they see the overflow id
+ * (/proc/sys/kernel/overflowuid and overflowgid), like the 16 bit system
+ * calls do for ids above 65535.
+ */
+#ifndef _UAPI_LINUX_UIDGID_R_H
+#define _UAPI_LINUX_UIDGID_R_H
+
+#include <linux/types.h>
+
+/*
+ * Kinds of id (__kernel_uid_r_t.type). An all-zero id is UID_R_NONE, so a
+ * zero-initialized id never stands for root.
+ */
+#define UID_R_NONE	0	/* no id: "unchanged" or "not set" */
+#define UID_R_LEGACY	1	/* classic 32 bit id in .legacy */
+#define UID_R_UUID	2	/* RFC 9562 UUID, version 4, in .uuid */
+#define UID_R_GUID	3	/* Microsoft GUID in .guid */
+
+#define UID_R_SIZE	16	/* bytes of .uuid and .guid */
+
+/*
+ * .uuid holds the UUID in network byte order, as RFC 9562 lays it out.
+ * .guid holds the GUID as Windows stores it: Data1, Data2 and Data3 little
+ * endian, Data4 as is.
+ *
+ * Bytes past the member .type selects are reserved and must be zero.
+ */
+typedef struct __kernel_uid_r {
+	__u32 type;
+	union {
+		__u32 legacy;
+		__u8 uuid[UID_R_SIZE];
+		__u8 guid[UID_R_SIZE];
+	};
+} __kernel_uid_r_t;
+
+typedef __kernel_uid_r_t __kernel_gid_r_t;
+
+#endif /* _UAPI_LINUX_UIDGID_R_H */
Signature · 1 line
2.56.0
#3 lore raw

RFC PATCH 3/41 uidgid: add uid_is_legacy() and gid_is_legacy()

In reply to Jan Koester

User and group ids are about to become able to hold a UUID or a GUID besides a classic 32 bit id. Add the predicates code that can only keep a classic id (in 32 bits of a buffer, for instance) tests with, so it can be converted before the types change. For now every id is a classic one.

No functional change.

Assisted-by Claude:claude-opus-5-5
---
 include/linux/uidgid.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
include/linux/uidgid.h +14 -0
index 2dc767e08f..182c682458 100644
@@ -22,6 +22,20 @@ struct uid_gid_map;
 #define KUIDT_INIT(value) (kuid_t){ value }
 #define KGIDT_INIT(value) (kgid_t){ value }
 
+/*
+ * Whether an id is a classic 32 bit id. All of them are for now; code that
+ * needs one (to store it in 32 bits, for example) checks with these.
+ */
+static inline bool uid_is_legacy(kuid_t uid)
+{
+	return true;
+}
+
+static inline bool gid_is_legacy(kgid_t gid)
+{
+	return true;
+}
+
 #ifdef CONFIG_MULTIUSER
 static inline uid_t __kuid_val(kuid_t uid)
 {
Signature · 1 line
2.56.0
#1 lore raw

RFC PATCH 1/41 uuid: move uuid_t and guid_t into <linux/uuid_types.h>

In reply to Jan Koester

<linux/uuid.h> pulls in <linux/string.h> for its helpers, which makes it unusable from headers low in the include chain. The next patches embed UUIDs and GUIDs in kuid_t and kgid_t, whose <linux/uidgid_types.h> is included by <linux/sched.h>.

Move the two types and UUID_SIZE into a header of their own that only needs <linux/types.h>. <linux/uuid.h> includes it, so no user changes.

No functional change.

Assisted-by Claude:claude-opus-5-5
---
 include/linux/uuid.h       | 11 +----------
 include/linux/uuid_types.h | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 10 deletions(-)
 create mode 100644 include/linux/uuid_types.h
include/linux/uuid.h +1 -10
index 43d4a79b27..cbdaf0ca45 100644
@@ -9,16 +9,7 @@
 #define _LINUX_UUID_H_
 
 #include <linux/string.h>
-
-#define UUID_SIZE 16
-
-typedef struct {
-	__u8 b[UUID_SIZE];
-} guid_t;
-
-typedef struct {
-	__u8 b[UUID_SIZE];
-} uuid_t;
+#include <linux/uuid_types.h>
 
 #define GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)			\
 ((guid_t)								\
include/linux/uuid_types.h new file +21 -0
new file mode 100644
index 0000000000..1e45b69571
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * UUID/GUID types, without the helpers of <linux/uuid.h>, for headers
+ * low in the include chain (such as <linux/uidgid_types.h>)
+ */
+#ifndef _LINUX_UUID_TYPES_H_
+#define _LINUX_UUID_TYPES_H_
+
+#include <linux/types.h>
+
+#define UUID_SIZE 16
+
+typedef struct {
+	__u8 b[UUID_SIZE];
+} guid_t;
+
+typedef struct {
+	__u8 b[UUID_SIZE];
+} uuid_t;
+
+#endif /* _LINUX_UUID_TYPES_H_ */
Signature · 1 line
2.56.0
#0 lore raw

cover UUID and GUID user and group ids (*_r system calls)

Hi,

this RFC series lets a user or group id be a UUID (RFC 9562, version 4) or a Microsoft GUID as well as a classic 32-bit number. Processes can run as such a user, files can be owned by one, and credentials, ACLs, keys, System V IPC, sockets, signals, audit and procfs carry the whole id.

Why
---
Directory services name users by 128-bit ids: Active Directory by objectGUID (and SIDs), LDAP directories often by entryUUID. Today every system that serves such users (winbind, sssd, nfsidmap, ksmbd user space) maps them to 32-bit numbers through ranges, hashes or a local database. The numbers differ between machines unless the mapping is configured the same everywhere, mappings can collide, and ownership written to shared storage or a backup depends on the machine that wrote it. With the 128-bit id in the kernel, the id the directory hands out is also the owner on disk and in every credential, and no mapping table is needed.

Design
------
- kuid_t and kgid_t become a tagged union (legacy number, UUID, GUID) instead of a u32. There is no table that maps UUIDs to numbers: the kernel compares, hashes and stores the whole id. uid_eq(), uid_lt() and the other helpers keep their meaning. Patches 1-3 add the UAPI type and helpers. Patches 4-8 fix places that relied on kuid_t being a u32: sk_uid is now read through a seqcount, and af_unix, netlink and Bluetooth keep only classic ids in skb->cb. Patch 9 changes the type.

- UUIDs and GUIDs exist only in the initial user namespace. They are not part of any uid_map or gid_map, show as the overflow id in other namespaces, and no capability in a child namespace gives privilege over them. Idmapped mounts pass them through unchanged.

- The classic system calls keep their 32-bit ids and show a UUID or GUID as the overflow id, as the 16-bit calls do for ids above 65535. A new family, named after the old calls with an _r suffix (getuid_r, setresuid_r, setgroups_r, fchownat_r, ...), takes a 20-byte __kernel_uid_r_t:

	typedef struct __kernel_uid_r {
		__u32 type;	/* UID_R_NONE, _LEGACY, _UUID, _GUID */
		union {
			__u32 legacy;
			__u8 uuid[16];
			__u8 guid[16];
		};
	} __kernel_uid_r_t;

It has the same layout on every ABI, so none of the calls needs a compat entry.

- Existing interfaces get _R variants where an id is in the ABI:
STATX_UID_R/STATX_GID_R, SO_PEERCRED_R, SO_PEERGROUPS_R, SCM_CREDENTIALS_R, si_uid_r in siginfo (offset 96 in every layout), IPC_STAT_R/IPC_SET_R, KEYCTL_CHOWN_R, and version 3 of the POSIX ACL xattr. procfs, audit records, key descriptions and the RPCSEC_GSS upcall use a text form (decimal, UUID, or GUID in braces).

- A filesystem has to declare that it can store such owners (SB_I_UID_R). Everywhere else, chown and creating a file as such a user fail with EOVERFLOW, so a UUID never turns into a wrong number on disk. tmpfs, ramfs and devpts declare it, overlayfs does when its upper layer does, and ext4 does with a new read-only compatible feature, uid_r (patches 31, 32 and 34; 256-byte inodes). NFSv4 and ksmbd carry the ids as text or as SIDs (S-1-22-3/4/5/6-...).

- Things that can't carry a 128-bit id fail closed instead of mapping:
quotas don't account such owners, AUTH_SYS sends the overflow id, unprivileged ublk devices are refused, and gssd versions that don't know uid_r= refuse the upcall.

Documentation/userspace-api/uid_r.rst (patches 35 and 41) describes the whole ABI and its limitations.

Testing
-------
- tools/testing/selftests/uid_r (patch 36): 14/14 pass.
- A boot test suite (nolibc init on QEMU, ext4 images with and without uid_r): 88/88 pass, on a kernel with USER_NS, overlayfs, tmpfs, POSIX ACLs and audit enabled.
- End to end on a full distribution (FenrirOS: patched libc, e2fsprogs, OpenSSH, rsync, libarchive, a ksmbd and NFS server): UUID users log in over ssh, own files on ext4, and reach ksmbd and NFSv4 shares.
- The runtime tests above ran on the same series on top of v7.2.9 and v7.2.11. On v7.3-rc7, the series has so far been built for x86_64 (bzImage and modules, with USER_NS, audit, ecryptfs, fscrypt, quota, ublk, NFS, Bluetooth and the LSMs enabled), not yet booted.
- The syscall tables of the other architectures are wired up (patch 22) but haven't been built.

The e2fsprogs changes (mke2fs/tune2fs -O uid_r, e2fsck, debugfs, ACL conversion in libext2fs) will be sent to linux-ext4 separately.

Open questions
--------------
- Is a tagged union in kuid_t acceptable, or would you rather see the 128-bit id kept beside a u32 kuid_t?
- The new calls copy the classic get/set*id() and chown() families one by one (20 entries). A single setid_r(which, ...) call would need fewer syscall numbers. Which do you prefer?
- Should the series be split per subsystem (core/uidgid, fs and VFS, net, ext4, nfsd/ksmbd) after this RFC?

The series is based on v7.3-rc7. The syscall numbers (473-492 on most architectures) are placeholders and will follow whatever is merged first.

Jan Koester (41):
uuid: move uuid_t and guid_t into <linux/uuid_types.h>
uapi: add <linux/uidgid_r.h> for 128 bit capable user and group ids
uidgid: add uid_is_legacy() and gid_is_legacy()
net: sock: read sk_uid through a seqcount
af_unix: keep sender ids in skb->cb only when they are classic ids
netlink: keep classic sender ids in skb->cb
Bluetooth: keep classic sender ids in skb->cb
smb: client: use __kuid_val() for the unix SIDs of the caller
uidgid: let kuid_t and kgid_t hold a UUID or a GUID
uidgid: convert between kernel ids and the ids of the *_r system calls
fscrypt: show the whole uid in the description of user key claims
keys: name per-user keyrings of UUID and GUID users by the whole uid
ublk: refuse unprivileged devices to UUID and GUID users
nfsd: don't hand out uid 0 for read layouts of UUID-owned files
SUNRPC: name UUID and GUID users to gssd as uid_r=
ecryptfs: hash daemons by kuid_hash()
quota: don't account UUID and GUID owners
fs: keep UUID and GUID owners off filesystems that can't store them
cred: add the *_r variants of the get/set*id() system calls
groups: add getgroups_r() and setgroups_r()
fs: add chown_r(), lchown_r(), fchown_r() and fchownat_r()
arch: wire up the *_r uid and gid system calls
statx: report UUID and GUID owners
shmem, ramfs: allow UUID and GUID owners
uidgid: parse and print ids in their text form
proc: show UUID and GUID ids in status, accept them for loginuid
audit: log UUID and GUID ids in full
net: add SO_PEERCRED_R, SO_PEERGROUPS_R and SCM_CREDENTIALS_R
signal: report the sender's UUID or GUID uid in si_uid_r
ipc: add IPC_STAT_R and IPC_SET_R
ext4: add the uid_r feature for UUID and GUID owners
ext4: let uid_r be turned on while the filesystem is mounted
posix_acl: support UUID and GUID entries
ext4: store ACLs with UUID and GUID entries on uid_r filesystems
Documentation: describe UUID and GUID user and group ids
selftests: add tests for UUID and GUID ids
ovl: allow UUID and GUID owners when the upper layer does
devpts: allow UUID and GUID owners
ksmbd: log in UUID and GUID users and map them to SIDs nfsd, nfs: carry UUID and GUID owners as their text form
Documentation: uid_r: describe SMB and NFSv4

 Documentation/userspace-api/index.rst       |   1 +
 Documentation/userspace-api/uid_r.rst       | 186 +++++++
 arch/alpha/include/uapi/asm/socket.h        |   5 +
 arch/alpha/kernel/syscalls/syscall.tbl      |  20 +
 arch/arm/tools/syscall.tbl                  |  20 +
 arch/arm64/tools/syscall_32.tbl             |  20 +
 arch/m68k/kernel/syscalls/syscall.tbl       |  20 +
 arch/microblaze/kernel/syscalls/syscall.tbl |  20 +
 arch/mips/include/uapi/asm/socket.h         |   5 +
 arch/mips/kernel/syscalls/syscall_n32.tbl   |  20 +
 arch/mips/kernel/syscalls/syscall_n64.tbl   |  20 +
 arch/mips/kernel/syscalls/syscall_o32.tbl   |  20 +
 arch/parisc/include/uapi/asm/socket.h       |   5 +
 arch/parisc/kernel/syscalls/syscall.tbl     |  20 +
 arch/powerpc/kernel/syscalls/syscall.tbl    |  20 +
 arch/s390/kernel/syscalls/syscall.tbl       |  20 +
 arch/sh/kernel/syscalls/syscall.tbl         |  20 +
 arch/sparc/include/uapi/asm/socket.h        |   5 +
 arch/sparc/kernel/syscalls/syscall.tbl      |  20 +
 arch/x86/entry/syscalls/syscall_32.tbl      |  20 +
 arch/x86/entry/syscalls/syscall_64.tbl      |  20 +
 arch/xtensa/kernel/syscalls/syscall.tbl     |  20 +
 drivers/block/ublk_drv.c                    |  17 +-
 drivers/tty/tty_audit.c                     |   7 +-
 fs/attr.c                                   |   7 +
 fs/crypto/keyring.c                         |   7 +-
 fs/devpts/inode.c                           |   2 +
 fs/ecryptfs/messaging.c                     |   2 +-
 fs/ext4/acl.c                               | 109 +++-
 fs/ext4/acl.h                               |  34 +-
 fs/ext4/ext4.h                              |  27 +-
 fs/ext4/inode.c                             | 115 ++++-
 fs/ext4/ioctl.c                             |  30 +-
 fs/ext4/super.c                             |  45 +-
 fs/mnt_idmapping.c                          |  14 +
 fs/nfs/nfs4idmap.c                          |  53 ++
 fs/nfs/super.c                              |   2 +
 fs/nfsd/flexfilelayout.c                    |   6 +-
 fs/nfsd/nfs4idmap.c                         |  68 ++-
 fs/open.c                                   | 144 +++++-
 fs/overlayfs/super.c                        |   3 +
 fs/posix_acl.c                              | 123 ++++-
 fs/proc/array.c                             |  17 +-
 fs/proc/base.c                              |  38 +-
 fs/quota/dquot.c                            |   3 +
 fs/ramfs/inode.c                            |   1 +
 fs/signalfd.c                               |   3 +
 fs/smb/client/cifsacl.c                     |   2 +-
 fs/smb/client/smb2pdu.c                     |   7 +-
 fs/smb/server/ksmbd_netlink.h               |  15 +-
 fs/smb/server/mgmt/user_config.c            |  35 +-
 fs/smb/server/mgmt/user_config.h            |   4 +-
 fs/smb/server/smb2pdu.c                     |  10 +-
 fs/smb/server/smb_common.c                  |  18 +-
 fs/smb/server/smbacl.c                      | 178 +++++--
 fs/smb/server/smbacl.h                      |  19 +-
 fs/smb/server/transport_ipc.c               |   4 +-
 fs/smb/server/vfs_cache.c                   |   9 +-
 fs/smb/server/vfs_cache.h                   |   4 +-
 fs/stat.c                                   |  24 +-
 include/linux/audit.h                       |   8 +-
 include/linux/compat.h                      |   6 +
 include/linux/fs.h                          |  29 +-
 include/linux/fs/super_types.h              |   1 +
 include/linux/mnt_idmapping.h               |  74 ++-
 include/linux/netlink.h                     |   2 +-
 include/linux/posix_acl_xattr.h             |  31 ++
 include/linux/ptrace.h                      |   2 +-
 include/linux/quota.h                       |  18 +
 include/linux/signal.h                      |  22 +
 include/linux/signal_types.h                |   5 +-
 include/linux/socket.h                      |   1 +
 include/linux/syscalls.h                    |  44 ++
 include/linux/uidgid.h                      | 165 +++++-
 include/linux/uidgid_types.h                |  32 +-
 include/linux/uuid.h                        |  11 +-
 include/linux/uuid_types.h                  |  21 +
 include/net/bluetooth/bluetooth.h           |   2 +-
 include/net/scm.h                           |  28 +
 include/net/sock.h                          |  32 +-
 include/uapi/asm-generic/siginfo.h          |  17 +
 include/uapi/asm-generic/socket.h           |   5 +
 include/uapi/asm-generic/unistd.h           |  43 +-
 include/uapi/linux/ipc.h                    |  17 +
 include/uapi/linux/keyctl.h                 |   1 +
 include/uapi/linux/posix_acl_xattr.h        |  19 +
 include/uapi/linux/signalfd.h               |   4 +-
 include/uapi/linux/socket.h                 |   9 +
 include/uapi/linux/stat.h                   |  10 +-
 include/uapi/linux/uidgid_r.h               |  45 ++
 io_uring/waitid.c                           |  32 +-
 io_uring/waitid.h                           |   1 +
 ipc/mqueue.c                                |   4 +-
 ipc/msg.c                                   |  40 +-
 ipc/sem.c                                   |  31 +-
 ipc/shm.c                                   |  32 +-
 ipc/util.c                                  | 112 +++-
 ipc/util.h                                  |  23 +-
 kernel/Makefile                             |   1 +
 kernel/audit.c                              |  50 +-
 kernel/audit.h                              |   4 +-
 kernel/auditsc.c                            |  63 ++-
 kernel/exit.c                               |  18 +-
 kernel/exit.h                               |   3 +
 kernel/groups.c                             |  94 +++-
 kernel/signal.c                             |  48 +-
 kernel/sys.c                                | 472 ++++++++++++-----
 kernel/sys_ni.c                             |  12 +
 kernel/ucount.c                             |   2 +-
 kernel/uidgid_r.c                           | 467 +++++++++++++++++
 kernel/user.c                               |   2 +-
 kernel/user_namespace.c                     |  10 +-
 lib/kobject_uevent.c                        |   8 +-
 mm/oom_kill.c                               |   2 +-
 mm/shmem.c                                  |   2 +
 net/bluetooth/hci_sock.c                    |   8 +-
 net/core/dev.c                              |   8 +-
 net/core/scm.c                              |  94 ++--
 net/core/sock.c                             |  90 +++-
 net/netlabel/netlabel_user.c                |   4 +-
 net/netlink/af_netlink.c                    |   4 +-
 net/socket.c                                |   5 +-
 net/sunrpc/auth_gss/auth_gss.c              |  44 +-
 net/unix/af_unix.c                          |  53 +-
 net/unix/af_unix.h                          |  11 +-
 scripts/syscall.tbl                         |  20 +
 security/apparmor/file.c                    |   8 +-
 security/integrity/ima/ima_policy.c         |   8 +-
 security/integrity/integrity_audit.c        |   6 +-
 security/ipe/audit.c                        |  12 +-
 security/keys/compat.c                      |   3 +
 security/keys/internal.h                    |   3 +
 security/keys/keyctl.c                      |  61 ++-
 security/keys/persistent.c                  |  11 +-
 security/keys/process_keys.c                |  36 +-
 security/keys/request_key.c                 |  12 +-
 security/selinux/selinuxfs.c                |   8 +-
 security/selinux/ss/services.c              |   4 +-
 tools/testing/selftests/Makefile            |   1 +
 tools/testing/selftests/uid_r/.gitignore    |   1 +
 tools/testing/selftests/uid_r/Makefile      |   6 +
 tools/testing/selftests/uid_r/config        |   4 +
 tools/testing/selftests/uid_r/uid_r_test.c  | 535 ++++++++++++++++++++
 143 files changed, 4425 insertions(+), 605 deletions(-)
 create mode 100644 Documentation/userspace-api/uid_r.rst
 create mode 100644 include/linux/uuid_types.h
 create mode 100644 include/uapi/linux/uidgid_r.h
 create mode 100644 kernel/uidgid_r.c
 create mode 100644 tools/testing/selftests/uid_r/.gitignore
 create mode 100644 tools/testing/selftests/uid_r/Makefile
 create mode 100644 tools/testing/selftests/uid_r/config
 create mode 100644 tools/testing/selftests/uid_r/uid_r_test.c

base-commit: 32c52ec87d6245ee2d12ed5dd509e40062939b50

Signature · 1 line
2.56.0
#4 lore raw

RFC PATCH 4/41 net: sock: read sk_uid through a seqcount

sk_uid is read without a lock, with READ_ONCE(), by the routing lookups and the reuseport checks, while sockfs_setattr() may change it. That only works for as long as a kuid_t is a single word, which it won't be once ids can be UUIDs and GUIDs.

Add sk_uid_seq next to it: writers bump it around the store and hold sk_callback_lock (sock_graft(), sockfs_setattr()) or own the socket alone (sock_init_data_uid()); sk_uid() retries until it sees a whole id. sk_clone() reads the parent's id the same way rather than relying on the copy made by sock_copy().

Assisted-by Claude:claude-opus-5-5
---
 include/net/sock.h | 28 +++++++++++++++++++++++++---
 net/core/sock.c    |  6 +++++-
 net/socket.c       |  5 +++--
 3 files changed, 33 insertions(+), 6 deletions(-)
include/net/sock.h +25 -3
index 60ea55dc18..0986d94665 100644
@@ -294,6 +294,8 @@ struct sk_filter;
   *	@sk_ack_backlog: current listen backlog
   *	@sk_max_ack_backlog: listen backlog set in listen()
   *	@sk_uid: user id of owner
+  *	@sk_uid_seq: makes lockless reads of @sk_uid see a whole id; writers
+  *		     hold @sk_callback_lock
   *	@sk_ino: inode number (zero if orphaned)
   *	@sk_prefer_busy_poll: prefer busypolling over softirq processing
   *	@sk_busy_poll_budget: napi processing budget when busypolling
@@ -509,6 +511,7 @@ struct sock {
 	u32			sk_priority;
 	u32			sk_mark;
 	kuid_t			sk_uid;
+	seqcount_t		sk_uid_seq;
 	u16			sk_protocol;
 	u16			sk_type;
 	struct dst_entry __rcu	*sk_dst_cache;
@@ -2109,11 +2112,23 @@ static inline int sk_rx_queue_get(const struct sock *sk)
 	return -1;
 }
 
+/*
+ * sk_uid is too big for WRITE_ONCE(): writers hold sk_callback_lock (or own
+ * the socket alone, before it is published) and bump sk_uid_seq around the
+ * store, so sk_uid() can read it without a lock.
+ */
+static inline void __sk_set_uid(struct sock *sk, kuid_t uid)
+{
+	write_seqcount_begin(&sk->sk_uid_seq);
+	sk->sk_uid = uid;
+	write_seqcount_end(&sk->sk_uid_seq);
+}
+
 static inline void sk_set_socket(struct sock *sk, struct socket *sock)
 {
 	WRITE_ONCE(sk->sk_socket, sock);
 	if (sock) {
-		WRITE_ONCE(sk->sk_uid, SOCK_INODE(sock)->i_uid);
+		__sk_set_uid(sk, SOCK_INODE(sock)->i_uid);
 		WRITE_ONCE(sk->sk_ino, SOCK_INODE(sock)->i_ino);
 	} else {
 		/* Note: sk_uid is unchanged. */
@@ -2161,8 +2176,15 @@ static inline u64 sock_i_ino(const struct sock *sk)
 
 static inline kuid_t sk_uid(const struct sock *sk)
 {
-	/* Paired with WRITE_ONCE() in sockfs_setattr() */
-	return READ_ONCE(sk->sk_uid);
+	unsigned int seq;
+	kuid_t uid;
+
+	/* Paired with __sk_set_uid() */
+	do {
+		seq = read_seqcount_begin(&sk->sk_uid_seq);
+		uid = sk->sk_uid;
+	} while (read_seqcount_retry(&sk->sk_uid_seq, seq));
+	return uid;
 }
 
 static inline kuid_t sock_net_uid(const struct net *net, const struct sock *sk)
net/core/sock.c +5 -1
index e8551df833..300bc75ce1 100644
@@ -2449,6 +2449,7 @@ static void sk_init_common(struct sock *sk)
 	skb_queue_head_init(&sk->sk_error_queue);
 
 	rwlock_init(&sk->sk_callback_lock);
+	seqcount_init(&sk->sk_uid_seq);
 	lockdep_set_class_and_name(&sk->sk_receive_queue.lock,
 			af_rlock_keys + sk->sk_family,
 			af_family_rlock_key_strings[sk->sk_family]);
@@ -2529,6 +2530,8 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority,
 
 	atomic_set(&newsk->sk_omem_alloc, 0);
 	sk_init_common(newsk);
+	/* sock_copy() may have caught a half written sk_uid */
+	newsk->sk_uid = sk_uid(sk);
 
 	newsk->sk_dst_cache	= NULL;
 	newsk->sk_dst_pending_confirm = 0;
@@ -3773,7 +3776,7 @@ void sock_init_data_uid(struct socket *sock, struct sock *sk, kuid_t uid)
 	} else {
 		RCU_INIT_POINTER(sk->sk_wq, NULL);
 	}
-	sk->sk_uid	=	uid;
+	__sk_set_uid(sk, uid);
 
 	sk->sk_state_change	=	sock_def_wakeup;
 	sk->sk_data_ready	=	sock_def_readable;
@@ -4614,6 +4617,7 @@ static int __init sock_struct_check(void)
 	CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_read_tx, sk_priority);
 	CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_read_tx, sk_mark);
 	CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_read_tx, sk_uid);
+	CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_read_tx, sk_uid_seq);
 	CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_read_tx, sk_protocol);
 	CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_read_tx, sk_dst_cache);
 	CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_read_tx, sk_route_caps);
net/socket.c +3 -2
index c05d86e63a..09658f3958 100644
@@ -679,8 +679,9 @@ static int sockfs_setattr(struct mnt_idmap *idmap,
 		struct socket *sock = SOCKET_I(d_inode(dentry));
 
 		if (sock->sk) {
-			/* Paired with READ_ONCE() in sk_uid() */
-			WRITE_ONCE(sock->sk->sk_uid, iattr->ia_uid);
+			write_lock_bh(&sock->sk->sk_callback_lock);
+			__sk_set_uid(sock->sk, iattr->ia_uid);
+			write_unlock_bh(&sock->sk->sk_callback_lock);
 		} else {
 			err = -ENOENT;
 		}
Signature · 1 line
2.56.0
#5 lore raw

RFC PATCH 5/41 af_unix: keep sender ids in skb->cb only when they are classic ids

In reply to Jan Koester

unix_skb_parms has to fit into the 48 bytes of skb->cb. With kuid_t and kgid_t growing to hold UUIDs and GUIDs the two of them alone would take 40 bytes.

Store classic ids as 32 bit values as before, and only for a UUID or GUID allocate a small struct unix_skb_ids for both, freed together with the pid reference in unix_destruct_scm(). AF_UNIX skbs carrying a pid reference are never cloned, so the pointer has a single owner. Senders with classic ids see no change and no allocation.

Assisted-by Claude:claude-opus-5-5
---
 net/unix/af_unix.c | 50 +++++++++++++++++++++++++++++++++++++++-------
 net/unix/af_unix.h | 11 ++++++++--
 2 files changed, 52 insertions(+), 9 deletions(-)
net/unix/af_unix.c +43 -7
index 42cffeafc8..2b17310534 100644
@@ -1969,11 +1969,46 @@ static void unix_peek_fds(struct scm_cookie *scm, struct sk_buff *skb)
 	unix_peek_fpl(scm->fp);
 }
 
+/*
+ * The sender's ids, in the skb itself for legacy ids; UUIDs and GUIDs don't
+ * fit in skb->cb and come from an allocation, freed with the pid reference
+ * in unix_destruct_scm().
+ */
+static int unix_skb_set_ids(struct sk_buff *skb, kuid_t uid, kgid_t gid)
+{
+	struct unix_skb_ids *ids = NULL;
+
+	if (!uid_is_legacy(uid) || !gid_is_legacy(gid)) {
+		ids = kmalloc_obj(*ids, GFP_KERNEL_ACCOUNT);
+		if (!ids)
+			return -ENOMEM;
+		ids->uid = uid;
+		ids->gid = gid;
+	}
+	kfree(UNIXCB(skb).ids);
+	UNIXCB(skb).ids = ids;
+	UNIXCB(skb).uid = __kuid_val(uid);
+	UNIXCB(skb).gid = __kgid_val(gid);
+	return 0;
+}
+
+static kuid_t unix_skb_uid(const struct sk_buff *skb)
+{
+	return UNIXCB(skb).ids ? UNIXCB(skb).ids->uid : KUIDT_INIT(UNIXCB(skb).uid);
+}
+
+static kgid_t unix_skb_gid(const struct sk_buff *skb)
+{
+	return UNIXCB(skb).ids ? UNIXCB(skb).ids->gid : KGIDT_INIT(UNIXCB(skb).gid);
+}
+
 static void unix_destruct_scm(struct sk_buff *skb)
 {
 	struct scm_cookie scm = {};
 
 	swap(scm.pid, UNIXCB(skb).pid);
+	kfree(UNIXCB(skb).ids);
+	UNIXCB(skb).ids = NULL;
 
 	if (UNIXCB(skb).fp)
 		unix_detach_fds(&scm, skb);
@@ -1992,20 +2027,21 @@ static int unix_scm_to_skb(struct scm_cookie *scm, struct sk_buff *skb, bool sen
 	int err = 0;
 
 	UNIXCB(skb).pid = get_pid(scm->pid);
-	UNIXCB(skb).uid = scm->creds.uid;
-	UNIXCB(skb).gid = scm->creds.gid;
 	UNIXCB(skb).fp = NULL;
+	skb->destructor = unix_wfree;
+	err = unix_skb_set_ids(skb, scm->creds.uid, scm->creds.gid);
+	if (err)
+		return err;
 	unix_get_secdata(scm, skb);
 	if (scm->fp && send_fds)
 		err = unix_attach_fds(scm, skb);
 
-	skb->destructor = unix_wfree;
 	return err;
 }
 
 static void unix_skb_to_scm(struct sk_buff *skb, struct scm_cookie *scm)
 {
-	scm_set_cred(scm, UNIXCB(skb).pid, UNIXCB(skb).uid, UNIXCB(skb).gid);
+	scm_set_cred(scm, UNIXCB(skb).pid, unix_skb_uid(skb), unix_skb_gid(skb));
 	unix_set_secdata(scm, skb);
 }
 
@@ -2039,7 +2075,7 @@ static int unix_maybe_add_creds(struct sk_buff *skb, const struct sock *sk,
 			return err;
 
 		UNIXCB(skb).pid = get_pid(pid);
-		current_uid_gid(&UNIXCB(skb).uid, &UNIXCB(skb).gid);
+		return unix_skb_set_ids(skb, current_uid(), current_gid());
 	}
 
 	return 0;
@@ -2049,8 +2085,8 @@ static bool unix_skb_scm_eq(struct sk_buff *skb,
 			    struct scm_cookie *scm)
 {
 	return UNIXCB(skb).pid == scm->pid &&
-	       uid_eq(UNIXCB(skb).uid, scm->creds.uid) &&
-	       gid_eq(UNIXCB(skb).gid, scm->creds.gid) &&
+	       uid_eq(unix_skb_uid(skb), scm->creds.uid) &&
+	       gid_eq(unix_skb_gid(skb), scm->creds.gid) &&
 	       unix_secdata_eq(scm, skb);
 }
 
net/unix/af_unix.h +9 -2
index 8119dbeef3..e861a430cf 100644
@@ -10,10 +10,17 @@
 
 struct sock *unix_peer_get(struct sock *sk);
 
-struct unix_skb_parms {
-	struct pid		*pid;		/* skb credentials	*/
+/* The sender's ids, when either is a UUID or GUID */
+struct unix_skb_ids {
 	kuid_t			uid;
 	kgid_t			gid;
+};
+
+struct unix_skb_parms {
+	struct pid		*pid;		/* skb credentials	*/
+	struct unix_skb_ids	*ids;		/* uid and gid, or NULL	*/
+	uid_t			uid;		/* for ids NULL: legacy	*/
+	gid_t			gid;		/* uid and gid		*/
 	struct scm_fp_list	*fp;		/* Passed files		*/
 #ifdef CONFIG_SECURITY_NETWORK
 	u32			secid;		/* Security ID		*/
Signature · 1 line
2.56.0
#6 lore raw

RFC PATCH 6/41 netlink: keep classic sender ids in skb->cb

In reply to Jan Koester

netlink_skb_parms has to fit into skb->cb, and netlink skbs are cloned together with it for broadcasts, so there is neither room for kuid_t and kgid_t holding UUIDs nor a single owner for an allocation.

Store the sender ids as classic kernel ids: a UUID or GUID becomes -1, which reaches the receiver of SCM_CREDENTIALS as the overflow id. The kernel's own permission checks on netlink messages use the socket's file credentials, not these.

Assisted-by Claude:claude-opus-5-5
---
 include/linux/netlink.h  |  2 +-
 include/net/scm.h        | 28 ++++++++++++++++++++++++++++
 lib/kobject_uevent.c     |  8 ++++----
 net/netlink/af_netlink.c |  4 ++--
 4 files changed, 35 insertions(+), 7 deletions(-)
include/linux/netlink.h +1 -1
index 882e9c1b6c..999c7a352e 100644
@@ -23,7 +23,7 @@ enum netlink_skb_flags {
 };
 
 struct netlink_skb_parms {
-	struct scm_creds	creds;		/* Skb credentials	*/
+	struct scm_creds_classic creds;		/* Skb credentials	*/
 	__u32			portid;
 	__u32			dst_group;
 	__u32			flags;
include/net/scm.h +28 -0
index 86ae6bc109..daa52e3d44 100644
@@ -23,6 +23,34 @@ struct scm_creds {
 	kgid_t	gid;
 };
 
+/*
+ * Sender credentials for skb->cb of skbs that get cloned along with it
+ * (netlink, bluetooth): no room for kuid_t and kgid_t, and no single owner
+ * for an allocation. The ids are classic kernel ids; a UUID or GUID becomes
+ * -1, which the receiver of SCM_CREDENTIALS sees as the overflow id.
+ */
+struct scm_creds_classic {
+	u32	pid;
+	uid_t	uid;
+	gid_t	gid;
+};
+
+static inline void scm_creds_to_classic(struct scm_creds_classic *classic,
+					const struct scm_creds *creds)
+{
+	classic->pid = creds->pid;
+	classic->uid = __kuid_val(creds->uid);
+	classic->gid = __kgid_val(creds->gid);
+}
+
+static inline void scm_creds_from_classic(struct scm_creds *creds,
+					  const struct scm_creds_classic *classic)
+{
+	creds->pid = classic->pid;
+	creds->uid = KUIDT_INIT(classic->uid);
+	creds->gid = KGIDT_INIT(classic->gid);
+}
+
 #ifdef CONFIG_UNIX
 struct unix_edge;
 #endif
lib/kobject_uevent.c +4 -4
index ddbc4d7482..8b63044881 100644
@@ -297,8 +297,8 @@ static struct sk_buff *alloc_uevent_skb(struct kobj_uevent_env *env,
 	skb_put_data(skb, env->buf, env->buflen);
 
 	parms = &NETLINK_CB(skb);
-	parms->creds.uid = GLOBAL_ROOT_UID;
-	parms->creds.gid = GLOBAL_ROOT_GID;
+	parms->creds.uid = __kuid_val(GLOBAL_ROOT_UID);
+	parms->creds.gid = __kgid_val(GLOBAL_ROOT_GID);
 	parms->dst_group = 1;
 	parms->portid = 0;
 
@@ -362,12 +362,12 @@ static int uevent_net_broadcast_tagged(struct sock *usk,
 		/* fix uid */
 		root_uid = make_kuid(owning_user_ns, 0);
 		if (uid_valid(root_uid))
-			parms->creds.uid = root_uid;
+			parms->creds.uid = __kuid_val(root_uid);
 
 		/* fix gid */
 		root_gid = make_kgid(owning_user_ns, 0);
 		if (gid_valid(root_gid))
-			parms->creds.gid = root_gid;
+			parms->creds.gid = __kgid_val(root_gid);
 	}
 
 	ret = netlink_broadcast(usk, skb, 0, 1, GFP_KERNEL);
net/netlink/af_netlink.c +2 -2
index 3029894eda..282a5d0da4 100644
@@ -1901,7 +1901,7 @@ static int netlink_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
 
 	NETLINK_CB(skb).portid	= nlk->portid;
 	NETLINK_CB(skb).dst_group = dst_group;
-	NETLINK_CB(skb).creds	= scm.creds;
+	scm_creds_to_classic(&NETLINK_CB(skb).creds, &scm.creds);
 	NETLINK_CB(skb).flags	= netlink_skb_flags;
 
 	err = -EFAULT;
@@ -1994,7 +1994,7 @@ static int netlink_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
 		netlink_cmsg_listen_all_nsid(sk, msg, skb);
 
 	memset(&scm, 0, sizeof(scm));
-	scm.creds = *NETLINK_CREDS(skb);
+	scm_creds_from_classic(&scm.creds, NETLINK_CREDS(skb));
 	if (flags & MSG_TRUNC)
 		copied = data_skb->len;
 
Signature · 1 line
2.56.0
#7 lore raw

RFC PATCH 7/41 Bluetooth: keep classic sender ids in skb->cb

In reply to Jan Koester

struct bt_skb_cb holds the sender's struct scm_creds for HCI sockets, which no longer fits into skb->cb now that kuid_t and kgid_t can hold UUIDs and GUIDs. Like netlink, keep them as struct scm_creds_classic:
classic ids as before, the overflow id for UUID and GUID senders.

Assisted-by Claude:claude-opus-5-5
---
 include/net/bluetooth/bluetooth.h | 2 +-
 net/bluetooth/hci_sock.c          | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
include/net/bluetooth/bluetooth.h +1 -1
index b624da5026..2c8fe50f4d 100644
@@ -497,7 +497,7 @@ struct bt_skb_cb {
 		struct l2cap_ctrl l2cap;
 		struct hci_ctrl hci;
 		struct mgmt_ctrl mgmt;
-		struct scm_creds creds;
+		struct scm_creds_classic creds;
 	};
 };
 #define bt_cb(skb) ((struct bt_skb_cb *)((skb)->cb))
net/bluetooth/hci_sock.c +4 -4
index 81068b5857..9f422ae5fd 100644
@@ -276,7 +276,7 @@ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb)
 
 static void hci_sock_copy_creds(struct sock *sk, struct sk_buff *skb)
 {
-	struct scm_creds *creds;
+	struct scm_creds_classic *creds;
 
 	if (!sk || WARN_ON(!skb))
 		return;
@@ -300,8 +300,8 @@ static void hci_sock_copy_creds(struct sock *sk, struct sk_buff *skb)
 
 	creds->pid = pid_vnr(sk->sk_peer_pid);
 	if (sk->sk_peer_cred) {
-		creds->uid = sk->sk_peer_cred->uid;
-		creds->gid = sk->sk_peer_cred->gid;
+		creds->uid = __kuid_val(sk->sk_peer_cred->uid);
+		creds->gid = __kgid_val(sk->sk_peer_cred->gid);
 	}
 }
 
@@ -1615,7 +1615,7 @@ static int hci_sock_recvmsg(struct socket *sock, struct msghdr *msg,
 	}
 
 	memset(&scm, 0, sizeof(scm));
-	scm.creds = bt_cb(skb)->creds;
+	scm_creds_from_classic(&scm.creds, &bt_cb(skb)->creds);
 
 	skb_free_datagram(sk, skb);
 
Signature · 1 line
2.56.0
#8 lore raw

RFC PATCH 8/41 smb: client: use __kuid_val() for the unix SIDs of the caller

In reply to Jan Koester

The S-1-5-88-1-<uid> and S-1-5-88-2-<gid> SIDs sent with a create request take the raw kernel ids from kuid_t.val, which is gone now that the ids can be UUIDs and GUIDs. Use __kuid_val()/__kgid_val(), the same value for classic ids and -1 for the others, which have no unix SID.

Assisted-by Claude:claude-opus-5-5
---
 fs/smb/client/cifsacl.c | 2 +-
 fs/smb/client/smb2pdu.c | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)
fs/smb/client/cifsacl.c +1 -1
index c5e47a835f..78ed25b1f7 100644
@@ -1086,7 +1086,7 @@ unsigned int setup_special_user_owner_ACE(struct smb_ace *pntace)
 
 	pntace->sid.sub_auth[0] = sid_unix_NFS_users.sub_auth[0];
 	pntace->sid.sub_auth[1] = sid_unix_NFS_users.sub_auth[1];
-	pntace->sid.sub_auth[2] = cpu_to_le32(current_fsgid().val);
+	pntace->sid.sub_auth[2] = cpu_to_le32(__kgid_val(current_fsgid()));
 
 	/* size = 1 + 1 + 2 + 4 + 1 + 1 + 6 + (psid->num_subauth*4) */
 	pntace->size = cpu_to_le16(ace_size);
fs/smb/client/smb2pdu.c +4 -3
index cfe3c4b4ab..941ca8a3d6 100644
@@ -2731,7 +2731,7 @@ static void setup_owner_group_sids(char *buf)
 	sids->owner.Authority[5] = 5;
 	sids->owner.SubAuthorities[0] = cpu_to_le32(88);
 	sids->owner.SubAuthorities[1] = cpu_to_le32(1);
-	sids->owner.SubAuthorities[2] = cpu_to_le32(current_fsuid().val);
+	sids->owner.SubAuthorities[2] = cpu_to_le32(__kuid_val(current_fsuid()));
 
 	/* Populate the group ownership fields S-1-5-88-2 */
 	sids->group.Revision = 1;
@@ -2739,9 +2739,10 @@ static void setup_owner_group_sids(char *buf)
 	sids->group.Authority[5] = 5;
 	sids->group.SubAuthorities[0] = cpu_to_le32(88);
 	sids->group.SubAuthorities[1] = cpu_to_le32(2);
-	sids->group.SubAuthorities[2] = cpu_to_le32(current_fsgid().val);
+	sids->group.SubAuthorities[2] = cpu_to_le32(__kgid_val(current_fsgid()));
 
-	cifs_dbg(FYI, "owner S-1-5-88-1-%d, group S-1-5-88-2-%d\n", current_fsuid().val, current_fsgid().val);
+	cifs_dbg(FYI, "owner S-1-5-88-1-%d, group S-1-5-88-2-%d\n",
+		 __kuid_val(current_fsuid()), __kgid_val(current_fsgid()));
 }
 
 /* See MS-SMB2 2.2.13.2.2 and MS-DTYP 2.4.6 */
Signature · 1 line
2.56.0
#13 lore raw

RFC PATCH 10/41 uidgid: convert between kernel ids and the ids of the *_r system calls

In reply to Jan Koester

Add the conversions between kuid_t/kgid_t and __kernel_uid_r_t the new system calls need: make_kuid_r(), from_kuid_r() and the never failing from_kuid_r_munged() (and the gid variants), and get_kuid_r() and put_kuid_r() to copy them from and to userspace.

get_kuid_r() returns INVALID_UID for "no id" -- a NULL pointer, UID_R_NONE, or a classic -1 -- which the set*id_r() and chown_r() calls take as "unchanged", like the classic calls take -1. It rejects malformed ids: unknown types, nonzero reserved bytes, UUIDs other than RFC 9562 version 4, the nil GUID, and UUIDs or GUIDs given from outside the initial user namespace.

Also add kuid_str() and kgid_str(), the text form of an id for logs and
procfs: a classic id in decimal, a UUID as usual, a GUID in braces.

Assisted-by Claude:claude-opus-5-5
---
 include/linux/uidgid.h |  35 +++++
 kernel/Makefile        |   1 +
 kernel/uidgid_r.c      | 323 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 359 insertions(+)
 create mode 100644 kernel/uidgid_r.c
include/linux/uidgid.h +35 -0
index e1adb50d5d..ac7786f760 100644
@@ -180,6 +180,17 @@ static inline u32 kgid_hash(kgid_t gid)
 	return __kid_hash(gid.type, __kgid_val(gid), gid.uuid.b);
 }
 
+/*
+ * The text form of an id, for logs and procfs: a legacy id as a decimal
+ * number, a UUID as "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" and a GUID in
+ * braces, "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}". KID_STR_LEN includes
+ * the terminating NUL.
+ */
+#define KID_STR_LEN 39
+
+char *kuid_str(kuid_t uid, char buf[KID_STR_LEN]);
+char *kgid_str(kgid_t gid, char buf[KID_STR_LEN]);
+
 #ifdef CONFIG_USER_NS
 
 extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
@@ -277,4 +288,28 @@ static inline u32 map_id_up(struct uid_gid_map *map, u32 id)
 }
 #endif /* CONFIG_USER_NS */
 
+/*
+ * Conversion between kuid_t/kgid_t and the ids of the *_r system calls
+ * (<uapi/linux/uidgid_r.h>), in kernel/uidgid_r.c.
+ */
+struct __kernel_uid_r;
+
+kuid_t make_kuid_r(struct user_namespace *from, const struct __kernel_uid_r *id);
+kgid_t make_kgid_r(struct user_namespace *from, const struct __kernel_uid_r *id);
+bool from_kuid_r(struct user_namespace *to, kuid_t uid, struct __kernel_uid_r *id);
+bool from_kgid_r(struct user_namespace *to, kgid_t gid, struct __kernel_uid_r *id);
+void from_kuid_r_munged(struct user_namespace *to, kuid_t uid,
+			struct __kernel_uid_r *id);
+void from_kgid_r_munged(struct user_namespace *to, kgid_t gid,
+			struct __kernel_uid_r *id);
+
+int get_kuid_r(struct user_namespace *from,
+	       const struct __kernel_uid_r __user *uid, kuid_t *kuid);
+int get_kgid_r(struct user_namespace *from,
+	       const struct __kernel_uid_r __user *gid, kgid_t *kgid);
+int put_kuid_r(struct user_namespace *to, kuid_t kuid,
+	       struct __kernel_uid_r __user *uid);
+int put_kgid_r(struct user_namespace *to, kgid_t kgid,
+	       struct __kernel_uid_r __user *gid);
+
 #endif /* _LINUX_UIDGID_H */
kernel/Makefile +1 -0
index 1e1a316735..813ddbf115 100644
@@ -89,6 +89,7 @@ obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o
 obj-$(CONFIG_COMPAT) += compat.o
 obj-$(CONFIG_CGROUPS) += cgroup/
 obj-$(CONFIG_UTS_NS) += utsname.o
+obj-y += uidgid_r.o
 obj-$(CONFIG_USER_NS) += user_namespace.o
 obj-$(CONFIG_PID_NS) += pid_namespace.o
 obj-$(CONFIG_IKCONFIG) += configs.o
kernel/uidgid_r.c new file +323 -0

323 lines not on this page · raw message

Signature · 1 line
2.56.0
#9 lore raw

RFC PATCH 9/41 uidgid: let kuid_t and kgid_t hold a UUID or a GUID

In reply to Jan Koester

Make kuid_t and kgid_t (and vfsuid_t and vfsgid_t, which share their layout) tagged unions: a classic 32 bit id, an RFC 9562 UUID, or a Microsoft GUID. KID_LEGACY is 0, so zeroed memory still holds the root ids, and KUIDT_INIT()/KGIDT_INIT() keep building classic ids, so the bulk of the kernel needs no change. The member is renamed from val to legacy so the compiler finds code that peeks at it directly.

Semantics of the new ids:

- They are not in any uid_map or gid_map: they exist in the initial user namespace only. kuid_has_mapping() is false for them in every other namespace, so no capability in a child namespace gives privilege over them, and from_kuid() and friends give -1 (the overflow id when munged), exactly as for any other id without a mapping. Anything that can only store or report a 32 bit id thereby already treats them safely.

- Idmapped mounts map classic ids; UUIDs and GUIDs pass through them unchanged, as long as the filesystem itself is in the initial user namespace.

- Ids are ordered by kind first and value second, so sorted group lists, bsearch() and range checks between classic ids keep working:
a UUID never falls into a range of classic ids.

- __kuid_val() and __kgid_val() stay the classic value of a classic id and are -1 for the others; hash tables keyed by ids (user_struct, ucounts) use the new kuid_hash() instead, and the IMA policy comparators the new ordering.

The structs grow from 4 to 20 bytes: struct cred by 128 bytes, struct inode by 32 bytes.

Assisted-by Claude:claude-opus-5-5
---
 fs/mnt_idmapping.c                  |  14 ++++
 include/linux/mnt_idmapping.h       |  74 ++++++++++++++-----
 include/linux/uidgid.h              | 109 ++++++++++++++++++++++------
 include/linux/uidgid_types.h        |  32 +++++++-
 kernel/groups.c                     |  15 ++--
 kernel/ucount.c                     |   2 +-
 kernel/user.c                       |   2 +-
 kernel/user_namespace.c             |  10 ++-
 mm/oom_kill.c                       |   2 +-
 security/integrity/ima/ima_policy.c |   8 +-
 10 files changed, 209 insertions(+), 59 deletions(-)
fs/mnt_idmapping.c +14 -0
index cb61fbdb52..c36e74a371 100644
@@ -87,6 +87,10 @@ vfsuid_t make_vfsuid(struct mnt_idmap *idmap,
 		return VFSUIDT_INIT(kuid);
 	if (idmap == &invalid_mnt_idmap)
 		return INVALID_VFSUID;
+	/* idmappings map classic ids only; UUIDs and GUIDs pass unchanged */
+	if (!uid_is_legacy(kuid))
+		return kuid_has_mapping(fs_userns, kuid) ?
+		       VFSUIDT_INIT(kuid) : INVALID_VFSUID;
 	if (initial_idmapping(fs_userns))
 		uid = __kuid_val(kuid);
 	else
@@ -126,6 +130,10 @@ vfsgid_t make_vfsgid(struct mnt_idmap *idmap,
 		return VFSGIDT_INIT(kgid);
 	if (idmap == &invalid_mnt_idmap)
 		return INVALID_VFSGID;
+	/* idmappings map classic ids only; UUIDs and GUIDs pass unchanged */
+	if (!gid_is_legacy(kgid))
+		return kgid_has_mapping(fs_userns, kgid) ?
+		       VFSGIDT_INIT(kgid) : INVALID_VFSGID;
 	if (initial_idmapping(fs_userns))
 		gid = __kgid_val(kgid);
 	else
@@ -156,6 +164,9 @@ kuid_t from_vfsuid(struct mnt_idmap *idmap,
 		return AS_KUIDT(vfsuid);
 	if (idmap == &invalid_mnt_idmap)
 		return INVALID_UID;
+	if (!vfsuid_is_legacy(vfsuid))
+		return kuid_has_mapping(fs_userns, AS_KUIDT(vfsuid)) ?
+		       AS_KUIDT(vfsuid) : INVALID_UID;
 	uid = map_id_up(&idmap->uid_map, __vfsuid_val(vfsuid));
 	if (uid == (uid_t)-1)
 		return INVALID_UID;
@@ -185,6 +196,9 @@ kgid_t from_vfsgid(struct mnt_idmap *idmap,
 		return AS_KGIDT(vfsgid);
 	if (idmap == &invalid_mnt_idmap)
 		return INVALID_GID;
+	if (!vfsgid_is_legacy(vfsgid))
+		return kgid_has_mapping(fs_userns, AS_KGIDT(vfsgid)) ?
+		       AS_KGIDT(vfsgid) : INVALID_GID;
 	gid = map_id_up(&idmap->gid_map, __vfsgid_val(vfsgid));
 	if (gid == (gid_t)-1)
 		return INVALID_GID;
include/linux/mnt_idmapping.h +56 -18

155 lines not on this page · raw message

include/linux/uidgid.h +87 -22

196 lines not on this page · raw message

include/linux/uidgid_types.h +30 -2
index b35ac4955a..0f595d075b 100644
@@ -3,13 +3,41 @@
 #define _LINUX_UIDGID_TYPES_H
 
 #include <linux/types.h>
+#include <linux/uuid_types.h>
 
+/*
+ * Kinds of kuid_t and kgid_t. KID_LEGACY is 0, so zeroed memory still
+ * holds GLOBAL_ROOT_UID and GLOBAL_ROOT_GID as it did when the ids were
+ * plain numbers. Userspace has its own numbering (UID_R_* in
+ * <uapi/linux/uidgid_r.h>), in which zero is "no id".
+ */
+enum kid_type {
+	KID_LEGACY = 0,		/* classic 32 bit id in .legacy */
+	KID_UUID,		/* RFC 9562 UUID in .uuid */
+	KID_GUID,		/* Microsoft GUID in .guid */
+};
+
+/*
+ * Only the member .type selects is meaningful; the bytes of .uuid past
+ * .legacy are undefined for a KID_LEGACY id. Copy the whole struct and
+ * use the helpers of <linux/uidgid.h> to look at it.
+ */
 typedef struct {
-	uid_t val;
+	u32 type;
+	union {
+		uid_t legacy;
+		uuid_t uuid;
+		guid_t guid;
+	};
 } kuid_t;
 
 typedef struct {
-	gid_t val;
+	u32 type;
+	union {
+		gid_t legacy;
+		uuid_t uuid;
+		guid_t guid;
+	};
 } kgid_t;
 
 #endif /* _LINUX_UIDGID_TYPES_H */
kernel/groups.c +7 -8
index b5e3be6a6b..3aa0651d7a 100644
@@ -73,18 +73,15 @@ static int groups_from_user(struct group_info *group_info,
 	return 0;
 }
 
-static int gid_cmp(const void *_a, const void *_b)
+static int groups_cmp(const void *_a, const void *_b)
 {
-	kgid_t a = *(kgid_t *)_a;
-	kgid_t b = *(kgid_t *)_b;
-
-	return gid_gt(a, b) - gid_lt(a, b);
+	return gid_cmp(*(kgid_t *)_a, *(kgid_t *)_b);
 }
 
 void groups_sort(struct group_info *group_info)
 {
 	sort(group_info->gid, group_info->ngroups, sizeof(*group_info->gid),
-	     gid_cmp, NULL);
+	     groups_cmp, NULL);
 }
 EXPORT_SYMBOL(groups_sort);
 
@@ -100,9 +97,11 @@ int groups_search(const struct group_info *group_info, kgid_t grp)
 	right = group_info->ngroups;
 	while (left < right) {
 		unsigned int mid = (left+right)/2;
-		if (gid_gt(grp, group_info->gid[mid]))
+		int cmp = gid_cmp(grp, group_info->gid[mid]);
+
+		if (cmp > 0)
 			left = mid + 1;
-		else if (gid_lt(grp, group_info->gid[mid]))
+		else if (cmp < 0)
 			right = mid;
 		else
 			return 1;
kernel/ucount.c +1 -1
index ec8b1445e2..d34bc9ea9d 100644
@@ -23,7 +23,7 @@ static struct hlist_nulls_head ucounts_hashtable[UCOUNTS_HASHTABLE_ENTRIES] = {
 static DEFINE_SPINLOCK(ucounts_lock);
 
 #define ucounts_hashfn(ns, uid)						\
-	hash_long((unsigned long)__kuid_val(uid) + (unsigned long)(ns), \
+	hash_long((unsigned long)kuid_hash(uid) + (unsigned long)(ns), \
 		  UCOUNTS_HASHTABLE_BITS)
 #define ucounts_hashentry(ns, uid)	\
 	(ucounts_hashtable + ucounts_hashfn(ns, uid))
kernel/user.c +1 -1
index 21bafdc113..e41806bb70 100644
@@ -88,7 +88,7 @@ EXPORT_SYMBOL_GPL(init_user_ns);
 #define UIDHASH_SZ	(1 << UIDHASH_BITS)
 #define UIDHASH_MASK		(UIDHASH_SZ - 1)
 #define __uidhashfn(uid)	(((uid >> UIDHASH_BITS) + uid) & UIDHASH_MASK)
-#define uidhashentry(uid)	(uidhash_table + __uidhashfn((__kuid_val(uid))))
+#define uidhashentry(uid)	(uidhash_table + __uidhashfn(kuid_hash(uid)))
 
 static struct kmem_cache *uid_cachep;
 static struct hlist_head uidhash_table[UIDHASH_SZ];
kernel/user_namespace.c +8 -2
index 0bed462e9b..88fc8ba586 100644
@@ -436,10 +436,13 @@ EXPORT_SYMBOL(make_kuid);
  *
  *	There is always a mapping into the initial user_namespace.
  *
- *	If @kuid has no mapping in @targ (uid_t)-1 is returned.
+ *	If @kuid has no mapping in @targ (uid_t)-1 is returned. A UUID or
+ *	GUID has no classic uid in any user namespace.
  */
 uid_t from_kuid(struct user_namespace *targ, kuid_t kuid)
 {
+	if (!uid_is_legacy(kuid))
+		return (uid_t) -1;
 	/* Map the uid from a global kernel uid */
 	return map_id_up(&targ->uid_map, __kuid_val(kuid));
 }
@@ -504,10 +507,13 @@ EXPORT_SYMBOL(make_kgid);
  *
  *	There is always a mapping into the initial user_namespace.
  *
- *	If @kgid has no mapping in @targ (gid_t)-1 is returned.
+ *	If @kgid has no mapping in @targ (gid_t)-1 is returned. A UUID or
+ *	GUID has no classic gid in any user namespace.
  */
 gid_t from_kgid(struct user_namespace *targ, kgid_t kgid)
 {
+	if (!gid_is_legacy(kgid))
+		return (gid_t) -1;
 	/* Map the gid from a global kernel gid */
 	return map_id_up(&targ->gid_map, __kgid_val(kgid));
 }
mm/oom_kill.c +1 -1
index 5f372f6e26..2ce3072931 100644
@@ -771,7 +771,7 @@ static void mark_oom_victim(struct task_struct *tsk)
 	thaw_process(tsk);
 	atomic_inc(&oom_victims);
 	cred = get_task_cred(tsk);
-	trace_mark_victim(tsk, cred->uid.val);
+	trace_mark_victim(tsk, __kuid_val(cred->uid));
 	put_cred(cred);
 }
 
security/integrity/ima/ima_policy.c +4 -4
index 68d9a5e6c2..839b88ea20 100644
@@ -81,22 +81,22 @@ struct ima_rule_opt_list {
  */
 static inline bool vfsuid_gt_kuid(vfsuid_t vfsuid, kuid_t kuid)
 {
-	return __vfsuid_val(vfsuid) > __kuid_val(kuid);
+	return vfsuid_cmp(vfsuid, VFSUIDT_INIT(kuid)) > 0;
 }
 
 static inline bool vfsgid_gt_kgid(vfsgid_t vfsgid, kgid_t kgid)
 {
-	return __vfsgid_val(vfsgid) > __kgid_val(kgid);
+	return vfsgid_cmp(vfsgid, VFSGIDT_INIT(kgid)) > 0;
 }
 
 static inline bool vfsuid_lt_kuid(vfsuid_t vfsuid, kuid_t kuid)
 {
-	return __vfsuid_val(vfsuid) < __kuid_val(kuid);
+	return vfsuid_cmp(vfsuid, VFSUIDT_INIT(kuid)) < 0;
 }
 
 static inline bool vfsgid_lt_kgid(vfsgid_t vfsgid, kgid_t kgid)
 {
-	return __vfsgid_val(vfsgid) < __kgid_val(kgid);
+	return vfsgid_cmp(vfsgid, VFSGIDT_INIT(kgid)) < 0;
 }
 
 struct ima_rule_entry {
Signature · 1 line
2.56.0
#14 lore raw

RFC PATCH 11/41 fscrypt: show the whole uid in the description of user key claims

In reply to Jan Koester

The ".fscrypt" keys that account a master key to a user are described as "<identifier>.uid.<uid>". For a UUID or GUID uid that printed -1; use kuid_str() so /proc/keys shows who the claim belongs to. Lookups compare the kuid itself and are not affected.

Assisted-by Claude:claude-opus-5-5
---
 fs/crypto/keyring.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/crypto/keyring.c +4 -3
index 76e28d1e00..080166267f 100644
@@ -178,7 +178,7 @@ static struct key_type key_type_fscrypt_user = {
 };
 
 #define FSCRYPT_MK_USER_DESCRIPTION_SIZE	\
-	(2 * FSCRYPT_KEY_IDENTIFIER_SIZE + CONST_STRLEN(".uid.") + 10 + 1)
+	(2 * FSCRYPT_KEY_IDENTIFIER_SIZE + CONST_STRLEN(".uid.") + KID_STR_LEN)
 
 /* Create ->s_master_keys if needed.  Synchronized by fscrypt_add_key_mutex. */
 static int allocate_filesystem_keyring(struct super_block *sb)
@@ -338,13 +338,14 @@ static int add_master_key_user(struct fscrypt_master_key *mk)
 {
 	kuid_t uid = current_fsuid();
 	char description[FSCRYPT_MK_USER_DESCRIPTION_SIZE];
+	char uidbuf[KID_STR_LEN];
 	struct key *quota_key;
 	struct fscrypt_master_key_user *mk_user;
 	int err;
 
-	snprintf(description, sizeof(description), "%*phN.uid.%u",
+	snprintf(description, sizeof(description), "%*phN.uid.%s",
 		 FSCRYPT_KEY_IDENTIFIER_SIZE, mk->mk_spec.u.identifier,
-		 __kuid_val(uid));
+		 kuid_str(uid, uidbuf));
 	quota_key = key_alloc(&key_type_fscrypt_user, description, uid,
 			      current_gid(), current_cred(),
 			      KEY_POS_SEARCH | KEY_USR_VIEW, 0, NULL);
Signature · 1 line
2.56.0
#10 lore raw

Re: [RFC PATCH 09/41] uidgid: let kuid_t and kgid_t hold a UUID or a GUID

In reply to Jan Koester
Quoted 10 lines · Jan Koester

Make kuid_t and kgid_t (and vfsuid_t and vfsgid_t, which share their layout) tagged unions: a classic 32 bit id, an RFC 9562 UUID, or a Microsoft GUID. KID_LEGACY is 0, so zeroed memory still holds the root ids, and KUIDT_INIT()/KGIDT_INIT() keep building classic ids, so the bulk of the kernel needs no change. The member is renamed from val to legacy so the compiler finds code that peeks at it directly.

Semantics of the new ids:

Quoted 7 lines

- They are not in any uid_map or gid_map: they exist in the initial user namespace only. kuid_has_mapping() is false for them in every other namespace, so no capability in a child namespace gives privilege over them, and from_kuid() and friends give -1 (the overflow id when munged), exactly as for any other id without a mapping. Anything that can only store or report a 32 bit id thereby already treats them safely.

Why?

Quoted 4 lines

- Idmapped mounts map classic ids; UUIDs and GUIDs pass through them unchanged, as long as the filesystem itself is in the initial user namespace.

Okay, so they pass through but don't work. Sounds unfortunate.

include/linux/mnt_idmapping.h extern struct mnt_idmap nop_mnt_idmap; · line 19

Quoted 6 lines
include/linux/mnt_idmapping.h +4 -1
+/* Like kuid_t and kgid_t: a classic id, a UUID or a GUID */
 typedef struct {
-       uid_t val;
+       u32 type;
+       union {
+               uid_t legacy;

Linux is Linux. small numerical uids are not "legacy".

Review

Quoted 2 lines
(quoted diff) +2 -0
+               uuid_t uuid;
+               guid_t guid;

I'm at a complete loss. Is guid is only unique on Earth but uuid unique in the entire universe? Even Microsoft admits that GUID and UUID are two names for the same thing.

I realize that Microsoft colossally screwed up years ago with their little endian uuid idea, and I sincerely hope that this is not some endian thing.

maintainer
#11 lore raw

Re: [RFC PATCH 09/41] uidgid: let kuid_t and kgid_t hold a UUID or a GUID

In reply to Jan Koester
Quoted 6 lines · Jan Koester

Make kuid_t and kgid_t (and vfsuid_t and vfsgid_t, which share their layout) tagged unions: a classic 32 bit id, an RFC 9562 UUID, or a Microsoft GUID. KID_LEGACY is 0, so zeroed memory still holds the root ids, and KUIDT_INIT()/KGIDT_INIT() keep building classic ids, so the bulk of the kernel needs no change. The member is renamed from val to legacy so the compiler finds code that peeks at it directly.

Most Linux systems aren't going to want this bloat to the core uid and gid types. So if this is supported at all (unclear it's worth it...), it will need to be controlled by a default-off kconfig option.

Side note: the subject line says the series contains 41 patches, but it seems only 11 were actually sent.

- Eric

#12 lore raw

Re: [RFC PATCH 09/41] uidgid: let kuid_t and kgid_t hold a UUID or a GUID

Hi,

here are all patches. I have problems to 42 mails with my provder sryy for that.

Am 18.10.26 um 23:02 schrieb Eric Biggers:

Quoted 8 lines · Jan Koester
Quoted 6 lines

Make kuid_t and kgid_t (and vfsuid_t and vfsgid_t, which share their layout) tagged unions: a classic 32 bit id, an RFC 9562 UUID, or a Microsoft GUID. KID_LEGACY is 0, so zeroed memory still holds the root ids, and KUIDT_INIT()/KGIDT_INIT() keep building classic ids, so the bulk of the kernel needs no change. The member is renamed from val to legacy so the compiler finds code that peeks at it directly.

Quoted 8 lines

Most Linux systems aren't going to want this bloat to the core uid and gid types. So if this is supported at all (unclear it's worth it...), it will need to be controlled by a default-off kconfig option.

Side note: the subject line says the series contains 41 patches, but it seems only 11 were actually sent.

- Eric

From 2c211c3fa29b75f9a75915a291c2eb4aef0977ed Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 04:46:02 +0200
Subject: [PATCH 01/43] uuid: move uuid_t and guid_t into <linux/uuid_types.h>

<linux/uuid.h> pulls in <linux/string.h> for its helpers, which makes it unusable from headers low in the include chain. The next patches embed UUIDs and GUIDs in kuid_t and kgid_t, whose <linux/uidgid_types.h> is included by <linux/sched.h>.

Move the two types and UUID_SIZE into a header of their own that only needs <linux/types.h>. <linux/uuid.h> includes it, so no user changes.

No functional change.

Assisted-by Claude:claude-opus-5-5
---
 include/linux/uuid.h       | 11 +----------
 include/linux/uuid_types.h | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 10 deletions(-)
 create mode 100644 include/linux/uuid_types.h
include/linux/uuid.h +1 -10
index 43d4a79b2..cbdaf0ca4 100644
@@ -9,16 +9,7 @@
 #define _LINUX_UUID_H_
 
 #include <linux/string.h>
-
-#define UUID_SIZE 16
-
-typedef struct {
-	__u8 b[UUID_SIZE];
-} guid_t;
-
-typedef struct {
-	__u8 b[UUID_SIZE];
-} uuid_t;
+#include <linux/uuid_types.h>
 
 #define GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)			\
 ((guid_t)								\
include/linux/uuid_types.h new file +21 -0
new file mode 100644
index 000000000..1e45b6957
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * UUID/GUID types, without the helpers of <linux/uuid.h>, for headers
+ * low in the include chain (such as <linux/uidgid_types.h>)
+ */
+#ifndef _LINUX_UUID_TYPES_H_
+#define _LINUX_UUID_TYPES_H_
+
+#include <linux/types.h>
+
+#define UUID_SIZE 16
+
+typedef struct {
+	__u8 b[UUID_SIZE];
+} guid_t;
+
+typedef struct {
+	__u8 b[UUID_SIZE];
+} uuid_t;
+
+#endif /* _LINUX_UUID_TYPES_H_ */

From 2de9c6c6992fc63fcdbcb695264b58dbc8f5abf7 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 04:53:23 +0200
Subject: [PATCH 02/43] uapi: add <linux/uidgid_r.h> for 128 bit capable user
and group ids

User and group ids are 32 bit numbers. Identities that come from elsewhere -- UUIDs handed out by a directory service, or the GUIDs of a Windows domain -- have to be squeezed into that range through mapping tables kept in userspace, and the kernel never sees who a process really is.

Add a tagged id for a new family of system calls (named after the classic ones with an _r suffix): a classic 32 bit id, an RFC 9562 version 4 UUID, or a Microsoft GUID in the byte order Windows stores it in. Type 0 is "no id", so a zero-initialized id is never root, and lets the set*id_r() calls express "unchanged" without a magic number.

The struct has no 64 bit members and the same layout on all ABIs, so none of the new calls needs a compat entry point.

Assisted-by Claude:claude-opus-5-5
---
 include/uapi/linux/uidgid_r.h | 45 +++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 include/uapi/linux/uidgid_r.h
include/uapi/linux/uidgid_r.h new file +45 -0

45 lines not on this page · raw message

From 08e37622aa591e4ed71916080efdcfa8fbbaf29c Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 05:20:09 +0200
Subject: [PATCH 03/43] uidgid: add uid_is_legacy() and gid_is_legacy()

User and group ids are about to become able to hold a UUID or a GUID besides a classic 32 bit id. Add the predicates code that can only keep a classic id (in 32 bits of a buffer, for instance) tests with, so it can be converted before the types change. For now every id is a classic one.

No functional change.

Assisted-by Claude:claude-opus-5-5
---
 include/linux/uidgid.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
include/linux/uidgid.h +14 -0
index 2dc767e08..182c68245 100644
@@ -22,6 +22,20 @@ struct uid_gid_map;
 #define KUIDT_INIT(value) (kuid_t){ value }
 #define KGIDT_INIT(value) (kgid_t){ value }
 
+/*
+ * Whether an id is a classic 32 bit id. All of them are for now; code that
+ * needs one (to store it in 32 bits, for example) checks with these.
+ */
+static inline bool uid_is_legacy(kuid_t uid)
+{
+	return true;
+}
+
+static inline bool gid_is_legacy(kgid_t gid)
+{
+	return true;
+}
+
 #ifdef CONFIG_MULTIUSER
 static inline uid_t __kuid_val(kuid_t uid)
 {

From ef1608126b20e64560dda494e242a59e01f27671 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 05:20:09 +0200
Subject: [PATCH 04/43] net: sock: read sk_uid through a seqcount

sk_uid is read without a lock, with READ_ONCE(), by the routing lookups and the reuseport checks, while sockfs_setattr() may change it. That only works for as long as a kuid_t is a single word, which it won't be once ids can be UUIDs and GUIDs.

Add sk_uid_seq next to it: writers bump it around the store and hold sk_callback_lock (sock_graft(), sockfs_setattr()) or own the socket alone (sock_init_data_uid()); sk_uid() retries until it sees a whole id. sk_clone() reads the parent's id the same way rather than relying on the copy made by sock_copy().

Assisted-by Claude:claude-opus-5-5
---
 include/net/sock.h | 28 +++++++++++++++++++++++++---
 net/core/sock.c    |  6 +++++-
 net/socket.c       |  5 +++--
 3 files changed, 33 insertions(+), 6 deletions(-)
include/net/sock.h +25 -3
index 60ea55dc1..0986d9466 100644
@@ -294,6 +294,8 @@ struct sk_filter;
   *	@sk_ack_backlog: current listen backlog
   *	@sk_max_ack_backlog: listen backlog set in listen()
   *	@sk_uid: user id of owner
+  *	@sk_uid_seq: makes lockless reads of @sk_uid see a whole id; writers
+  *		     hold @sk_callback_lock
   *	@sk_ino: inode number (zero if orphaned)
   *	@sk_prefer_busy_poll: prefer busypolling over softirq processing
   *	@sk_busy_poll_budget: napi processing budget when busypolling
@@ -509,6 +511,7 @@ struct sock {
 	u32			sk_priority;
 	u32			sk_mark;
 	kuid_t			sk_uid;
+	seqcount_t		sk_uid_seq;
 	u16			sk_protocol;
 	u16			sk_type;
 	struct dst_entry __rcu	*sk_dst_cache;
@@ -2109,11 +2112,23 @@ static inline int sk_rx_queue_get(const struct sock *sk)
 	return -1;
 }
 
+/*
+ * sk_uid is too big for WRITE_ONCE(): writers hold sk_callback_lock (or own
+ * the socket alone, before it is published) and bump sk_uid_seq around the
+ * store, so sk_uid() can read it without a lock.
+ */
+static inline void __sk_set_uid(struct sock *sk, kuid_t uid)
+{
+	write_seqcount_begin(&sk->sk_uid_seq);
+	sk->sk_uid = uid;
+	write_seqcount_end(&sk->sk_uid_seq);
+}
+
 static inline void sk_set_socket(struct sock *sk, struct socket *sock)
 {
 	WRITE_ONCE(sk->sk_socket, sock);
 	if (sock) {
-		WRITE_ONCE(sk->sk_uid, SOCK_INODE(sock)->i_uid);
+		__sk_set_uid(sk, SOCK_INODE(sock)->i_uid);
 		WRITE_ONCE(sk->sk_ino, SOCK_INODE(sock)->i_ino);
 	} else {
 		/* Note: sk_uid is unchanged. */
@@ -2161,8 +2176,15 @@ static inline u64 sock_i_ino(const struct sock *sk)
 
 static inline kuid_t sk_uid(const struct sock *sk)
 {
-	/* Paired with WRITE_ONCE() in sockfs_setattr() */
-	return READ_ONCE(sk->sk_uid);
+	unsigned int seq;
+	kuid_t uid;
+
+	/* Paired with __sk_set_uid() */
+	do {
+		seq = read_seqcount_begin(&sk->sk_uid_seq);
+		uid = sk->sk_uid;
+	} while (read_seqcount_retry(&sk->sk_uid_seq, seq));
+	return uid;
 }
 
 static inline kuid_t sock_net_uid(const struct net *net, const struct sock *sk)
net/core/sock.c +5 -1
index e4503ea6f..e814828e4 100644
@@ -2449,6 +2449,7 @@ static void sk_init_common(struct sock *sk)
 	skb_queue_head_init(&sk->sk_error_queue);
 
 	rwlock_init(&sk->sk_callback_lock);
+	seqcount_init(&sk->sk_uid_seq);
 	lockdep_set_class_and_name(&sk->sk_receive_queue.lock,
 			af_rlock_keys + sk->sk_family,
 			af_family_rlock_key_strings[sk->sk_family]);
@@ -2526,6 +2527,8 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority,
 
 	atomic_set(&newsk->sk_omem_alloc, 0);
 	sk_init_common(newsk);
+	/* sock_copy() may have caught a half written sk_uid */
+	newsk->sk_uid = sk_uid(sk);
 
 	newsk->sk_dst_cache	= NULL;
 	newsk->sk_dst_pending_confirm = 0;
@@ -3770,7 +3773,7 @@ void sock_init_data_uid(struct socket *sock, struct sock *sk, kuid_t uid)
 	} else {
 		RCU_INIT_POINTER(sk->sk_wq, NULL);
 	}
-	sk->sk_uid	=	uid;
+	__sk_set_uid(sk, uid);
 
 	sk->sk_state_change	=	sock_def_wakeup;
 	sk->sk_data_ready	=	sock_def_readable;
@@ -4611,6 +4614,7 @@ static int __init sock_struct_check(void)
 	CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_read_tx, sk_priority);
 	CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_read_tx, sk_mark);
 	CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_read_tx, sk_uid);
+	CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_read_tx, sk_uid_seq);
 	CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_read_tx, sk_protocol);
 	CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_read_tx, sk_dst_cache);
 	CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_read_tx, sk_route_caps);
net/socket.c +3 -2
index 63c69a0fa..abfa71e03 100644
@@ -654,8 +654,9 @@ static int sockfs_setattr(struct mnt_idmap *idmap,
 		struct socket *sock = SOCKET_I(d_inode(dentry));
 
 		if (sock->sk) {
-			/* Paired with READ_ONCE() in sk_uid() */
-			WRITE_ONCE(sock->sk->sk_uid, iattr->ia_uid);
+			write_lock_bh(&sock->sk->sk_callback_lock);
+			__sk_set_uid(sock->sk, iattr->ia_uid);
+			write_unlock_bh(&sock->sk->sk_callback_lock);
 		} else {
 			err = -ENOENT;
 		}

From bc9995e784487b1a01a632fa05cc913c44bea0b3 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 05:20:10 +0200
Subject: [PATCH 05/43] af_unix: keep sender ids in skb->cb only when they are
classic ids

unix_skb_parms has to fit into the 48 bytes of skb->cb. With kuid_t and kgid_t growing to hold UUIDs and GUIDs the two of them alone would take 40 bytes.

Store classic ids as 32 bit values as before, and only for a UUID or GUID allocate a small struct unix_skb_ids for both, freed together with the pid reference in unix_destruct_scm(). AF_UNIX skbs carrying a pid reference are never cloned, so the pointer has a single owner. Senders with classic ids see no change and no allocation.

Assisted-by Claude:claude-opus-5-5
---
 net/unix/af_unix.c | 50 +++++++++++++++++++++++++++++++++++++++-------
 net/unix/af_unix.h | 11 ++++++++--
 2 files changed, 52 insertions(+), 9 deletions(-)
net/unix/af_unix.c +43 -7

89 lines not on this page · raw message

net/unix/af_unix.h +9 -2
index 8119dbeef..e861a430c 100644
@@ -10,10 +10,17 @@
 
 struct sock *unix_peer_get(struct sock *sk);
 
-struct unix_skb_parms {
-	struct pid		*pid;		/* skb credentials	*/
+/* The sender's ids, when either is a UUID or GUID */
+struct unix_skb_ids {
 	kuid_t			uid;
 	kgid_t			gid;
+};
+
+struct unix_skb_parms {
+	struct pid		*pid;		/* skb credentials	*/
+	struct unix_skb_ids	*ids;		/* uid and gid, or NULL	*/
+	uid_t			uid;		/* for ids NULL: legacy	*/
+	gid_t			gid;		/* uid and gid		*/
 	struct scm_fp_list	*fp;		/* Passed files		*/
 #ifdef CONFIG_SECURITY_NETWORK
 	u32			secid;		/* Security ID		*/

From 569df5c5b28e22abba24652840bcfb06460e86d4 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 05:20:10 +0200
Subject: [PATCH 06/43] netlink: keep classic sender ids in skb->cb

netlink_skb_parms has to fit into skb->cb, and netlink skbs are cloned together with it for broadcasts, so there is neither room for kuid_t and kgid_t holding UUIDs nor a single owner for an allocation.

Store the sender ids as classic kernel ids: a UUID or GUID becomes -1, which reaches the receiver of SCM_CREDENTIALS as the overflow id. The kernel's own permission checks on netlink messages use the socket's file credentials, not these.

Assisted-by Claude:claude-opus-5-5
---
 include/linux/netlink.h  |  2 +-
 include/net/scm.h        | 28 ++++++++++++++++++++++++++++
 lib/kobject_uevent.c     |  8 ++++----
 net/netlink/af_netlink.c |  4 ++--
 4 files changed, 35 insertions(+), 7 deletions(-)
include/linux/netlink.h +1 -1
index 882e9c1b6..999c7a352 100644
@@ -23,7 +23,7 @@ enum netlink_skb_flags {
 };
 
 struct netlink_skb_parms {
-	struct scm_creds	creds;		/* Skb credentials	*/
+	struct scm_creds_classic creds;		/* Skb credentials	*/
 	__u32			portid;
 	__u32			dst_group;
 	__u32			flags;
include/net/scm.h +28 -0
index c52519669..e8a32f2d5 100644
@@ -23,6 +23,34 @@ struct scm_creds {
 	kgid_t	gid;
 };
 
+/*
+ * Sender credentials for skb->cb of skbs that get cloned along with it
+ * (netlink, bluetooth): no room for kuid_t and kgid_t, and no single owner
+ * for an allocation. The ids are classic kernel ids; a UUID or GUID becomes
+ * -1, which the receiver of SCM_CREDENTIALS sees as the overflow id.
+ */
+struct scm_creds_classic {
+	u32	pid;
+	uid_t	uid;
+	gid_t	gid;
+};
+
+static inline void scm_creds_to_classic(struct scm_creds_classic *classic,
+					const struct scm_creds *creds)
+{
+	classic->pid = creds->pid;
+	classic->uid = __kuid_val(creds->uid);
+	classic->gid = __kgid_val(creds->gid);
+}
+
+static inline void scm_creds_from_classic(struct scm_creds *creds,
+					  const struct scm_creds_classic *classic)
+{
+	creds->pid = classic->pid;
+	creds->uid = KUIDT_INIT(classic->uid);
+	creds->gid = KGIDT_INIT(classic->gid);
+}
+
 #ifdef CONFIG_UNIX
 struct unix_edge;
 #endif
lib/kobject_uevent.c +4 -4
index ddbc4d748..8b6304488 100644
@@ -297,8 +297,8 @@ static struct sk_buff *alloc_uevent_skb(struct kobj_uevent_env *env,
 	skb_put_data(skb, env->buf, env->buflen);
 
 	parms = &NETLINK_CB(skb);
-	parms->creds.uid = GLOBAL_ROOT_UID;
-	parms->creds.gid = GLOBAL_ROOT_GID;
+	parms->creds.uid = __kuid_val(GLOBAL_ROOT_UID);
+	parms->creds.gid = __kgid_val(GLOBAL_ROOT_GID);
 	parms->dst_group = 1;
 	parms->portid = 0;
 
@@ -362,12 +362,12 @@ static int uevent_net_broadcast_tagged(struct sock *usk,
 		/* fix uid */
 		root_uid = make_kuid(owning_user_ns, 0);
 		if (uid_valid(root_uid))
-			parms->creds.uid = root_uid;
+			parms->creds.uid = __kuid_val(root_uid);
 
 		/* fix gid */
 		root_gid = make_kgid(owning_user_ns, 0);
 		if (gid_valid(root_gid))
-			parms->creds.gid = root_gid;
+			parms->creds.gid = __kgid_val(root_gid);
 	}
 
 	ret = netlink_broadcast(usk, skb, 0, 1, GFP_KERNEL);
net/netlink/af_netlink.c +2 -2
index 7288de715..2cc51f5cd 100644
@@ -1897,7 +1897,7 @@ static int netlink_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
 
 	NETLINK_CB(skb).portid	= nlk->portid;
 	NETLINK_CB(skb).dst_group = dst_group;
-	NETLINK_CB(skb).creds	= scm.creds;
+	scm_creds_to_classic(&NETLINK_CB(skb).creds, &scm.creds);
 	NETLINK_CB(skb).flags	= netlink_skb_flags;
 
 	err = -EFAULT;
@@ -1990,7 +1990,7 @@ static int netlink_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
 		netlink_cmsg_listen_all_nsid(sk, msg, skb);
 
 	memset(&scm, 0, sizeof(scm));
-	scm.creds = *NETLINK_CREDS(skb);
+	scm_creds_from_classic(&scm.creds, NETLINK_CREDS(skb));
 	if (flags & MSG_TRUNC)
 		copied = data_skb->len;
 

From d7971b6cc6b094a0d9e6c844b153e45d447b9a49 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 09:25:48 +0200
Subject: [PATCH 07/43] Bluetooth: keep classic sender ids in skb->cb

struct bt_skb_cb holds the sender's struct scm_creds for HCI sockets, which no longer fits into skb->cb now that kuid_t and kgid_t can hold UUIDs and GUIDs. Like netlink, keep them as struct scm_creds_classic:
classic ids as before, the overflow id for UUID and GUID senders.

Assisted-by Claude:claude-opus-5-5
---
 include/net/bluetooth/bluetooth.h | 2 +-
 net/bluetooth/hci_sock.c          | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
include/net/bluetooth/bluetooth.h +1 -1
index b624da502..2c8fe50f4 100644
@@ -497,7 +497,7 @@ struct bt_skb_cb {
 		struct l2cap_ctrl l2cap;
 		struct hci_ctrl hci;
 		struct mgmt_ctrl mgmt;
-		struct scm_creds creds;
+		struct scm_creds_classic creds;
 	};
 };
 #define bt_cb(skb) ((struct bt_skb_cb *)((skb)->cb))
net/bluetooth/hci_sock.c +4 -4
index 81068b585..9f422ae5f 100644
@@ -276,7 +276,7 @@ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb)
 
 static void hci_sock_copy_creds(struct sock *sk, struct sk_buff *skb)
 {
-	struct scm_creds *creds;
+	struct scm_creds_classic *creds;
 
 	if (!sk || WARN_ON(!skb))
 		return;
@@ -300,8 +300,8 @@ static void hci_sock_copy_creds(struct sock *sk, struct sk_buff *skb)
 
 	creds->pid = pid_vnr(sk->sk_peer_pid);
 	if (sk->sk_peer_cred) {
-		creds->uid = sk->sk_peer_cred->uid;
-		creds->gid = sk->sk_peer_cred->gid;
+		creds->uid = __kuid_val(sk->sk_peer_cred->uid);
+		creds->gid = __kgid_val(sk->sk_peer_cred->gid);
 	}
 }
 
@@ -1615,7 +1615,7 @@ static int hci_sock_recvmsg(struct socket *sock, struct msghdr *msg,
 	}
 
 	memset(&scm, 0, sizeof(scm));
-	scm.creds = bt_cb(skb)->creds;
+	scm_creds_from_classic(&scm.creds, &bt_cb(skb)->creds);
 
 	skb_free_datagram(sk, skb);
 

From 225a9221002f52d05cecffd96c09bb83fb4ab23f Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 09:25:48 +0200
Subject: [PATCH 08/43] smb: client: use __kuid_val() for the unix SIDs of the
caller

The S-1-5-88-1-<uid> and S-1-5-88-2-<gid> SIDs sent with a create request take the raw kernel ids from kuid_t.val, which is gone now that the ids can be UUIDs and GUIDs. Use __kuid_val()/__kgid_val(), the same value for classic ids and -1 for the others, which have no unix SID.

Assisted-by Claude:claude-opus-5-5
---
 fs/smb/client/cifsacl.c | 2 +-
 fs/smb/client/smb2pdu.c | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)
fs/smb/client/cifsacl.c +1 -1
index c5e47a835..78ed25b1f 100644
@@ -1086,7 +1086,7 @@ unsigned int setup_special_user_owner_ACE(struct smb_ace *pntace)
 
 	pntace->sid.sub_auth[0] = sid_unix_NFS_users.sub_auth[0];
 	pntace->sid.sub_auth[1] = sid_unix_NFS_users.sub_auth[1];
-	pntace->sid.sub_auth[2] = cpu_to_le32(current_fsgid().val);
+	pntace->sid.sub_auth[2] = cpu_to_le32(__kgid_val(current_fsgid()));
 
 	/* size = 1 + 1 + 2 + 4 + 1 + 1 + 6 + (psid->num_subauth*4) */
 	pntace->size = cpu_to_le16(ace_size);
fs/smb/client/smb2pdu.c +4 -3
index cfe3c4b4a..941ca8a3d 100644
@@ -2731,7 +2731,7 @@ static void setup_owner_group_sids(char *buf)
 	sids->owner.Authority[5] = 5;
 	sids->owner.SubAuthorities[0] = cpu_to_le32(88);
 	sids->owner.SubAuthorities[1] = cpu_to_le32(1);
-	sids->owner.SubAuthorities[2] = cpu_to_le32(current_fsuid().val);
+	sids->owner.SubAuthorities[2] = cpu_to_le32(__kuid_val(current_fsuid()));
 
 	/* Populate the group ownership fields S-1-5-88-2 */
 	sids->group.Revision = 1;
@@ -2739,9 +2739,10 @@ static void setup_owner_group_sids(char *buf)
 	sids->group.Authority[5] = 5;
 	sids->group.SubAuthorities[0] = cpu_to_le32(88);
 	sids->group.SubAuthorities[1] = cpu_to_le32(2);
-	sids->group.SubAuthorities[2] = cpu_to_le32(current_fsgid().val);
+	sids->group.SubAuthorities[2] = cpu_to_le32(__kgid_val(current_fsgid()));
 
-	cifs_dbg(FYI, "owner S-1-5-88-1-%d, group S-1-5-88-2-%d\n", current_fsuid().val, current_fsgid().val);
+	cifs_dbg(FYI, "owner S-1-5-88-1-%d, group S-1-5-88-2-%d\n",
+		 __kuid_val(current_fsuid()), __kgid_val(current_fsgid()));
 }
 
 /* See MS-SMB2 2.2.13.2.2 and MS-DTYP 2.4.6 */

From 093cde89699173d36105300d26d92a2f4bf5475a Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 05:20:33 +0200
Subject: [PATCH 09/43] uidgid: let kuid_t and kgid_t hold a UUID or a GUID

Make kuid_t and kgid_t (and vfsuid_t and vfsgid_t, which share their layout) tagged unions: a classic 32 bit id, an RFC 9562 UUID, or a Microsoft GUID. KID_LEGACY is 0, so zeroed memory still holds the root ids, and KUIDT_INIT()/KGIDT_INIT() keep building classic ids, so the bulk of the kernel needs no change. The member is renamed from val to legacy so the compiler finds code that peeks at it directly.

Semantics of the new ids:

- They are not in any uid_map or gid_map: they exist in the initial user namespace only. kuid_has_mapping() is false for them in every other namespace, so no capability in a child namespace gives privilege over them, and from_kuid() and friends give -1 (the overflow id when munged), exactly as for any other id without a mapping. Anything that can only store or report a 32 bit id thereby already treats them safely.

- Idmapped mounts map classic ids; UUIDs and GUIDs pass through them unchanged, as long as the filesystem itself is in the initial user namespace.

- Ids are ordered by kind first and value second, so sorted group lists, bsearch() and range checks between classic ids keep working:
a UUID never falls into a range of classic ids.

- __kuid_val() and __kgid_val() stay the classic value of a classic id and are -1 for the others; hash tables keyed by ids (user_struct, ucounts) use the new kuid_hash() instead, and the IMA policy comparators the new ordering.

The structs grow from 4 to 20 bytes: struct cred by 128 bytes, struct inode by 32 bytes.

Assisted-by Claude:claude-opus-5-5
---
 fs/mnt_idmapping.c                  |  14 ++++
 include/linux/mnt_idmapping.h       |  74 ++++++++++++++-----
 include/linux/uidgid.h              | 109 ++++++++++++++++++++++------
 include/linux/uidgid_types.h        |  32 +++++++-
 kernel/groups.c                     |  15 ++--
 kernel/ucount.c                     |   2 +-
 kernel/user.c                       |   2 +-
 kernel/user_namespace.c             |  10 ++-
 mm/oom_kill.c                       |   2 +-
 security/integrity/ima/ima_policy.c |   8 +-
 10 files changed, 209 insertions(+), 59 deletions(-)
fs/mnt_idmapping.c +14 -0
index cb61fbdb5..c36e74a37 100644
@@ -87,6 +87,10 @@ vfsuid_t make_vfsuid(struct mnt_idmap *idmap,
 		return VFSUIDT_INIT(kuid);
 	if (idmap == &invalid_mnt_idmap)
 		return INVALID_VFSUID;
+	/* idmappings map classic ids only; UUIDs and GUIDs pass unchanged */
+	if (!uid_is_legacy(kuid))
+		return kuid_has_mapping(fs_userns, kuid) ?
+		       VFSUIDT_INIT(kuid) : INVALID_VFSUID;
 	if (initial_idmapping(fs_userns))
 		uid = __kuid_val(kuid);
 	else
@@ -126,6 +130,10 @@ vfsgid_t make_vfsgid(struct mnt_idmap *idmap,
 		return VFSGIDT_INIT(kgid);
 	if (idmap == &invalid_mnt_idmap)
 		return INVALID_VFSGID;
+	/* idmappings map classic ids only; UUIDs and GUIDs pass unchanged */
+	if (!gid_is_legacy(kgid))
+		return kgid_has_mapping(fs_userns, kgid) ?
+		       VFSGIDT_INIT(kgid) : INVALID_VFSGID;
 	if (initial_idmapping(fs_userns))
 		gid = __kgid_val(kgid);
 	else
@@ -156,6 +164,9 @@ kuid_t from_vfsuid(struct mnt_idmap *idmap,
 		return AS_KUIDT(vfsuid);
 	if (idmap == &invalid_mnt_idmap)
 		return INVALID_UID;
+	if (!vfsuid_is_legacy(vfsuid))
+		return kuid_has_mapping(fs_userns, AS_KUIDT(vfsuid)) ?
+		       AS_KUIDT(vfsuid) : INVALID_UID;
 	uid = map_id_up(&idmap->uid_map, __vfsuid_val(vfsuid));
 	if (uid == (uid_t)-1)
 		return INVALID_UID;
@@ -185,6 +196,9 @@ kgid_t from_vfsgid(struct mnt_idmap *idmap,
 		return AS_KGIDT(vfsgid);
 	if (idmap == &invalid_mnt_idmap)
 		return INVALID_GID;
+	if (!vfsgid_is_legacy(vfsgid))
+		return kgid_has_mapping(fs_userns, AS_KGIDT(vfsgid)) ?
+		       AS_KGIDT(vfsgid) : INVALID_GID;
 	gid = map_id_up(&idmap->gid_map, __vfsgid_val(vfsgid));
 	if (gid == (gid_t)-1)
 		return INVALID_GID;
include/linux/mnt_idmapping.h +56 -18

155 lines not on this page · raw message

include/linux/uidgid.h +87 -22

196 lines not on this page · raw message

include/linux/uidgid_types.h +30 -2
index b35ac4955..0f595d075 100644
@@ -3,13 +3,41 @@
 #define _LINUX_UIDGID_TYPES_H
 
 #include <linux/types.h>
+#include <linux/uuid_types.h>
 
+/*
+ * Kinds of kuid_t and kgid_t. KID_LEGACY is 0, so zeroed memory still
+ * holds GLOBAL_ROOT_UID and GLOBAL_ROOT_GID as it did when the ids were
+ * plain numbers. Userspace has its own numbering (UID_R_* in
+ * <uapi/linux/uidgid_r.h>), in which zero is "no id".
+ */
+enum kid_type {
+	KID_LEGACY = 0,		/* classic 32 bit id in .legacy */
+	KID_UUID,		/* RFC 9562 UUID in .uuid */
+	KID_GUID,		/* Microsoft GUID in .guid */
+};
+
+/*
+ * Only the member .type selects is meaningful; the bytes of .uuid past
+ * .legacy are undefined for a KID_LEGACY id. Copy the whole struct and
+ * use the helpers of <linux/uidgid.h> to look at it.
+ */
 typedef struct {
-	uid_t val;
+	u32 type;
+	union {
+		uid_t legacy;
+		uuid_t uuid;
+		guid_t guid;
+	};
 } kuid_t;
 
 typedef struct {
-	gid_t val;
+	u32 type;
+	union {
+		gid_t legacy;
+		uuid_t uuid;
+		guid_t guid;
+	};
 } kgid_t;
 
 #endif /* _LINUX_UIDGID_TYPES_H */
kernel/groups.c +7 -8
index b5e3be6a6..3aa0651d7 100644
@@ -73,18 +73,15 @@ static int groups_from_user(struct group_info *group_info,
 	return 0;
 }
 
-static int gid_cmp(const void *_a, const void *_b)
+static int groups_cmp(const void *_a, const void *_b)
 {
-	kgid_t a = *(kgid_t *)_a;
-	kgid_t b = *(kgid_t *)_b;
-
-	return gid_gt(a, b) - gid_lt(a, b);
+	return gid_cmp(*(kgid_t *)_a, *(kgid_t *)_b);
 }
 
 void groups_sort(struct group_info *group_info)
 {
 	sort(group_info->gid, group_info->ngroups, sizeof(*group_info->gid),
-	     gid_cmp, NULL);
+	     groups_cmp, NULL);
 }
 EXPORT_SYMBOL(groups_sort);
 
@@ -100,9 +97,11 @@ int groups_search(const struct group_info *group_info, kgid_t grp)
 	right = group_info->ngroups;
 	while (left < right) {
 		unsigned int mid = (left+right)/2;
-		if (gid_gt(grp, group_info->gid[mid]))
+		int cmp = gid_cmp(grp, group_info->gid[mid]);
+
+		if (cmp > 0)
 			left = mid + 1;
-		else if (gid_lt(grp, group_info->gid[mid]))
+		else if (cmp < 0)
 			right = mid;
 		else
 			return 1;
kernel/ucount.c +1 -1
index d6dc3e859..3cf03ad7c 100644
@@ -22,7 +22,7 @@ static struct hlist_nulls_head ucounts_hashtable[UCOUNTS_HASHTABLE_ENTRIES] = {
 static DEFINE_SPINLOCK(ucounts_lock);
 
 #define ucounts_hashfn(ns, uid)						\
-	hash_long((unsigned long)__kuid_val(uid) + (unsigned long)(ns), \
+	hash_long((unsigned long)kuid_hash(uid) + (unsigned long)(ns), \
 		  UCOUNTS_HASHTABLE_BITS)
 #define ucounts_hashentry(ns, uid)	\
 	(ucounts_hashtable + ucounts_hashfn(ns, uid))
kernel/user.c +1 -1
index 7aef4e679..11a226bf8 100644
@@ -88,7 +88,7 @@ EXPORT_SYMBOL_GPL(init_user_ns);
 #define UIDHASH_SZ	(1 << UIDHASH_BITS)
 #define UIDHASH_MASK		(UIDHASH_SZ - 1)
 #define __uidhashfn(uid)	(((uid >> UIDHASH_BITS) + uid) & UIDHASH_MASK)
-#define uidhashentry(uid)	(uidhash_table + __uidhashfn((__kuid_val(uid))))
+#define uidhashentry(uid)	(uidhash_table + __uidhashfn(kuid_hash(uid)))
 
 static struct kmem_cache *uid_cachep;
 static struct hlist_head uidhash_table[UIDHASH_SZ];
kernel/user_namespace.c +8 -2
index 0bed462e9..88fc8ba58 100644
@@ -436,10 +436,13 @@ EXPORT_SYMBOL(make_kuid);
  *
  *	There is always a mapping into the initial user_namespace.
  *
- *	If @kuid has no mapping in @targ (uid_t)-1 is returned.
+ *	If @kuid has no mapping in @targ (uid_t)-1 is returned. A UUID or
+ *	GUID has no classic uid in any user namespace.
  */
 uid_t from_kuid(struct user_namespace *targ, kuid_t kuid)
 {
+	if (!uid_is_legacy(kuid))
+		return (uid_t) -1;
 	/* Map the uid from a global kernel uid */
 	return map_id_up(&targ->uid_map, __kuid_val(kuid));
 }
@@ -504,10 +507,13 @@ EXPORT_SYMBOL(make_kgid);
  *
  *	There is always a mapping into the initial user_namespace.
  *
- *	If @kgid has no mapping in @targ (gid_t)-1 is returned.
+ *	If @kgid has no mapping in @targ (gid_t)-1 is returned. A UUID or
+ *	GUID has no classic gid in any user namespace.
  */
 gid_t from_kgid(struct user_namespace *targ, kgid_t kgid)
 {
+	if (!gid_is_legacy(kgid))
+		return (gid_t) -1;
 	/* Map the gid from a global kernel gid */
 	return map_id_up(&targ->gid_map, __kgid_val(kgid));
 }
mm/oom_kill.c +1 -1
index 5f372f6e2..2ce307293 100644
@@ -771,7 +771,7 @@ static void mark_oom_victim(struct task_struct *tsk)
 	thaw_process(tsk);
 	atomic_inc(&oom_victims);
 	cred = get_task_cred(tsk);
-	trace_mark_victim(tsk, cred->uid.val);
+	trace_mark_victim(tsk, __kuid_val(cred->uid));
 	put_cred(cred);
 }
 
security/integrity/ima/ima_policy.c +4 -4
index b1c010e8e..3ea17c6c0 100644
@@ -79,22 +79,22 @@ struct ima_rule_opt_list {
  */
 static inline bool vfsuid_gt_kuid(vfsuid_t vfsuid, kuid_t kuid)
 {
-	return __vfsuid_val(vfsuid) > __kuid_val(kuid);
+	return vfsuid_cmp(vfsuid, VFSUIDT_INIT(kuid)) > 0;
 }
 
 static inline bool vfsgid_gt_kgid(vfsgid_t vfsgid, kgid_t kgid)
 {
-	return __vfsgid_val(vfsgid) > __kgid_val(kgid);
+	return vfsgid_cmp(vfsgid, VFSGIDT_INIT(kgid)) > 0;
 }
 
 static inline bool vfsuid_lt_kuid(vfsuid_t vfsuid, kuid_t kuid)
 {
-	return __vfsuid_val(vfsuid) < __kuid_val(kuid);
+	return vfsuid_cmp(vfsuid, VFSUIDT_INIT(kuid)) < 0;
 }
 
 static inline bool vfsgid_lt_kgid(vfsgid_t vfsgid, kgid_t kgid)
 {
-	return __vfsgid_val(vfsgid) < __kgid_val(kgid);
+	return vfsgid_cmp(vfsgid, VFSGIDT_INIT(kgid)) < 0;
 }
 
 struct ima_rule_entry {

From 071a6e5d021ccb4f8480761e148b06ce58114758 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 05:20:33 +0200
Subject: [PATCH 10/43] uidgid: convert between kernel ids and the ids of the
*_r system calls

Add the conversions between kuid_t/kgid_t and __kernel_uid_r_t the new system calls need: make_kuid_r(), from_kuid_r() and the never failing from_kuid_r_munged() (and the gid variants), and get_kuid_r() and put_kuid_r() to copy them from and to userspace.

get_kuid_r() returns INVALID_UID for "no id" -- a NULL pointer, UID_R_NONE, or a classic -1 -- which the set*id_r() and chown_r() calls take as "unchanged", like the classic calls take -1. It rejects malformed ids: unknown types, nonzero reserved bytes, UUIDs other than RFC 9562 version 4, the nil GUID, and UUIDs or GUIDs given from outside the initial user namespace.

Also add kuid_str() and kgid_str(), the text form of an id for logs and
procfs: a classic id in decimal, a UUID as usual, a GUID in braces.

Assisted-by Claude:claude-opus-5-5
---
 include/linux/uidgid.h |  35 +++++
 kernel/Makefile        |   1 +
 kernel/uidgid_r.c      | 323 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 359 insertions(+)
 create mode 100644 kernel/uidgid_r.c
include/linux/uidgid.h +35 -0
index e1adb50d5..ac7786f76 100644
@@ -180,6 +180,17 @@ static inline u32 kgid_hash(kgid_t gid)
 	return __kid_hash(gid.type, __kgid_val(gid), gid.uuid.b);
 }
 
+/*
+ * The text form of an id, for logs and procfs: a legacy id as a decimal
+ * number, a UUID as "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" and a GUID in
+ * braces, "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}". KID_STR_LEN includes
+ * the terminating NUL.
+ */
+#define KID_STR_LEN 39
+
+char *kuid_str(kuid_t uid, char buf[KID_STR_LEN]);
+char *kgid_str(kgid_t gid, char buf[KID_STR_LEN]);
+
 #ifdef CONFIG_USER_NS
 
 extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
@@ -277,4 +288,28 @@ static inline u32 map_id_up(struct uid_gid_map *map, u32 id)
 }
 #endif /* CONFIG_USER_NS */
 
+/*
+ * Conversion between kuid_t/kgid_t and the ids of the *_r system calls
+ * (<uapi/linux/uidgid_r.h>), in kernel/uidgid_r.c.
+ */
+struct __kernel_uid_r;
+
+kuid_t make_kuid_r(struct user_namespace *from, const struct __kernel_uid_r *id);
+kgid_t make_kgid_r(struct user_namespace *from, const struct __kernel_uid_r *id);
+bool from_kuid_r(struct user_namespace *to, kuid_t uid, struct __kernel_uid_r *id);
+bool from_kgid_r(struct user_namespace *to, kgid_t gid, struct __kernel_uid_r *id);
+void from_kuid_r_munged(struct user_namespace *to, kuid_t uid,
+			struct __kernel_uid_r *id);
+void from_kgid_r_munged(struct user_namespace *to, kgid_t gid,
+			struct __kernel_uid_r *id);
+
+int get_kuid_r(struct user_namespace *from,
+	       const struct __kernel_uid_r __user *uid, kuid_t *kuid);
+int get_kgid_r(struct user_namespace *from,
+	       const struct __kernel_uid_r __user *gid, kgid_t *kgid);
+int put_kuid_r(struct user_namespace *to, kuid_t kuid,
+	       struct __kernel_uid_r __user *uid);
+int put_kgid_r(struct user_namespace *to, kgid_t kgid,
+	       struct __kernel_uid_r __user *gid);
+
 #endif /* _LINUX_UIDGID_H */
kernel/Makefile +1 -0
index 1e1a31673..813ddbf11 100644
@@ -89,6 +89,7 @@ obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o
 obj-$(CONFIG_COMPAT) += compat.o
 obj-$(CONFIG_CGROUPS) += cgroup/
 obj-$(CONFIG_UTS_NS) += utsname.o
+obj-y += uidgid_r.o
 obj-$(CONFIG_USER_NS) += user_namespace.o
 obj-$(CONFIG_PID_NS) += pid_namespace.o
 obj-$(CONFIG_IKCONFIG) += configs.o
kernel/uidgid_r.c new file +323 -0

323 lines not on this page · raw message

From ff405749f415e682fa1ce99c7dcba8795fe35997 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 05:20:33 +0200
Subject: [PATCH 11/43] fscrypt: show the whole uid in the description of user
key claims

The ".fscrypt" keys that account a master key to a user are described as "<identifier>.uid.<uid>". For a UUID or GUID uid that printed -1; use kuid_str() so /proc/keys shows who the claim belongs to. Lookups compare the kuid itself and are not affected.

Assisted-by Claude:claude-opus-5-5
---
 fs/crypto/keyring.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/crypto/keyring.c +4 -3
index 38b73e703..1b9e80223 100644
@@ -178,7 +178,7 @@ static struct key_type key_type_fscrypt_user = {
 };
 
 #define FSCRYPT_MK_USER_DESCRIPTION_SIZE	\
-	(2 * FSCRYPT_KEY_IDENTIFIER_SIZE + CONST_STRLEN(".uid.") + 10 + 1)
+	(2 * FSCRYPT_KEY_IDENTIFIER_SIZE + CONST_STRLEN(".uid.") + KID_STR_LEN)
 
 /* Create ->s_master_keys if needed.  Synchronized by fscrypt_add_key_mutex. */
 static int allocate_filesystem_keyring(struct super_block *sb)
@@ -338,13 +338,14 @@ static int add_master_key_user(struct fscrypt_master_key *mk)
 {
 	kuid_t uid = current_fsuid();
 	char description[FSCRYPT_MK_USER_DESCRIPTION_SIZE];
+	char uidbuf[KID_STR_LEN];
 	struct key *quota_key;
 	struct fscrypt_master_key_user *mk_user;
 	int err;
 
-	snprintf(description, sizeof(description), "%*phN.uid.%u",
+	snprintf(description, sizeof(description), "%*phN.uid.%s",
 		 FSCRYPT_KEY_IDENTIFIER_SIZE, mk->mk_spec.u.identifier,
-		 __kuid_val(uid));
+		 kuid_str(uid, uidbuf));
 	quota_key = key_alloc(&key_type_fscrypt_user, description, uid,
 			      current_gid(), current_cred(),
 			      KEY_POS_SEARCH | KEY_USR_VIEW, 0, NULL);

From f6833729017d969eeb706c8d025ceecfcbd109e2 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 06:01:52 +0200
Subject: [PATCH 12/43] keys: name per-user keyrings of UUID and GUID users by
the whole uid

The user keyring, the user session keyring and the persistent keyring are found by name: "_uid.<uid>", "_uid_ses.<uid>" and "_persistent.<uid>", the uid in the caller's user namespace. A UUID or GUID uid has none and comes out as -1, so all such users would find and share the same keyrings -- each other's keys.

Name their keyrings after the text form of the uid (kuid_str()), which is unique; classic uids keep their names. Hand request-key the text form as well instead of -1.

Also add KEYCTL_CHOWN_R, KEYCTL_CHOWN with __kernel_uid_r_t ids, so keys can be given to UUID and GUID users and groups.

Assisted-by Claude:claude-opus-5-5
---
 include/uapi/linux/keyctl.h  |  1 +
 security/keys/compat.c       |  3 ++
 security/keys/internal.h     |  3 ++
 security/keys/keyctl.c       | 61 ++++++++++++++++++++++++++----------
 security/keys/persistent.c   | 11 +++++--
 security/keys/process_keys.c | 36 +++++++++++++++------
 security/keys/request_key.c  | 12 +++++--
 7 files changed, 97 insertions(+), 30 deletions(-)
include/uapi/linux/keyctl.h +1 -0
index 4c8884eea..73ee0cb7b 100644
@@ -70,6 +70,7 @@
 #define KEYCTL_MOVE			30	/* Move keys between keyrings */
 #define KEYCTL_CAPABILITIES		31	/* Find capabilities of keyrings subsystem */
 #define KEYCTL_WATCH_KEY		32	/* Watch a key or ring of keys for changes */
+#define KEYCTL_CHOWN_R			33	/* set ownership of a key, __kernel_uid_r_t ids */
 
 /* keyctl structures */
 struct keyctl_dh_params {
security/keys/compat.c +3 -0
index 1545efdca..c7acf7db5 100644
@@ -52,6 +52,9 @@ COMPAT_SYSCALL_DEFINE5(keyctl, u32, option,
 	case KEYCTL_CHOWN:
 		return keyctl_chown_key(arg2, arg3, arg4);
 
+	case KEYCTL_CHOWN_R:
+		return keyctl_chown_key_r(arg2, compat_ptr(arg3), compat_ptr(arg4));
+
 	case KEYCTL_SETPERM:
 		return keyctl_setperm_key(arg2, arg3);
 
security/keys/internal.h +3 -0
index b7b622bc3..63874fa53 100644
@@ -249,6 +249,9 @@ extern long keyctl_keyring_search(key_serial_t, const char __user *,
 				  const char __user *, key_serial_t);
 extern long keyctl_read_key(key_serial_t, char __user *, size_t);
 extern long keyctl_chown_key(key_serial_t, uid_t, gid_t);
+extern long keyctl_chown_key_r(key_serial_t id,
+			       const struct __kernel_uid_r __user *user,
+			       const struct __kernel_uid_r __user *group);
 extern long keyctl_setperm_key(key_serial_t, key_perm_t);
 extern long keyctl_instantiate_key(key_serial_t, const void __user *,
 				   size_t, key_serial_t);
security/keys/keyctl.c +45 -16

109 lines not on this page · raw message

security/keys/persistent.c +9 -2
index bdab99539..2c4b32cd2 100644
@@ -83,7 +83,8 @@ static long key_get_persistent(struct user_namespace *ns, kuid_t uid,
 	struct keyring_index_key index_key;
 	struct key *persistent;
 	key_ref_t reg_ref, persistent_ref;
-	char buf[32];
+	char buf[sizeof("_persistent.") + KID_STR_LEN];
+	char idbuf[KID_STR_LEN];
 	long ret;
 	bool created = false;
 
@@ -91,7 +92,13 @@ static long key_get_persistent(struct user_namespace *ns, kuid_t uid,
 	memset(&index_key, 0, sizeof(index_key));
 	index_key.type = &key_type_keyring;
 	index_key.description = buf;
-	index_key.desc_len = sprintf(buf, "_persistent.%u", from_kuid(ns, uid));
+	/* a UUID or GUID has no uid in @ns: name it by its text form */
+	if (uid_is_legacy(uid))
+		index_key.desc_len = sprintf(buf, "_persistent.%u",
+					     from_kuid(ns, uid));
+	else
+		index_key.desc_len = sprintf(buf, "_persistent.%s",
+					     kuid_str(uid, idbuf));
 	key_set_index_key(&index_key);
 
 	if (ns->persistent_keyring_register) {
security/keys/process_keys.c +27 -9
index a63c46bb2..6f275899f 100644
@@ -67,6 +67,25 @@ static struct key *get_user_register(struct user_namespace *user_ns)
 	return reg_keyring;
 }
 
+/*
+ * The name of a user's keyring or user session keyring: @prefix and the uid
+ * in @user_ns, or for a UUID or GUID uid its text form. Those have no uid
+ * in any namespace, and as -1 all of them would share the keyrings.
+ */
+#define USER_KEYRING_NAME_SIZE	(sizeof("_uid_ses.") + KID_STR_LEN)
+
+static int user_keyring_name(char *buf, const char *prefix,
+			     struct user_namespace *user_ns, kuid_t kuid)
+{
+	char idbuf[KID_STR_LEN];
+
+	if (!uid_is_legacy(kuid))
+		return snprintf(buf, USER_KEYRING_NAME_SIZE, "%s%s", prefix,
+				kuid_str(kuid, idbuf));
+	return snprintf(buf, USER_KEYRING_NAME_SIZE, "%s%u", prefix,
+			from_kuid(user_ns, kuid));
+}
+
 /*
  * Look up the user and user session keyrings for the current process's UID,
  * creating them if they don't exist.
@@ -79,13 +98,12 @@ int look_up_user_keyrings(struct key **_user_keyring,
 	struct key *reg_keyring, *uid_keyring, *session_keyring;
 	key_perm_t user_keyring_perm;
 	key_ref_t uid_keyring_r, session_keyring_r;
-	uid_t uid = from_kuid(user_ns, cred->user->uid);
-	char buf[20];
+	char buf[USER_KEYRING_NAME_SIZE];
 	int ret;
 
 	user_keyring_perm = (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_ALL;
 
-	kenter("%u", uid);
+	kenter("%u", from_kuid(user_ns, cred->user->uid));
 
 	reg_keyring = get_user_register(user_ns);
 	if (IS_ERR(reg_keyring))
@@ -98,7 +116,7 @@ int look_up_user_keyrings(struct key **_user_keyring,
 	 * already as it may have been pinned by a session, but the user_struct
 	 * pointing to it may have been destroyed by setuid.
 	 */
-	snprintf(buf, sizeof(buf), "_uid.%u", uid);
+	user_keyring_name(buf, "_uid.", user_ns, cred->user->uid);
 	uid_keyring_r = keyring_search(make_key_ref(reg_keyring, true),
 				       &key_type_keyring, buf, false);
 	kdebug("_uid %p", uid_keyring_r);
@@ -120,7 +138,7 @@ int look_up_user_keyrings(struct key **_user_keyring,
 	}
 
 	/* Get a default session keyring (which might also exist already) */
-	snprintf(buf, sizeof(buf), "_uid_ses.%u", uid);
+	user_keyring_name(buf, "_uid_ses.", user_ns, cred->user->uid);
 	session_keyring_r = keyring_search(make_key_ref(reg_keyring, true),
 					   &key_type_keyring, buf, false);
 	kdebug("_uid_ses %p", session_keyring_r);
@@ -186,7 +204,7 @@ struct key *get_user_session_keyring_rcu(const struct cred *cred)
 {
 	struct key *reg_keyring = READ_ONCE(cred->user_ns->user_keyring_register);
 	key_ref_t session_keyring_r;
-	char buf[20];
+	char buf[USER_KEYRING_NAME_SIZE];
 
 	struct keyring_search_context ctx = {
 		.index_key.type		= &key_type_keyring,
@@ -201,9 +219,9 @@ struct key *get_user_session_keyring_rcu(const struct cred *cred)
 	if (!reg_keyring)
 		return NULL;
 
-	ctx.index_key.desc_len = snprintf(buf, sizeof(buf), "_uid_ses.%u",
-					  from_kuid(cred->user_ns,
-						    cred->user->uid));
+	ctx.index_key.desc_len = user_keyring_name(buf, "_uid_ses.",
+						   cred->user_ns,
+						   cred->user->uid);
 
 	session_keyring_r = keyring_search_rcu(make_key_ref(reg_keyring, true),
 					       &ctx);
security/keys/request_key.c +9 -3
index fa2bb9f2f..48067bb73 100644
@@ -122,7 +122,7 @@ static int call_sbin_request_key(struct key *authkey, void *aux)
 	const struct cred *cred = current_cred();
 	key_serial_t prkey, sskey;
 	struct key *key = rka->target_key, *keyring, *session, *user_session;
-	char *argv[9], *envp[3], uid_str[12], gid_str[12];
+	char *argv[9], *envp[3], uid_str[KID_STR_LEN], gid_str[KID_STR_LEN];
 	char key_str[12], keyring_str[3][12];
 	char desc[20];
 	int ret, i;
@@ -152,8 +152,14 @@ static int call_sbin_request_key(struct key *authkey, void *aux)
 		goto error_link;
 
 	/* record the UID and GID */
-	sprintf(uid_str, "%d", from_kuid(&init_user_ns, cred->fsuid));
-	sprintf(gid_str, "%d", from_kgid(&init_user_ns, cred->fsgid));
+	if (uid_is_legacy(cred->fsuid))
+		sprintf(uid_str, "%d", from_kuid(&init_user_ns, cred->fsuid));
+	else
+		kuid_str(cred->fsuid, uid_str);
+	if (gid_is_legacy(cred->fsgid))
+		sprintf(gid_str, "%d", from_kgid(&init_user_ns, cred->fsgid));
+	else
+		kgid_str(cred->fsgid, gid_str);
 
 	/* we say which key is under construction */
 	sprintf(key_str, "%d", key->serial);

From 245f472248d9b190f4f071cf273b3b99513f0188 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 09:44:28 +0200
Subject: [PATCH 13/43] ublk: refuse unprivileged devices to UUID and GUID
users

The owner of an unprivileged ublk device is recorded in 32 bit fields of struct ublksrv_ctrl_dev_info, and only the owner may open the disk. A UUID or GUID user comes out as -1 there, like every other one, so they could open each other's devices.

Fail the creation of unprivileged devices by such users with -EOVERFLOW, and never let such a user pass the owner check.

Assisted-by Claude:claude-opus-5-5
---
 drivers/block/ublk_drv.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/block/ublk_drv.c +12 -5
index d879e8492..6db109433 100644
@@ -1313,7 +1313,12 @@ static void ublk_free_disk(struct gendisk *disk)
 	ublk_put_device(ub);
 }
 
-static void ublk_store_owner_uid_gid(unsigned int *owner_uid,
+/*
+ * The owner of an unprivileged device is kept in 32 bits: -EOVERFLOW for
+ * a UUID or GUID user or group, which all would come out as -1 and so
+ * pass for each other.
+ */
+static int ublk_store_owner_uid_gid(unsigned int *owner_uid,
 		unsigned int *owner_gid)
 {
 	kuid_t uid;
@@ -1323,6 +1328,7 @@ static void ublk_store_owner_uid_gid(unsigned int *owner_uid,
 
 	*owner_uid = from_kuid(&init_user_ns, uid);
 	*owner_gid = from_kgid(&init_user_ns, gid);
+	return uid_is_legacy(uid) && gid_is_legacy(gid) ? 0 : -EOVERFLOW;
 }
 
 static int ublk_open(struct gendisk *disk, blk_mode_t mode)
@@ -1344,9 +1350,8 @@ static int ublk_open(struct gendisk *disk, blk_mode_t mode)
 	if (ub->dev_info.flags & UBLK_F_UNPRIVILEGED_DEV) {
 		unsigned int curr_uid, curr_gid;
 
-		ublk_store_owner_uid_gid(&curr_uid, &curr_gid);
-
-		if (curr_uid != ub->dev_info.owner_uid || curr_gid !=
+		if (ublk_store_owner_uid_gid(&curr_uid, &curr_gid) ||
+		    curr_uid != ub->dev_info.owner_uid || curr_gid !=
 				ub->dev_info.owner_gid)
 			return -EPERM;
 	}
@@ -4740,7 +4745,9 @@ static int ublk_ctrl_add_dev(const struct ublksrv_ctrl_cmd *header)
 		return -EINVAL;
 
 	/* the created device is always owned by current user */
-	ublk_store_owner_uid_gid(&info.owner_uid, &info.owner_gid);
+	if (ublk_store_owner_uid_gid(&info.owner_uid, &info.owner_gid) &&
+	    (info.flags & UBLK_F_UNPRIVILEGED_DEV))
+		return -EOVERFLOW;
 
 	if (header->dev_id != info.dev_id) {
 		pr_warn("%s: dev id not match %u %u\n",

From 4bed0c3c6d7f1a88aa2245e56540bff41546879e Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 09:44:28 +0200
Subject: [PATCH 14/43] nfsd: don't hand out uid 0 for read layouts of
UUID-owned files

Read-only flexfile layout segments use the owner's uid plus one, so the client gets no write access on the data server. For a UUID or GUID owner from_kuid() is -1 and the "plus one" makes it 0, root. Use the overflow uid for them instead.

Assisted-by Claude:claude-opus-5-5
---
 fs/nfsd/flexfilelayout.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/nfsd/flexfilelayout.c +5 -1
index 6d531285a..f459d2c1c 100644
@@ -51,7 +51,11 @@ nfsd4_ff_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode,
 
 	/* Do not allow a IOMODE_READ segment to have write pemissions */
 	if (seg->iomode == IOMODE_READ) {
-		u = from_kuid(&init_user_ns, inode->i_uid) + 1;
+		/* any uid but the owner's; a UUID or GUID has no "+ 1" */
+		if (uid_is_legacy(inode->i_uid))
+			u = from_kuid(&init_user_ns, inode->i_uid) + 1;
+		else
+			u = overflowuid;
 		fl->uid = make_kuid(&init_user_ns, u);
 	} else
 		fl->uid = inode->i_uid;

From 4f4ba81d63301a105956deac69ebb4f20915fe9c Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 09:44:28 +0200
Subject: [PATCH 15/43] SUNRPC: name UUID and GUID users to gssd as uid_r=

gssd learns the user of an upcall as a 32 bit uid. UUID and GUID users would all reach it as the overflow uid and share its credentials.

In the text (v1) upcall, name such a user as uid_r= with the text form of the id instead of uid=. gssd versions that don't know uid_r= find no uid= and refuse the upcall, so nobody ends up with the overflow uid's credentials; where gssd's user namespace can't see the user, the upcall names no user at all and fails the same way.

A downcall for such a user starts with uid -1, which is never valid, followed by the user as __kernel_uid_r_t; downcalls for classic uids are unchanged.

The binary (v0) upcall has room for a 32 bit uid only: fail it with -EACCES for UUID and GUID users.

Assisted-by Claude:claude-opus-5-5
---
 net/sunrpc/auth_gss/auth_gss.c | 44 +++++++++++++++++++++++++++++++---
 1 file changed, 41 insertions(+), 3 deletions(-)
net/sunrpc/auth_gss/auth_gss.c +41 -3

70 lines not on this page · raw message

From 4753274b6b481c959cdfc8c1c1ed87926f3e918f Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 09:44:28 +0200
Subject: [PATCH 16/43] ecryptfs: hash daemons by kuid_hash()

The daemon hash uses from_kuid(&init_user_ns, euid), which puts all UUID and GUID users into one bucket. Lookups compare the kuid, so this only costs time; use kuid_hash().

Assisted-by Claude:claude-opus-5-5
---
 fs/ecryptfs/messaging.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ecryptfs/messaging.c +1 -1
index 73c7b8215..4e2524f78 100644
@@ -21,7 +21,7 @@ static struct hlist_head *ecryptfs_daemon_hash;
 DEFINE_MUTEX(ecryptfs_daemon_hash_mux);
 static int ecryptfs_hash_bits;
 #define ecryptfs_current_euid_hash(uid) \
-	hash_long((unsigned long)from_kuid(&init_user_ns, current_euid()), ecryptfs_hash_bits)
+	hash_long((unsigned long)kuid_hash(current_euid()), ecryptfs_hash_bits)
 
 static u32 ecryptfs_msg_counter;
 static struct ecryptfs_msg_ctx *ecryptfs_msg_ctx_arr;

From 3ffa1a2f4681e8c60b29af384f1b6b8933862ca0 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 06:01:52 +0200
Subject: [PATCH 17/43] quota: don't account UUID and GUID owners

Quota files and the quotactl interface use 32 bit ids. dqget() would hash and store a UUID or GUID owner as -1, so all of them would share one dquot, written out as id 4294967295.

Treat such ids like quota being off for them: dqget() returns -ESRCH, which its callers already handle by not charging the inode. An inode given to such an owner stays charged to the previous one.

Assisted-by Claude:claude-opus-5-5
---
 fs/quota/dquot.c      |  3 +++
 include/linux/quota.h | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)
fs/quota/dquot.c +3 -0
index 9850de395..363335461 100644
@@ -954,6 +954,9 @@ struct dquot *dqget(struct super_block *sb, struct kqid qid)
 
 	if (!qid_has_mapping(sb->s_user_ns, qid))
 		return ERR_PTR(-EINVAL);
+	/* Quota files hold 32 bit ids: like quota off for UUIDs and GUIDs */
+	if (!qid_is_legacy(qid))
+		return ERR_PTR(-ESRCH);
 
         if (!sb_has_quota_active(sb, qid.type))
 		return ERR_PTR(-ESRCH);
include/linux/quota.h +18 -0
index 89a0d83dd..00685209f 100644
@@ -80,6 +80,24 @@ extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
 extern bool qid_valid(struct kqid qid);
 
+/**
+ *	qid_is_legacy - Report if a kqid fits the 32 bit ids of quota files
+ *	@qid: The kernel internal quota identifier to test.
+ *
+ *	UUID and GUID owners don't, and are not subject to quotas.
+ */
+static inline bool qid_is_legacy(struct kqid qid)
+{
+	switch (qid.type) {
+	case USRQUOTA:
+		return uid_is_legacy(qid.uid);
+	case GRPQUOTA:
+		return gid_is_legacy(qid.gid);
+	default:
+		return true;
+	}
+}
+
 /**
  *	make_kqid - Map a user-namespace, type, qid tuple into a kqid.
  *	@from: User namespace that the qid is in

From 11b9761ef9b0089c4f6244221b91ea63786fd22d Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 05:46:04 +0200
Subject: [PATCH 18/43] fs: keep UUID and GUID owners off filesystems that
can't store them

Filesystems write inode owners with i_uid_read()/i_gid_read(), which turn a UUID or GUID into -1. Add SB_I_UID_R for filesystems that can store such owners, and refuse them elsewhere with -EOVERFLOW, the error already used for ids without a mapping in the filesystem's namespace:

- notify_change() refuses ATTR_UID/ATTR_GID with such an id,
- fsuidgid_has_mapping() is false for a caller whose fsuid or fsgid is one, so may_create() and friends refuse to create inodes owned by it.

No filesystem sets the flag yet.

Assisted-by Claude:claude-opus-5-5
---
 fs/attr.c                      |  7 +++++++
 include/linux/fs.h             | 29 +++++++++++++++++++++++++----
 include/linux/fs/super_types.h |  1 +
 3 files changed, 33 insertions(+), 4 deletions(-)
fs/attr.c +7 -0
index 71888ac90..09d51b1a3 100644
@@ -526,6 +526,13 @@ int notify_change(struct mnt_idmap *idmap, struct dentry *dentry,
 	    !vfsgid_has_fsmapping(idmap, inode->i_sb->s_user_ns,
 				  attr->ia_vfsgid))
 		return -EOVERFLOW;
+	/* and that the filesystem can store a UUID or GUID owner */
+	if (ia_valid & ATTR_UID &&
+	    !sb_can_own_kuid(inode->i_sb, vfsuid_into_kuid(attr->ia_vfsuid)))
+		return -EOVERFLOW;
+	if (ia_valid & ATTR_GID &&
+	    !sb_can_own_kgid(inode->i_sb, vfsgid_into_kgid(attr->ia_vfsgid)))
+		return -EOVERFLOW;
 
 	/* Don't allow modifications of files with invalid uids or
 	 * gids unless those uids & gids are being made valid.
include/linux/fs.h +25 -4
index 09de7bf6f..3778f48dd 100644
@@ -1563,14 +1563,35 @@ static inline void inode_fsgid_set(struct inode *inode,
 	inode->i_gid = mapped_fsgid(idmap, i_user_ns(inode));
 }
 
+/**
+ * sb_can_own_kuid() - check whether a filesystem can store an owner
+ * @sb: the superblock
+ * @kuid: the owner
+ *
+ * Classic ids fit any filesystem; UUIDs and GUIDs only those that set
+ * SB_I_UID_R. Elsewhere i_uid_read() would turn them into -1.
+ *
+ * Return: true if @sb can store @kuid.
+ */
+static inline bool sb_can_own_kuid(const struct super_block *sb, kuid_t kuid)
+{
+	return uid_is_legacy(kuid) || (sb->s_iflags & SB_I_UID_R);
+}
+
+static inline bool sb_can_own_kgid(const struct super_block *sb, kgid_t kgid)
+{
+	return gid_is_legacy(kgid) || (sb->s_iflags & SB_I_UID_R);
+}
+
 /**
  * fsuidgid_has_mapping() - check whether caller's fsuid/fsgid is mapped
  * @sb: the superblock we want a mapping in
  * @idmap: idmap of the relevant mount
  *
  * Check whether the caller's fsuid and fsgid have a valid mapping in the
- * s_user_ns of the superblock @sb. If the caller is on an idmapped mount map
- * the caller's fsuid and fsgid according to the @idmap first.
+ * s_user_ns of the superblock @sb, and whether @sb can store them as owner
+ * of a new inode. If the caller is on an idmapped mount map the caller's
+ * fsuid and fsgid according to the @idmap first.
  *
  * Return: true if fsuid and fsgid is mapped, false if not.
  */
@@ -1582,10 +1603,10 @@ static inline bool fsuidgid_has_mapping(struct super_block *sb,
 	kgid_t kgid;
 
 	kuid = mapped_fsuid(idmap, fs_userns);
-	if (!uid_valid(kuid))
+	if (!uid_valid(kuid) || !sb_can_own_kuid(sb, kuid))
 		return false;
 	kgid = mapped_fsgid(idmap, fs_userns);
-	if (!gid_valid(kgid))
+	if (!gid_valid(kgid) || !sb_can_own_kgid(sb, kgid))
 		return false;
 	return kuid_has_mapping(fs_userns, kuid) &&
 	       kgid_has_mapping(fs_userns, kgid);
include/linux/fs/super_types.h +1 -0
index 68747182a..8ba93c4b8 100644
@@ -348,5 +348,6 @@ struct super_block {
 #define SB_I_NOIDMAP	0x00002000	/* No idmapped mounts on this superblock */
 #define SB_I_ALLOW_HSM	0x00004000	/* Allow HSM events on this superblock */
 #define SB_I_NO_DATA_INTEGRITY	0x00008000 /* fs cannot guarantee data persistence on sync */
+#define SB_I_UID_R	0x00010000	/* fs stores UUID and GUID owners, not just classic ids */
 
 #endif /* _LINUX_FS_SUPER_TYPES_H */

From cf69bedf0e5b28065152ee8d73226ccf731e829e Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 05:46:04 +0200
Subject: [PATCH 19/43] cred: add the *_r variants of the get/set*id() system
calls

Add getuid_r(), geteuid_r(), getgid_r(), getegid_r(), setuid_r(), setgid_r(), setreuid_r(), setregid_r(), setresuid_r(), getresuid_r(), setresgid_r(), getresgid_r(), setfsuid_r() and setfsgid_r(). They work like the classic calls but take and return pointers to __kernel_uid_r_t, so a process can be a UUID or GUID user and group. The classic calls see such ids as the overflow id, like the 16 bit calls see ids above 65535.

To share the logic, the classic implementations are split into a part converting the arguments and a do_*() part working on kuid_t/kgid_t, in which an invalid id means "unchanged" -- what -1 converts to. A NULL pointer, UID_R_NONE or a classic -1 mean "unchanged" in the new calls as well.

UUIDs and GUIDs have no mapping outside the initial user namespace, so only CAP_SETUID/CAP_SETGID there can switch to one.

setfsuid_r() and setfsgid_r() differ from the classic calls in one
respect: they return -EPERM when the change is not allowed instead of failing silently, and hand the old id back through a second argument.

The system call numbers are assigned in a later patch.

Assisted-by Claude:claude-opus-5-5
---
 include/linux/syscalls.h |  27 +++
 kernel/sys.c             | 472 +++++++++++++++++++++++++++++----------
 kernel/sys_ni.c          |  10 +
 3 files changed, 385 insertions(+), 124 deletions(-)
include/linux/syscalls.h +27 -0
index 874d9067a..903cc6fa0 100644
@@ -17,6 +17,7 @@ struct iocb;
 struct io_event;
 struct iovec;
 struct __kernel_old_itimerval;
+struct __kernel_uid_r;
 struct kexec_segment;
 struct linux_dirent;
 struct linux_dirent64;
@@ -966,6 +967,32 @@ asmlinkage long sys_statx(int dfd, const char __user *path, unsigned flags,
 asmlinkage long sys_rseq(struct rseq __user *rseq, uint32_t rseq_len,
 			 int flags, uint32_t sig);
 asmlinkage long sys_rseq_slice_yield(void);
+asmlinkage long sys_getuid_r(struct __kernel_uid_r __user *uid);
+asmlinkage long sys_geteuid_r(struct __kernel_uid_r __user *uid);
+asmlinkage long sys_getgid_r(struct __kernel_uid_r __user *gid);
+asmlinkage long sys_getegid_r(struct __kernel_uid_r __user *gid);
+asmlinkage long sys_setuid_r(const struct __kernel_uid_r __user *uid);
+asmlinkage long sys_setgid_r(const struct __kernel_uid_r __user *gid);
+asmlinkage long sys_setreuid_r(const struct __kernel_uid_r __user *ruid,
+			       const struct __kernel_uid_r __user *euid);
+asmlinkage long sys_setregid_r(const struct __kernel_uid_r __user *rgid,
+			       const struct __kernel_uid_r __user *egid);
+asmlinkage long sys_setresuid_r(const struct __kernel_uid_r __user *ruid,
+				const struct __kernel_uid_r __user *euid,
+				const struct __kernel_uid_r __user *suid);
+asmlinkage long sys_getresuid_r(struct __kernel_uid_r __user *ruid,
+				struct __kernel_uid_r __user *euid,
+				struct __kernel_uid_r __user *suid);
+asmlinkage long sys_setresgid_r(const struct __kernel_uid_r __user *rgid,
+				const struct __kernel_uid_r __user *egid,
+				const struct __kernel_uid_r __user *sgid);
+asmlinkage long sys_getresgid_r(struct __kernel_uid_r __user *rgid,
+				struct __kernel_uid_r __user *egid,
+				struct __kernel_uid_r __user *sgid);
+asmlinkage long sys_setfsuid_r(const struct __kernel_uid_r __user *uid,
+			       struct __kernel_uid_r __user *old_uid);
+asmlinkage long sys_setfsgid_r(const struct __kernel_uid_r __user *gid,
+			       struct __kernel_uid_r __user *old_gid);
 asmlinkage long sys_open_tree(int dfd, const char __user *path, unsigned flags);
 asmlinkage long sys_open_tree_attr(int dfd, const char __user *path,
 				   unsigned flags,
kernel/sys.c +348 -124

701 lines not on this page · raw message

kernel/sys_ni.c +10 -0
index add3032da..090996af1 100644
@@ -103,6 +103,16 @@ COND_SYSCALL(setfsuid);
 COND_SYSCALL(setfsgid);
 COND_SYSCALL(setgroups);
 COND_SYSCALL(getgroups);
+COND_SYSCALL(setregid_r);
+COND_SYSCALL(setgid_r);
+COND_SYSCALL(setreuid_r);
+COND_SYSCALL(setuid_r);
+COND_SYSCALL(setresuid_r);
+COND_SYSCALL(getresuid_r);
+COND_SYSCALL(setresgid_r);
+COND_SYSCALL(getresgid_r);
+COND_SYSCALL(setfsuid_r);
+COND_SYSCALL(setfsgid_r);
 COND_SYSCALL(mq_open);
 COND_SYSCALL_COMPAT(mq_open);
 COND_SYSCALL(mq_unlink);

From c65fc7ba019e7c8e55cb4f3cc5f8f30a3e3ba6d5 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 05:46:05 +0200
Subject: [PATCH 20/43] groups: add getgroups_r() and setgroups_r()

Supplementary groups as arrays of __kernel_gid_r_t, so they can include UUID and GUID groups. Unlike the set*id_r() calls, "no id" is not accepted in the list. getgroups() reports such groups as the overflow gid.

Assisted-by Claude:claude-opus-5-5
---
 include/linux/syscalls.h |  4 ++
 kernel/groups.c          | 79 +++++++++++++++++++++++++++++++++++++++-
 kernel/sys_ni.c          |  2 +
 3 files changed, 83 insertions(+), 2 deletions(-)
include/linux/syscalls.h +4 -0
index 903cc6fa0..8e7b4e927 100644
@@ -993,6 +993,10 @@ asmlinkage long sys_setfsuid_r(const struct __kernel_uid_r __user *uid,
 			       struct __kernel_uid_r __user *old_uid);
 asmlinkage long sys_setfsgid_r(const struct __kernel_uid_r __user *gid,
 			       struct __kernel_uid_r __user *old_gid);
+asmlinkage long sys_getgroups_r(int gidsetsize,
+				struct __kernel_uid_r __user *grouplist);
+asmlinkage long sys_setgroups_r(int gidsetsize,
+				const struct __kernel_uid_r __user *grouplist);
 asmlinkage long sys_open_tree(int dfd, const char __user *path, unsigned flags);
 asmlinkage long sys_open_tree_attr(int dfd, const char __user *path,
 				   unsigned flags,
kernel/groups.c +77 -2

103 lines not on this page · raw message

kernel/sys_ni.c +2 -0
index 090996af1..555c94d58 100644
@@ -113,6 +113,8 @@ COND_SYSCALL(setresgid_r);
 COND_SYSCALL(getresgid_r);
 COND_SYSCALL(setfsuid_r);
 COND_SYSCALL(setfsgid_r);
+COND_SYSCALL(setgroups_r);
+COND_SYSCALL(getgroups_r);
 COND_SYSCALL(mq_open);
 COND_SYSCALL_COMPAT(mq_open);
 COND_SYSCALL(mq_unlink);

From 44dd43a5e185f3e17a1a41b91783a80bfafd7c2f Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 05:46:05 +0200
Subject: [PATCH 21/43] fs: add chown_r(), lchown_r(), fchown_r() and
fchownat_r()

The chown family with __kernel_uid_r_t owner and group, so files can be given UUID and GUID owners on filesystems that support them (SB_I_UID_R); others refuse with -EOVERFLOW. NULL pointers, UID_R_NONE and the classic -1 leave the owner or group unchanged.

The classic calls and the new ones share the lookup and setattr code, which now works on a struct chown_ids. The classic calls still report a malformed id only once the file is found, as before.

Assisted-by Claude:claude-opus-5-5
---
 fs/open.c                | 144 +++++++++++++++++++++++++++++++++++----
 include/linux/syscalls.h |  13 ++++
 2 files changed, 145 insertions(+), 12 deletions(-)
fs/open.c +132 -12

204 lines not on this page · raw message

include/linux/syscalls.h +13 -0
index 8e7b4e927..38d9cfa05 100644
@@ -997,6 +997,19 @@ asmlinkage long sys_getgroups_r(int gidsetsize,
 				struct __kernel_uid_r __user *grouplist);
 asmlinkage long sys_setgroups_r(int gidsetsize,
 				const struct __kernel_uid_r __user *grouplist);
+asmlinkage long sys_chown_r(const char __user *filename,
+			    const struct __kernel_uid_r __user *user,
+			    const struct __kernel_uid_r __user *group);
+asmlinkage long sys_lchown_r(const char __user *filename,
+			     const struct __kernel_uid_r __user *user,
+			     const struct __kernel_uid_r __user *group);
+asmlinkage long sys_fchown_r(unsigned int fd,
+			     const struct __kernel_uid_r __user *user,
+			     const struct __kernel_uid_r __user *group);
+asmlinkage long sys_fchownat_r(int dfd, const char __user *filename,
+			       const struct __kernel_uid_r __user *user,
+			       const struct __kernel_uid_r __user *group,
+			       int flag);
 asmlinkage long sys_open_tree(int dfd, const char __user *path, unsigned flags);
 asmlinkage long sys_open_tree_attr(int dfd, const char __user *path,
 				   unsigned flags,

From 1c5c7548a3a38582ad7e9127fa697189523cb4b3 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 05:46:05 +0200
Subject: [PATCH 22/43] arch: wire up the *_r uid and gid system calls

Assign 472-491 on all architectures (582-601 on alpha) to getuid_r, geteuid_r, getgid_r, getegid_r, setuid_r, setgid_r, setreuid_r, setregid_r, setresuid_r, getresuid_r, setresgid_r, getresgid_r, setfsuid_r, setfsgid_r, getgroups_r, setgroups_r, chown_r, lchown_r, fchown_r and fchownat_r.

__kernel_uid_r_t has the same layout on all ABIs, so the compat ABIs use the native entry points.

Assisted-by Claude:claude-opus-5-5
---
 arch/alpha/kernel/syscalls/syscall.tbl      | 20 ++++++++++
 arch/arm/tools/syscall.tbl                  | 20 ++++++++++
 arch/arm64/tools/syscall_32.tbl             | 20 ++++++++++
 arch/m68k/kernel/syscalls/syscall.tbl       | 20 ++++++++++
 arch/microblaze/kernel/syscalls/syscall.tbl | 20 ++++++++++
 arch/mips/kernel/syscalls/syscall_n32.tbl   | 20 ++++++++++
 arch/mips/kernel/syscalls/syscall_n64.tbl   | 20 ++++++++++
 arch/mips/kernel/syscalls/syscall_o32.tbl   | 20 ++++++++++
 arch/parisc/kernel/syscalls/syscall.tbl     | 20 ++++++++++
 arch/powerpc/kernel/syscalls/syscall.tbl    | 20 ++++++++++
 arch/s390/kernel/syscalls/syscall.tbl       | 20 ++++++++++
 arch/sh/kernel/syscalls/syscall.tbl         | 20 ++++++++++
 arch/sparc/kernel/syscalls/syscall.tbl      | 20 ++++++++++
 arch/x86/entry/syscalls/syscall_32.tbl      | 20 ++++++++++
 arch/x86/entry/syscalls/syscall_64.tbl      | 20 ++++++++++
 arch/xtensa/kernel/syscalls/syscall.tbl     | 20 ++++++++++
 include/uapi/asm-generic/unistd.h           | 42 ++++++++++++++++++++-
 scripts/syscall.tbl                         | 20 ++++++++++
 18 files changed, 381 insertions(+), 1 deletion(-)
arch/alpha/kernel/syscalls/syscall.tbl +20 -0
index f31b7afff..272281891 100644
@@ -511,3 +511,23 @@
 579	common	file_setattr			sys_file_setattr
 580	common	listns				sys_listns
 581	common	rseq_slice_yield		sys_rseq_slice_yield
+582	common	getuid_r		sys_getuid_r
+583	common	geteuid_r		sys_geteuid_r
+584	common	getgid_r		sys_getgid_r
+585	common	getegid_r		sys_getegid_r
+586	common	setuid_r		sys_setuid_r
+587	common	setgid_r		sys_setgid_r
+588	common	setreuid_r		sys_setreuid_r
+589	common	setregid_r		sys_setregid_r
+590	common	setresuid_r		sys_setresuid_r
+591	common	getresuid_r		sys_getresuid_r
+592	common	setresgid_r		sys_setresgid_r
+593	common	getresgid_r		sys_getresgid_r
+594	common	setfsuid_r		sys_setfsuid_r
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

arch/arm/tools/syscall.tbl +20 -0
index 94351e22b..45273f44f 100644

Lines of this file are not shown. View the raw message.

arch/arm64/tools/syscall_32.tbl +20 -0
index 62d93d88e..2f2fac533 100644

Lines of this file are not shown. View the raw message.

arch/m68k/kernel/syscalls/syscall.tbl +20 -0
index 248934257..bcfd36931 100644

Lines of this file are not shown. View the raw message.

arch/microblaze/kernel/syscalls/syscall.tbl +20 -0
index 223d26303..915bc93ae 100644

Lines of this file are not shown. View the raw message.

arch/mips/kernel/syscalls/syscall_n32.tbl +20 -0
index 7430714e2..217333bb8 100644

Lines of this file are not shown. View the raw message.

arch/mips/kernel/syscalls/syscall_n64.tbl +20 -0
index 630aab9e5..32016b1eb 100644

Lines of this file are not shown. View the raw message.

arch/mips/kernel/syscalls/syscall_o32.tbl +20 -0
index 128653112..baba1c0e6 100644

Lines of this file are not shown. View the raw message.

arch/parisc/kernel/syscalls/syscall.tbl +20 -0
index c6331dad9..c21ae0689 100644

Lines of this file are not shown. View the raw message.

arch/powerpc/kernel/syscalls/syscall.tbl +20 -0
index 4fcc7c58a..29fcf6b29 100644

Lines of this file are not shown. View the raw message.

arch/s390/kernel/syscalls/syscall.tbl +20 -0
index 09a7ef04d..4199958e7 100644

Lines of this file are not shown. View the raw message.

arch/sh/kernel/syscalls/syscall.tbl +20 -0
index 70b315cbe..b5ed5b657 100644

Lines of this file are not shown. View the raw message.

arch/sparc/kernel/syscalls/syscall.tbl +20 -0
index 7e71bf7fc..07e143706 100644

Lines of this file are not shown. View the raw message.

arch/x86/entry/syscalls/syscall_32.tbl +20 -0
index f832ebd2d..f3890beb0 100644

Lines of this file are not shown. View the raw message.

arch/x86/entry/syscalls/syscall_64.tbl +20 -0
index 524155d65..86a0fc606 100644

Lines of this file are not shown. View the raw message.

arch/xtensa/kernel/syscalls/syscall.tbl +20 -0
index a9bca4e48..5cdc5d0c3 100644

Lines of this file are not shown. View the raw message.

include/uapi/asm-generic/unistd.h +41 -1

42 lines not on this page · raw message

scripts/syscall.tbl +20 -0
index 7a42b32b6..62d8543c1 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

From 4e4523d671c6ea6eafe7b4dd31e0f9ff468b3381 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 06:01:52 +0200
Subject: [PATCH 23/43] statx: report UUID and GUID owners

Add stx_uid_r and stx_gid_r, the owner and group as __kernel_uid_r_t, taking 40 of the 64 spare bytes at the end of struct statx, and STATX_UID_R and STATX_GID_R for them. Every filesystem provides them, from the kstat the VFS has anyway. stx_uid and stx_gid keep showing a UUID or GUID as the overflow id.

struct statx is designed to be extended this way, so there is no new system call: statx() with the new mask bits is the *_r variant.

Assisted-by Claude:claude-opus-5-5
---
 fs/stat.c                 | 24 +++++++++++++++++++++++-
 include/uapi/linux/stat.h | 10 +++++++++-
 2 files changed, 32 insertions(+), 2 deletions(-)
fs/stat.c +23 -1
index c461c3054..993ca4907 100644

Lines of this file are not shown. View the raw message.

include/uapi/linux/stat.h +9 -1
index 1686861aa..689757d8a 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

From 29109d2223e9f7d212f0523442bd187a730b9bc4 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 06:01:52 +0200
Subject: [PATCH 24/43] shmem, ramfs: allow UUID and GUID owners

Both keep inode owners in memory only, so they can hold any kuid_t. Set SB_I_UID_R. Quotas of tmpfs don't account such owners.

Assisted-by Claude:claude-opus-5-5
---
 fs/ramfs/inode.c | 1 +
 mm/shmem.c       | 2 ++
 2 files changed, 3 insertions(+)
fs/ramfs/inode.c +1 -0
index 3987639ed..604349dbd 100644

Lines of this file are not shown. View the raw message.

mm/shmem.c +2 -0
index cfb546785..f6c60d7d3 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

From 9e46d0c433624ac3aa474a2f4b9e12dbe186aafa Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 06:14:40 +0200
Subject: [PATCH 25/43] uidgid: parse and print ids in their text form

Add helpers for interfaces that pass ids as text:

- make_kuid_str()/make_kgid_str() parse what kuid_str() writes: a decimal number, a UUID, or a GUID in braces,
- kuid_str_munged()/kgid_str_munged() write an id as seen from a user namespace, the overflow id if it has no mapping there,
- kuid_str_signed()/kgid_str_signed() write a legacy id as a signed number, for output that used "%d",
- KUID_STR() and friends wrap them as expressions with a buffer of the enclosing block, so that printf-like calls can replace "%u", from_kuid(&init_user_ns, uid) by "%s", KUID_STR(uid) and print legacy ids exactly as before.

Assisted-by Claude:claude-opus-5-5
---
 include/linux/uidgid.h |  19 ++++++
 kernel/uidgid_r.c      | 152 +++++++++++++++++++++++++++++++++++++++--
 2 files changed, 167 insertions(+), 4 deletions(-)
include/linux/uidgid.h +19 -0
index ac7786f76..03ece8a4c 100644

Lines of this file are not shown. View the raw message.

kernel/uidgid_r.c +148 -4

152 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

From 94accd00741ae112870e5fa3cb2130abe7cf8dd3 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 06:14:41 +0200
Subject: [PATCH 26/43] proc: show UUID and GUID ids in status, accept them for
loginuid

/proc/<pid>/status shows ids without a 32 bit form as the overflow id. Add Uid_r:, Gid_r: and Groups_r: lines with the same ids as text (kuid_str()): a number, a UUID, or a GUID in braces, munged as usual for ids the reader's user namespace can't see.

/proc/<pid>/loginuid accepts the text form of a UUID or GUID, so login services can record such users, and shows such a loginuid as text. Classic loginuids read and write as before, including 4294967295 for "unset".

Assisted-by Claude:claude-opus-5-5
---
 fs/proc/array.c | 17 ++++++++++++++++-
 fs/proc/base.c  | 38 ++++++++++++++++++++++++--------------
 2 files changed, 40 insertions(+), 15 deletions(-)
fs/proc/array.c +16 -1
index 479ea8cb4..ff61ab1bc 100644

Lines of this file are not shown. View the raw message.

fs/proc/base.c +24 -14
index 780f81259..b7f9fc83e 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

From 729596c48d80aea72214439e0dc2d53acd6e42f3 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 06:14:42 +0200
Subject: [PATCH 27/43] audit: log UUID and GUID ids in full

Audit records print ids with from_kuid(&init_user_ns, ...), which gives -1 for a UUID or GUID. 4294967295 is what audit uses for "unset", so a UUID user's actions would be logged as if there were no login user.

Print all ids in audit records with KUID_STR()/KGID_STR(): classic ids come out exactly as before (signed where the format was "%d"), UUIDs and GUIDs in their text form. The binary AUDIT_SIGNAL_INFO reply keeps its 32 bit field.

Assisted-by Claude:claude-opus-5-5
---
 drivers/tty/tty_audit.c              |  7 ++--
 kernel/audit.c                       | 50 ++++++++++++-------------
 kernel/auditsc.c                     | 55 ++++++++++++++--------------
 net/core/dev.c                       |  8 ++--
 net/netlabel/netlabel_user.c         |  4 +-
 security/apparmor/file.c             |  8 ++--
 security/integrity/integrity_audit.c |  6 +--
 security/ipe/audit.c                 | 12 +++---
 security/selinux/selinuxfs.c         |  8 ++--
 security/selinux/ss/services.c       |  4 +-
 10 files changed, 78 insertions(+), 84 deletions(-)
drivers/tty/tty_audit.c +3 -4
index d014af6ab..03ad4961b 100644

Lines of this file are not shown. View the raw message.

kernel/audit.c +23 -27

50 lines not on this page · raw message

kernel/auditsc.c +27 -28

55 lines not on this page · raw message

net/core/dev.c +4 -4
index 1a06976e1..394866cf3 100644

Lines of this file are not shown. View the raw message.

net/netlabel/netlabel_user.c +2 -2
index 0da652844..31ac4a0fc 100644

Lines of this file are not shown. View the raw message.

security/apparmor/file.c +4 -4
index c9d55fe10..b0afd5289 100644

Lines of this file are not shown. View the raw message.

security/integrity/integrity_audit.c +3 -3
index d8d9e5ff1..cc4959182 100644

Lines of this file are not shown. View the raw message.

security/ipe/audit.c +6 -6
index 93fb59fbd..ace64cf21 100644

Lines of this file are not shown. View the raw message.

security/selinux/selinuxfs.c +4 -4
index 5aaaf6941..813f69169 100644

Lines of this file are not shown. View the raw message.

security/selinux/ss/services.c +2 -2
index 7afce9754..dd0d397b4 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

From 3ebb2b61c7d33fdd8c6e8715ca3724f7ce09bffd Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 06:31:32 +0200
Subject: [PATCH 28/43] net: add SO_PEERCRED_R, SO_PEERGROUPS_R and
SCM_CREDENTIALS_R

Services authenticate AF_UNIX peers with SO_PEERCRED, SO_PEERGROUPS and SCM_CREDENTIALS, which carry 32 bit ids: a UUID or GUID user shows up as the overflow id there.

Add variants with __kernel_uid_r_t ids:

- SO_PEERCRED_R returns a struct __kernel_ucred_r of the peer,
- SO_PEERGROUPS_R its supplementary groups as __kernel_gid_r_t,
- SO_PASSCRED_R asks for SCM_CREDENTIALS_R messages, with a struct __kernel_ucred_r, next to or instead of SCM_CREDENTIALS (a separate option, so receivers sizing their control buffer for SCM_CREDENTIALS don't get truncated), and SCM_CREDENTIALS_R can be sent with the same privilege rules as SCM_CREDENTIALS.

The classic SCM_CREDENTIALS sending path now shares the checks and pid handling with it. Netlink keeps classic ids in its skbs, so it hands out the overflow id for UUID senders in SCM_CREDENTIALS_R too.

Assisted-by Claude:claude-opus-5-5
---
 arch/alpha/include/uapi/asm/socket.h  |  4 ++
 arch/mips/include/uapi/asm/socket.h   |  4 ++
 arch/parisc/include/uapi/asm/socket.h |  4 ++
 arch/sparc/include/uapi/asm/socket.h  |  4 ++
 include/linux/socket.h                |  1 +
 include/net/sock.h                    |  4 +-
 include/uapi/asm-generic/socket.h     |  4 ++
 include/uapi/linux/socket.h           |  9 +++
 net/core/scm.c                        | 94 ++++++++++++++++++---------
 net/core/sock.c                       | 84 ++++++++++++++++++++++++
 net/unix/af_unix.c                    |  3 +-
 11 files changed, 181 insertions(+), 34 deletions(-)
arch/alpha/include/uapi/asm/socket.h +4 -0
index 5ef57f88d..fa1ee54b6 100644

Lines of this file are not shown. View the raw message.

arch/mips/include/uapi/asm/socket.h +4 -0
index 72fb1b006..5c9e7ba73 100644

Lines of this file are not shown. View the raw message.

arch/parisc/include/uapi/asm/socket.h +4 -0
index c16ec36df..5a93cdbfa 100644

Lines of this file are not shown. View the raw message.

arch/sparc/include/uapi/asm/socket.h +4 -0
index 71befa109..3ca685533 100644

Lines of this file are not shown. View the raw message.

include/linux/socket.h +1 -0
index 2a8d7b14f..89484bc6d 100644

Lines of this file are not shown. View the raw message.

include/net/sock.h +3 -1
index 0986d9466..7055afcf0 100644

Lines of this file are not shown. View the raw message.

include/uapi/asm-generic/socket.h +4 -0
index 53b5a8c00..89c927eb0 100644

Lines of this file are not shown. View the raw message.

include/uapi/linux/socket.h +9 -0
index d3fcd3b5e..38d3cd814 100644

Lines of this file are not shown. View the raw message.

net/core/scm.c +62 -32

94 lines not on this page · raw message

net/core/sock.c +84 -0

84 lines not on this page · raw message

net/unix/af_unix.c +2 -1
index e7af9f870..8523158f7 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

From e4bac2399b74616af0e7c8572b0ac46ffec74db4 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 08:46:03 +0200
Subject: [PATCH 29/43] signal: report the sender's UUID or GUID uid in
si_uid_r

si_uid is 32 bits, so a signal from a UUID or GUID user names the overflow uid as its sender, and so do SIGCHLD and waitid() for such a child.

Add si_uid_r, the sender's uid as __kernel_uid_r_t, to siginfo_t. union __sifields has no room that all kinds of signals with si_uid share, so it lives at a fixed offset (96) in the padding of siginfo_t, the same in every layout and ABI, compat_siginfo included; kernel_siginfo grows to cover it. The kernel sets it wherever it sets si_uid, through siginfo_set_uid() and siginfo_set_kernel_uid(), maps it into the receiver's user namespace like si_uid, and it is UID_R_NONE where nobody set it. Signals queued from userspace carry what the sender put there, exactly like si_uid.

signalfd_siginfo gets ssi_uid_r from its padding, and waitid() (also through io_uring, which keeps its waitid_info in the async data now, as it no longer fits into the command) fills in si_uid_r.

Assisted-by Claude:claude-opus-5-5
---
 fs/signalfd.c                      |  3 ++
 include/linux/compat.h             |  6 ++++
 include/linux/ptrace.h             |  2 +-
 include/linux/signal.h             | 22 ++++++++++++++
 include/linux/signal_types.h       |  5 +++-
 include/uapi/asm-generic/siginfo.h | 17 +++++++++++
 include/uapi/linux/signalfd.h      |  4 ++-
 io_uring/waitid.c                  | 32 +++++++++++---------
 io_uring/waitid.h                  |  1 +
 ipc/mqueue.c                       |  4 +--
 kernel/exit.c                      | 18 ++++++++++--
 kernel/exit.h                      |  3 ++
 kernel/signal.c                    | 47 ++++++++++++++++++++----------
 13 files changed, 128 insertions(+), 36 deletions(-)
fs/signalfd.c +3 -0
index dff53745e..8bca9d7f0 100644

Lines of this file are not shown. View the raw message.

include/linux/compat.h +6 -0
index 8da0a15c9..4b8505900 100644

Lines of this file are not shown. View the raw message.

include/linux/ptrace.h +1 -1
index ef314f7a9..b213b7385 100644

Lines of this file are not shown. View the raw message.

include/linux/signal.h +22 -0
index f19816832..928e67e28 100644

Lines of this file are not shown. View the raw message.

include/linux/signal_types.h +4 -1
index caf4f7a59..eaf922e44 100644

Lines of this file are not shown. View the raw message.

include/uapi/asm-generic/siginfo.h +17 -0
index 5a1ca43b5..e8f32c942 100644

Lines of this file are not shown. View the raw message.

include/uapi/linux/signalfd.h +3 -1
index 83429a05b..471bafc53 100644

Lines of this file are not shown. View the raw message.

io_uring/waitid.c +19 -13
index 2b7560174..24f27b67d 100644

Lines of this file are not shown. View the raw message.

io_uring/waitid.h +1 -0
index d5544aaf3..60b744a0e 100644

Lines of this file are not shown. View the raw message.

ipc/mqueue.c +2 -2
index 4798b3759..261315ede 100644

Lines of this file are not shown. View the raw message.

kernel/exit.c +15 -3
index 27e5cf81e..885348cb9 100644

Lines of this file are not shown. View the raw message.

kernel/exit.h +3 -0
index 278faa26a..f24a6d691 100644

Lines of this file are not shown. View the raw message.

kernel/signal.c +32 -15

47 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

From 4f09f46d6e44650f8dba0cd827d8cc5ea98f6764 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 08:58:25 +0200
Subject: [PATCH 30/43] ipc: add IPC_STAT_R and IPC_SET_R

The ids of SysV message queues, semaphore sets and shared memory segments reach userspace in struct ipc64_perm, 32 bits each, so a UUID or GUID owner shows up as the overflow id and can't be set at all.

Rather than doubling every *id64_ds, add two commands shared by msgctl(), semctl() and shmctl() that work on a struct ipc_perm_r with key, mode, and uid, gid, cuid and cgid as __kernel_uid_r_t:

- IPC_STAT_R reads it, with the permission checks of IPC_STAT,
- IPC_SET_R sets uid, gid and mode like IPC_SET does (a message queue keeps its size).

The IPC_SET path now works on the kernel ids of a struct ipc_set_ids, which the classic command fills from its ipc64_perm. The audit record of IPC_SET has the new owner as a kuid as well and logs it like the other audit ids, in the initial user namespace.

Assisted-by Claude:claude-opus-5-5
---
 include/linux/audit.h    |   8 +--
 include/uapi/linux/ipc.h |  17 ++++++
 ipc/msg.c                |  40 ++++++++++----
 ipc/sem.c                |  31 ++++++++---
 ipc/shm.c                |  32 ++++++++---
 ipc/util.c               | 112 +++++++++++++++++++++++++++++++++++----
 ipc/util.h               |  23 +++++++-
 kernel/audit.h           |   4 +-
 kernel/auditsc.c         |   8 +--
 9 files changed, 226 insertions(+), 49 deletions(-)
include/linux/audit.h +4 -4
index 45abb3722..a769f04e4 100644

Lines of this file are not shown. View the raw message.

include/uapi/linux/ipc.h +17 -0
index 5995fc9d6..e927564fb 100644

Lines of this file are not shown. View the raw message.

ipc/msg.c +30 -10
index 62996b97f..a3f5287e5 100644

Lines of this file are not shown. View the raw message.

ipc/sem.c +23 -8
index 5ec41de7e..ab456991e 100644

Lines of this file are not shown. View the raw message.

ipc/shm.c +24 -8
index b3e8a58e1..dc50f800f 100644

Lines of this file are not shown. View the raw message.

ipc/util.c +101 -11

112 lines not on this page · raw message

ipc/util.h +21 -2
index a55d6cebe..b0d57f4e6 100644

Lines of this file are not shown. View the raw message.

kernel/audit.h +2 -2
index 92d5e723d..6195f1388 100644

Lines of this file are not shown. View the raw message.

kernel/auditsc.c +4 -4
index ed35bdfd7..518eb0b4e 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

From fc5d29ea3c2bb44d9b8c547d79d06eda12d3da29 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 09:18:36 +0200
Subject: [PATCH 31/43] ext4: add the uid_r feature for UUID and GUID owners

Add a read-only compatible feature, uid_r, that lets inodes have UUID and GUID owners and groups. The inode gains i_uid_r_type and i_gid_r_type (0: the classic i_uid/i_gid apply) and 16 bytes for each id after i_projid, which grows i_extra_isize from 32 to 68 bytes; only filesystems with the feature reserve the room in new inodes, others keep the old size.

For a UUID or GUID the classic fields hold 0xffffffff. Kernels without the feature may only mount read-only, and see such files as owned by an id nobody has.

With the feature the superblock gets SB_I_UID_R. Inodes from before it, or with in-inode xattrs in the way, are expanded when they get such an owner, as for project ids; -EOVERFLOW if that fails. The feature needs inodes of at least 196 bytes, so in practice 256.

Assisted-by Claude:claude-opus-5-5
---
 fs/ext4/ext4.h  |  26 ++++++++++-
 fs/ext4/inode.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++-
 fs/ext4/super.c |  16 ++++++-
 3 files changed, 152 insertions(+), 5 deletions(-)
fs/ext4/ext4.h +25 -1
index ed4241797..ff82a054a 100644

Lines of this file are not shown. View the raw message.

fs/ext4/inode.c +113 -2

115 lines not on this page · raw message

fs/ext4/super.c +14 -2
index 63de62a75..6e034672f 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

From 0cd5682e8a7b9ccab4a77308d7ef8e267a39e5a4 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sun, 11 Oct 2026 06:36:04 +0200
Subject: [PATCH 32/43] ext4: let uid_r be turned on while the filesystem is
mounted

SB_I_UID_R was only set when the filesystem was mounted, so after "tune2fs -O uid_r" on a mounted filesystem chown() to a UUID or GUID owner kept failing with -EOVERFLOW until it was unmounted and mounted again.

Take the feature up on remount, and accept it in EXT4_IOC_SET_TUNE_SB_PARAM, which then also raises s_want_extra_isize like tune2fs does and makes it usable at once. The ioctl also takes it when the feature bit is already on disk but not in use yet, which is the case after an older tune2fs wrote the superblock directly.

Once on, it stays on until the filesystem is unmounted: cached inodes may have such owners by then.

Assisted-by Claude:claude-opus-5-5
---
 fs/ext4/ext4.h  |  1 +
 fs/ext4/ioctl.c | 30 +++++++++++++++++++++++++++++-
 fs/ext4/super.c | 29 +++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 1 deletion(-)
fs/ext4/ext4.h +1 -0
index ff82a054a..fec9ed52f 100644

Lines of this file are not shown. View the raw message.

fs/ext4/ioctl.c +29 -1
index c8387e6a2..89bf1d36e 100644

Lines of this file are not shown. View the raw message.

fs/ext4/super.c +29 -0
index 6e034672f..5393a500f 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

From cebc5009d5b7bc5cbf7ac2cc2d4c31fa7745df40 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 09:42:13 +0200
Subject: [PATCH 33/43] posix_acl: support UUID and GUID entries

The ACL xattrs carry 32 bit ids, so ACL_USER and ACL_GROUP entries for UUID and GUID users and groups could neither be set nor shown.

Add version 3 of the xattr format, whose entries hold an id kind and 16 bytes of id. setxattr() takes version 2 and 3; getxattr() returns version 3 only if the ACL has such an entry the caller can see, so existing tools keep getting version 2 for everything else.

set_posix_acl() refuses UUID and GUID entries with -EOVERFLOW on filesystems without SB_I_UID_R, whose ACL formats can't store them.

Assisted-by Claude:claude-opus-5-5
---
 fs/posix_acl.c                       | 123 ++++++++++++++++++++++++++-
 include/linux/posix_acl_xattr.h      |  31 +++++++
 include/uapi/linux/posix_acl_xattr.h |  19 +++++
 3 files changed, 171 insertions(+), 2 deletions(-)
fs/posix_acl.c +121 -2

123 lines not on this page · raw message

include/linux/posix_acl_xattr.h +31 -0
index 9e1892525..307d543bc 100644

Lines of this file are not shown. View the raw message.

include/uapi/linux/posix_acl_xattr.h +19 -0
index 506380f0b..a44a51507 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

From 4730a39af742eb48cba608f533650fa7b745d075 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 09:42:13 +0200
Subject: [PATCH 34/43] ext4: store ACLs with UUID and GUID entries on uid_r
filesystems

ACLs whose ACL_USER or ACL_GROUP entries are UUIDs or GUIDs are written in a new on-disk format, EXT4_ACL_VERSION_R: the short entries stay as they are, the user and group entries carry an EXT4_ID_R_* kind and 16 bytes of id. Only such ACLs use it, and only uid_r filesystems can have them (set_posix_acl() refuses them elsewhere); all other ACLs keep EXT4_ACL_VERSION.

Assisted-by Claude:claude-opus-5-5
---
 fs/ext4/acl.c | 109 +++++++++++++++++++++++++++++++++++++++-----------
 fs/ext4/acl.h |  34 +++++++++++++---
 2 files changed, 115 insertions(+), 28 deletions(-)
fs/ext4/acl.c +86 -23

109 lines not on this page · raw message

fs/ext4/acl.h +29 -5
index 0c5a79c3b..48bc352ec 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

From 825df690080fcdde8137d756313edb34ca09fa64 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 09:46:09 +0200
Subject: [PATCH 35/43] Documentation: describe UUID and GUID user and group
ids

Describe __kernel_uid_r_t, the rules for UUID and GUID ids (overflow ids in classic interfaces, the initial user namespace only, filesystems with SB_I_UID_R), the *_r system calls, the extended interfaces (statx, socket credentials, siginfo, SysV IPC, keyctl, POSIX ACLs, procfs, audit) and the current limitations.

Assisted-by Claude:claude-opus-5-5
---
 Documentation/userspace-api/index.rst |   1 +
 Documentation/userspace-api/uid_r.rst | 169 ++++++++++++++++++++++++++
 2 files changed, 170 insertions(+)
 create mode 100644 Documentation/userspace-api/uid_r.rst
Documentation/userspace-api/index.rst +1 -0
index a68b1bea5..fcac7703f 100644

Lines of this file are not shown. View the raw message.

Documentation/userspace-api/uid_r.rst new file +169 -0

169 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

From 370df49a17ca0157a7ddae3161cdfb23c194b7a6 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 09:48:30 +0200
Subject: [PATCH 36/43] selftests: add tests for UUID and GUID ids

Test the *_r system calls (malformed ids, switching to a UUID user and back through the saved uid, GUID groups, sorted supplementary groups, chown_r() and statx() on tmpfs, creating files as a UUID fsuid, -EOVERFLOW on sysfs) and the extended interfaces: SO_PEERCRED_R, SO_PEERGROUPS_R, SCM_CREDENTIALS_R, ssi_uid_r, IPC_STAT_R/IPC_SET_R, version 3 POSIX ACL xattrs, the Uid_r: line of /proc/<pid>/status, and that the root of a user namespace has no privilege over UUID owners.

Assisted-by Claude:claude-opus-5-5
---
 tools/testing/selftests/Makefile           |   1 +
 tools/testing/selftests/uid_r/.gitignore   |   1 +
 tools/testing/selftests/uid_r/Makefile     |   6 +
 tools/testing/selftests/uid_r/config       |   4 +
 tools/testing/selftests/uid_r/uid_r_test.c | 535 +++++++++++++++++++++
 5 files changed, 547 insertions(+)
 create mode 100644 tools/testing/selftests/uid_r/.gitignore
 create mode 100644 tools/testing/selftests/uid_r/Makefile
 create mode 100644 tools/testing/selftests/uid_r/config
 create mode 100644 tools/testing/selftests/uid_r/uid_r_test.c
tools/testing/selftests/Makefile +1 -0
index b622052ec..284ee2c6f 100644

Lines of this file are not shown. View the raw message.

tools/testing/selftests/uid_r/.gitignore new file +1 -0
new file mode 100644
index 000000000..5855e85e3

Lines of this file are not shown. View the raw message.

tools/testing/selftests/uid_r/Makefile new file +6 -0
new file mode 100644
index 000000000..d5dc3e6aa

Lines of this file are not shown. View the raw message.

tools/testing/selftests/uid_r/config new file +4 -0
new file mode 100644
index 000000000..424ac0a2c

Lines of this file are not shown. View the raw message.

tools/testing/selftests/uid_r/uid_r_test.c new file +535 -0

535 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

From b10dd013157fbbe54658f021bbc524299b781d43 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 13:58:30 +0200
Subject: [PATCH 37/43] ovl: allow UUID and GUID owners when the upper layer
does

Changes to an overlay land in its upper layer, so whether the overlay can store UUID and GUID owners is the upper layer's business: take SB_I_UID_R over from it. Copy-up of such an owner from a lower layer into an upper layer without the flag keeps failing with -EOVERFLOW.

This is what a live system with a tmpfs over a read-only image needs to give files to UUID and GUID users.

Assisted-by Claude:claude-opus-5-5
---
 fs/overlayfs/super.c | 3 +++
 1 file changed, 3 insertions(+)
fs/overlayfs/super.c +3 -0
index 43eb0c053..5b48a9499 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

From 764cb4600427c956b7addf402c6e7ceae4751d1c Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 14:31:16 +0200
Subject: [PATCH 38/43] devpts: allow UUID and GUID owners

Terminals are given to the user of a login session: sshd and login chown the slave to the user, and a pty opened by a UUID or GUID user gets that user as its owner. devpts keeps owners in its inodes only, so like tmpfs and ramfs it can hold any kind of owner: set SB_I_UID_R.

Without it, sshd's chown() of the pty of a UUID user fails with -EOVERFLOW and the session is closed.

Assisted-by Claude:claude-opus-5-5
---
 fs/devpts/inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/devpts/inode.c +2 -0
index 9844dcf35..1bdda468d 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

From e9708d8dd4a8e6241f380983b27bb151da5b11ba Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 14:43:50 +0200
Subject: [PATCH 39/43] ksmbd: log in UUID and GUID users and map them to SIDs

A user whose ids are UUIDs or GUIDs could not use ksmbd: the login response carries 32 bit ids, sessions ran as make_kuid(uid), and SIDs were built from from_kuid_munged(), so such users and their files all became the overflow id.

Take the ids from the login response extension: flags, formerly reserved and zero, has KSMBD_LOGIN_EXT_ID_R when uid_r and gid_r (also formerly reserved) hold the user's ids as __kernel_uid_r_t, and KSMBD_LOGIN_EXT_GROUPS_R when the payload holds __kernel_gid_r_t supplementary groups instead of gid_t. struct ksmbd_user keeps kuid, kgid and kgid_t groups, which the session's credentials and durable handle owners use.

UUID and GUID users and groups have no RID; they are represented as S-1-22-<kind>-w0-w1-w2-w3 (kind 3/4: UUID user/group, 5/6: GUID user/group; w0..w3 the 16 bytes as big endian words), next to the existing S-1-22-1-<uid> and S-1-22-2-<gid>, in security descriptors, inherited ACEs, POSIX ACL entries and owner changes from clients.

The SMB3 POSIX extension's fixed 16 and 28 byte SID buffers can't hold such a SID; they keep showing the overflow id.

Assisted-by Claude:claude-opus-5-5
---
 fs/smb/server/ksmbd_netlink.h    |  15 ++-
 fs/smb/server/mgmt/user_config.c |  35 +++++-
 fs/smb/server/mgmt/user_config.h |   4 +-
 fs/smb/server/smb2pdu.c          |   8 +-
 fs/smb/server/smb_common.c       |  18 ++--
 fs/smb/server/smbacl.c           | 176 ++++++++++++++++++++++++-------
 fs/smb/server/smbacl.h           |  19 +++-
 fs/smb/server/transport_ipc.c    |   4 +-
 fs/smb/server/vfs_cache.c        |   9 +-
 fs/smb/server/vfs_cache.h        |   4 +-
 10 files changed, 227 insertions(+), 65 deletions(-)
fs/smb/server/ksmbd_netlink.h +14 -1
index af1e76045..40c43507b 100644

Lines of this file are not shown. View the raw message.

fs/smb/server/mgmt/user_config.c +32 -3
index 0be08cf18..6050bc748 100644

Lines of this file are not shown. View the raw message.

fs/smb/server/mgmt/user_config.h +3 -1
index cc460b4ff..e55470e00 100644

Lines of this file are not shown. View the raw message.

fs/smb/server/smb2pdu.c +4 -4
index 3e6d30242..f99f2fd92 100644

Lines of this file are not shown. View the raw message.

fs/smb/server/smb_common.c +9 -9
index 080fbc9eb..8278c99a7 100644

Lines of this file are not shown. View the raw message.

fs/smb/server/smbacl.c +138 -38

176 lines not on this page · raw message

fs/smb/server/smbacl.h +17 -2
index 01810c16c..b6a01f0d4 100644

Lines of this file are not shown. View the raw message.

fs/smb/server/transport_ipc.c +3 -1
index 5ad33fbfc..934e62de0 100644

Lines of this file are not shown. View the raw message.

fs/smb/server/vfs_cache.c +5 -4
index 5eae49ed1..c0b01d8a3 100644

Lines of this file are not shown. View the raw message.

fs/smb/server/vfs_cache.h +2 -2
index 1c6fc4349..d028a3944 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

From ab4f638ba87da32eeb855689b52a9df2c2badec1 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 14:45:48 +0200
Subject: [PATCH 40/43] nfsd, nfs: carry UUID and GUID owners as their text
form

NFSv4 owners and ACL principals are strings. Classic ids go through idmapd or, with id mapping disabled, as decimal numbers; a UUID or GUID user or group (Documentation/userspace-api/uid_r.rst) has neither a number nor an idmapd entry and showed as the overflow id.

Encode such an id as its text form -- "xxxxxxxx-xxxx-xxxx-xxxx- xxxxxxxxxxxx" for a UUID, the same in braces for a GUID -- in both directions on the server and the client, and take such a string (it has no '@', so it can't be a user@domain name) as that id again. NFSv4 superblocks set SB_I_UID_R, so the client can chown to such owners.

RPC credentials stay classic: AUTH_SYS has a 32 bit uid, so a UUID or GUID user on a client still reaches the server as the overflow id.

Assisted-by Claude:claude-opus-5-5
---
 fs/nfs/nfs4idmap.c  | 53 +++++++++++++++++++++++++++++++++++
 fs/nfs/super.c      |  2 ++
 fs/nfsd/nfs4idmap.c | 68 +++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 121 insertions(+), 2 deletions(-)
fs/nfs/nfs4idmap.c +53 -0

53 lines not on this page · raw message

fs/nfs/super.c +2 -0
index cb19f1540..2d292e441 100644

Lines of this file are not shown. View the raw message.

fs/nfsd/nfs4idmap.c +66 -2

68 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

From 591abc7a124985b02c2a0ff87314b783e133542e Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 10 Oct 2026 14:46:03 +0200
Subject: [PATCH 41/43] Documentation: uid_r: describe SMB and NFSv4

ksmbd's login extension and SIDs for UUID and GUID users, NFSv4 owner strings, and what AUTH_SYS and the SMB3 POSIX extensions can't carry.

Assisted-by Claude:claude-opus-5-5
---
 Documentation/userspace-api/uid_r.rst | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
Documentation/userspace-api/uid_r.rst +17 -0
index c08048545..d16d4317f 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

From c3bd00e9eac032f25d2468cfd286788ee3539fc8 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sun, 11 Oct 2026 17:28:28 +0200
Subject: [PATCH 42/43] ksmbd: pass through NTLM authentication to a domain
controller

A ksmbd server that is a member of an Active Directory domain cannot check the NTLM response of a domain user on its own: it has no password hash for that user. Add a way to defer the check to user space, which can ask a domain controller over NETLOGON (NetrLogonSamLogonEx).

When the login response for a user carries the new KSMBD_USER_FLAG_PASSTHROUGH flag, ksmbd no longer computes the NTLMv2 response from a local hash. Instead ksmbd_decode_ntlmssp_auth_blob() hands the server challenge and the client's user name, domain name, workstation and NT/LM responses to user space through the new KSMBD_EVENT_NTLM_AUTHEN_REQUEST event and takes the session base key from the KSMBD_EVENT_NTLM_AUTHEN_RESPONSE, then continues with the existing key-exchange path.

The two new events get a strict netlink policy and are validated in ipc_validate_msg(); ksmbd_nl_init_fixup() keeps strict validation for commands at or after resv_start_op so the new fixed-size response is checked.

Assisted-by Claude:claude-opus-4-8
---
 fs/smb/server/auth.c          | 68 ++++++++++++++++++++++++++++++++
 fs/smb/server/ksmbd_netlink.h | 41 ++++++++++++++++++++
 fs/smb/server/transport_ipc.c | 73 ++++++++++++++++++++++++++++++++++-
 fs/smb/server/transport_ipc.h |  3 ++
 4 files changed, 183 insertions(+), 2 deletions(-)
fs/smb/server/auth.c +68 -0

68 lines not on this page · raw message

fs/smb/server/ksmbd_netlink.h +41 -0

41 lines not on this page · raw message

fs/smb/server/transport_ipc.c +71 -2

73 lines not on this page · raw message

fs/smb/server/transport_ipc.h +3 -0
index e51850f14..f957a33ae 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

From 6d2b53020107922610f03a572c52f4b924054411 Mon Sep 17 00:00:00 2001
From: Jan Koester <[email protected]>
Date: Sat, 17 Oct 2026 09:29:07 +0200
Subject: [PATCH 43/43] ksmbd: put the workgroup into the NTLMSSP target info's
domain names

ksmbd_build_ntlmssp_challenge_blob() writes the netbios name into all four AV pairs of the challenge's target info, the domain names (MsvAvNbDomainName, MsvAvDnsDomainName) included. The client copies them into its NTLMv2 response.

With NTLM pass-through, a domain controller verifies that response over NETLOGON, and Samba (NTLMv2_RESPONSE_verify_workstation()) refuses it with NT_STATUS_LOGON_FAILURE unless MsvAvNbComputerName is the secure channel's computer account and MsvAvNbDomainName its workgroup. Every pass-through login of a domain user then fails.

Put the workgroup into the two domain names. Size the challenge blob from both names in one helper, ntlmssp_challenge_size(), and check that the blob fits into the response buffer when it is built in place without SPNEGO: the workgroup may be longer than the netbios name.

Assisted-by Claude:claude-opus-5-5
---
 fs/smb/server/auth.c    | 41 ++++++++++++++++++++++++++++++++++-------
 fs/smb/server/smb2pdu.c | 21 +++++++++++++++++++--
 2 files changed, 53 insertions(+), 9 deletions(-)
fs/smb/server/auth.c +34 -7

41 lines not on this page · raw message

fs/smb/server/smb2pdu.c +19 -2
index f99f2fd92..e6b2b6a5d 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.