UUID and GUID user and group ids (*_r system calls)
Subsystems (55)
v2 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 selftests and the boot test suite ran on the same series on top of v7.2.9 and v7.2.11. On v7.3-rc7, the series is built for x86_64 (bzImage and modules, with USER_NS, audit, ecryptfs, fscrypt, quota, ublk, NFS, Bluetooth and the LSMs enabled) and boots in QEMU, where an integration test with a full user space passes 24/24: ssh sessions with a pty as UUID users, UUID owners on tmpfs and overlayfs, SMB logins of UUID users through ksmbd with S-1-22-3-... owner SIDs, and NFSv4 showing and setting UUID owners. ext4 uid_r was not part of it.
- 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?
Changes in v2:
- No code changes. v1 reached the lists only up to patch 11, the mail provider throttled the rest; this is the complete series, now sent from [email protected] (author and Signed-off-by changed to it).
- Hunk offsets refreshed against v7.3-rc7, testing section updated.
- v1: https://lore.kernel.org/r/[email protected]
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: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907
Signature · 1 line
2.56.0
RFC PATCH v2 1/41 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.
--- 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
@@ -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
@@ -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
[email protected]
AI reviewRe: [RFC PATCH v2 01/41] uuid: move uuid_t and guid_t into <linux/uuid_types.h>
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
<
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 inkuid_tandkgid_t, whose <linux/uidgid_types.h> is included by <linux/sched.h>.
Quoted 8 lines
Move the two types and
UUID_SIZEinto 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-5Signed-off-by Jan Koester <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
RFC PATCH v2 2/41 uapi: add <linux/uidgid_r.h> for 128 bit capable user and group ids
In reply to Jan KoesterUser 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.
--- 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
@@ -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
[email protected]
AI reviewRe: [RFC PATCH v2 02/41] uapi: add <linux/uidgid_r.h> for 128 bit capable user and group ids
Sashiko has reviewed this patch and found no issues.
Quoted 12 lines
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.
Quoted 6 lines
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-5Signed-off-by Jan Koester <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
RFC PATCH v2 3/41 uidgid: add uid_is_legacy() and gid_is_legacy()
In reply to Jan KoesterUser 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.
--- include/linux/uidgid.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/linux/uidgid.h +14 -0
@@ -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
[email protected]
AI reviewRe: [RFC PATCH v2 03/41] uidgid: add uid_is_legacy() and gid_is_legacy()
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] uidgid: uid_is_legacy() and gid_is_legacy() bifurcate kernel UID/GID model --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] uidgid: uid_is_legacy() and gid_is_legacy() bifurcate kernel UID/GID model --
commit 89bf063fd971bc3a6a5e091bc2ca038531384166
Author: Jan Koester <[email protected]>
uidgid: add uid_is_legacy() and gid_is_legacy()
This commit adds the uid_is_legacy() and gid_is_legacy() predicate helpers in include/linux/uidgid.h to check whether a kuid_t or kgid_t holds a 32-bit id in preparation for storing 128-bit ids in those types.
Quoted 15 lines
include/linux/uidgid.h +7
-0@@ -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;
include/linux/uidgid.h struct uid_gid_map; · line 41
Quoted 10 lines
include/linux/uidgid.h +7
-0+} + +static inline bool gid_is_legacy (kgid_t gid) +{ +return true; +} +#ifdef CONFIG_MULTIUSER static inline uid_t __kuid_val (kuid_t uid) {
[Severity: High]
Introducing uid_is_legacy() and gid_is_legacy() in include/linux/uidgid.h to bifurcate kernel code paths for 20-byte tagged union kuid_t, kgid_t, vfsuid_t, and vfsgid_t types raises several architectural and correctness regressions.
kuid_t and kgid_t are designed as zero-overhead 32-bit wrappers passed by value in a single register and embedded in core structures including struct inode, struct cred, struct group_info, struct user_struct, struct posix_acl_entry, and struct kstat. Expanding each id from 4 bytes to 20 bytes grows struct cred by 128 bytes and struct inode by 32 bytes for every cached inode, while turning pass-by-value helpers and equality checks into 20-byte struct copies and __builtin_memcmp() calls.
Expanding inode->i_uid and inode->i_gid beyond 32 bits also breaks the single-word access assumption required by lockless readers in acl_permission_check() during rcu pathwalk and in generic_fillattr() during statx() when racing with updates in setattr_copy() and i_uid_update(), which can result in torn reads.
Furthermore, splitting kernel subsystems with uid_is_legacy() and gid_is_legacy() so that __kuid_val() and from_kuid() return (uid_t)-1 and from_kuid_munged() collapses non-legacy ids into overflowuid and overflowgid breaks the invariant that every valid kuid_t and kgid_t maps uniformly across the vfs, filesystems, user namespaces, quotas, netlink credentials, and userspace interfaces.
Should mapping external 128-bit directory ids to 32-bit ids be handled by userspace identity daemons and existing kernel id-mapping facilities instead of bifurcating kuid_t and kgid_t with uid_is_legacy() and gid_is_legacy()?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
RFC PATCH v2 4/41 net: sock: read sk_uid through a seqcount
In reply to Jan Koestersk_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().
--- 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
@@ -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
@@ -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
@@ -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
[email protected]
AI reviewRe: [RFC PATCH v2 04/41] net: sock: read sk_uid through a seqcount
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] net: sock: write_seqcount_begin() called in preemptible sock_init_data_uid() - [High] net: sock…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] net: sock: write_seqcount_begin() called in preemptible sock_init_data_uid()
- [High] net: sock: raw seqcount_t under sk_callback_lock livelocks on PREEMPT_RT --
commit e15d18b6d3adc57553d8944b44a103206aaa6a91
Author: Jan Koester <[email protected]>
net: sock: read sk_uid through a seqcount
This commit introduces a sequence counter (sk_uid_seq) in struct sock to protect lockless reads of sk_uid against concurrent updates in sock_graft() and sockfs_setattr(). Writers update sk_uid via __sk_set_uid(), while readers use sk_uid() to retry until a consistent value is read.
Quoted 4 lines
include/net/sock.h +0
-0
[ ... ]
Quoted 39 lines
include/net/sock.h +14
-3@@ -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);
include/net/sock.h static inline u64 sock_i_ino(const struct sock *sk) · line 2188
Quoted 10 lines
include/net/sock.h +9
-0+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; }
[Severity: High]
Could using a raw seqcount_t for sk_uid_seq cause preemption warnings and a reader livelock on preempt-rt kernels?
Runtime writers such as sockfs_setattr(), sock_graft(), and mptcp_sock_graft() serialize updates to sk->sk_uid with write_lock_bh(&sk->sk_callback_lock) before calling __sk_set_uid() (directly or via sk_set_socket()). On preempt-rt kernels, write_lock_bh() on an rwlock_t does not disable preemption:
include/linux/rwlock_rt.h:write_lock_bh() {
local_bh_disable();
rt_write_lock(rwlock);
}Because sk_uid_seq is a raw seqcount_t rather than a seqcount_rwlock_t associated with sk_callback_lock, write_seqcount_begin(&sk->sk_uid_seq) does not disable preemption and triggers lockdep_assert_preemption_disabled() in __seqprop_assert():
include/linux/seqlock.h:__seqprop_assert() {
lockdep_assert_preemption_disabled();
}In addition, if a higher-priority task preempts the writer between write_seqcount_begin() and write_seqcount_end() while sk_uid_seq.sequence is odd and calls sk_uid(), read_seqcount_begin(&sk->sk_uid_seq) will spin indefinitely in __read_seqcount_begin():
include/linux/seqlock.h:__read_seqcount_begin() {
while (unlikely((__seq = seqprop_sequence(s)) & 1))
cpu_relax();
}With a raw seqcount_t, the reader has no associated rwlock_t to block on and priority-boost the preempted writer. Should sk_uid_seq be a seqcount_rwlock_t initialized with sk_callback_lock, or should preemption be disabled around the write section?
Quoted 4 lines
net/core/sock.c +0
-0
[ ... ]
net/core/sock.c void sock_init_data_uid(struct socket *sock, struct sock *sk, kuid_t uid) · line 3782
Quoted 9 lines
net/core/sock.c +1
-1@@ -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;
[Severity: High]
What happens when sock_init_data_uid() calls sk_set_socket() and __sk_set_uid() in preemptible process context with softirqs enabled?
During socket creation (for example, inet_create() -> sock_init_data() -> sock_init_data_uid()), sock_init_data_uid() runs in normal process context with preemption and bottom halves enabled and no locks held. Calling __sk_set_uid() (both via sk_set_socket() when sock is non-null and directly in sock_init_data_uid()) invokes write_seqcount_begin(&sk->sk_uid_seq) on a raw seqcount_t while preemption is enabled, which immediately triggers the warning in lockdep_assert_preemption_disabled().
Furthermore, write_seqcount_begin(&sk->sk_uid_seq) records a lockdep write acquisition on the sk_uid_seq class with softirqs enabled. When sk_uid() is later called from softirq context (such as during tcp_v4_rcv() -> tcp_v4_syn_recv_sock() -> sk_clone(), or during routing and reuseport lookups), read_seqcount_begin(&sk->sk_uid_seq) records a softirq read on the same class in mark_usage() in kernel/locking/lockdep.c, triggering an inconsistent lock state warning (softirq-on-w to in-softirq-r).
Since the socket is not yet published in sock_init_data_uid(), should sk->sk_uid be initialized with a plain assignment when the socket is still unshared, only using __sk_set_uid() under write_lock_bh(&sk->sk_callback_lock)?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
RFC PATCH v2 5/41 af_unix: keep sender ids in skb->cb only when they are classic ids
In reply to Jan Koesterunix_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.
--- 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
@@ -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 senint 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
@@ -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
[email protected]
AI reviewRe: [RFC PATCH v2 05/41] af_unix: keep sender ids in skb->cb only when they are classic ids
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] af_unix: unix_skb_parms can exceed skb->cb size under CONFIG_RANDSTRUCT --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] af_unix: unix_skb_parms can exceed skb->cb size under CONFIG_RANDSTRUCT --
commit 9d78c8ae60dfc024139d5c6d850877e3acd5d5ea
Author: Jan Koester <[email protected]>
af_unix: keep sender ids in skb->cb only when they are classic ids
This commit keeps classic 32-bit sender uid and gid values inline in unix_skb_parms while dynamically allocating a struct unix_skb_ids for non-legacy ids so that unix_skb_parms continues to fit within the 48-byte skb->cb buffer.
Quoted 14 lines
net/unix/af_unix.h +2
-2@@ -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;
net/unix/af_unix.h line 26
Quoted 10 lines
net/unix/af_unix.h +7
-0+}; + +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 */
[Severity: Low]
Can this cause a build regression on 64-bit kernels when CONFIG_RANDSTRUCT and CONFIG_SECURITY_NETWORK are enabled?
In net/unix/af_unix.h, struct unix_skb_parms is marked with __randomize_layout:
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 */
#endif
u32 consumed;
} __randomize_layout;Adding the ids pointer while keeping uid and gid as separate 4-byte members gives struct unix_skb_parms three 8-byte pointers (pid, ids, fp) and four 4-byte integers (uid, gid, secid, consumed) on 64-bit builds with CONFIG_SECURITY_NETWORK=y.
When a randstruct seed shuffles these seven members into an alternating order of 4-byte integers and 8-byte pointers (u32, ptr, u32, ptr, u32, ptr, u32), each 8-byte pointer is preceded by 4 bytes of alignment padding and the trailing 4-byte integer is followed by 4 bytes of tail padding.
That pads sizeof(struct unix_skb_parms) to 56 bytes, exceeding the 48-byte skb->cb buffer and triggering the compile-time assertion in net/unix/af_unix.c:af_unix_init():
static int __init af_unix_init(void)
{
int i, rc = -1;
BUILD_BUG_ON(sizeof(struct unix_skb_parms) > sizeof_field(struct sk_buff, cb));Would placing ids and the legacy uid/gid pair in a union (since uid and gid are only used when ids is NULL), or grouping uid and gid into an unnamed struct so they are randomized as a single 8-byte unit, avoid this padding overhead?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
RFC PATCH v2 6/41 netlink: keep classic sender ids in skb->cb
In reply to Jan Koesternetlink_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.
--- 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
@@ -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
@@ -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
@@ -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
@@ -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;
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 06/41] netlink: keep classic sender ids in skb->cb
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines
netlink_skb_parmshas to fit intoskb->cb, and netlink skbs are cloned together with it for broadcasts, so there is neither room forkuid_tandkgid_tholding UUIDs nor a single owner for an allocation.
Quoted 8 lines
Store the sender ids as classic kernel ids: a UUID or GUID becomes -1, which reaches the receiver of
SCM_CREDENTIALSas 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-5Signed-off-by Jan Koester <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
RFC PATCH v2 7/41 Bluetooth: keep classic sender ids in skb->cb
In reply to Jan Koesterstruct 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.
--- 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
@@ -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
@@ -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
[email protected]
AI reviewRe: [RFC PATCH v2 07/41] Bluetooth: keep classic sender ids in skb->cb
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
struct
bt_skb_cbholds the sender's structscm_credsfor HCI sockets, which no longer fits intoskb->cbnow thatkuid_tandkgid_tcan hold UUIDs and GUIDs. Like netlink, keep them as structscm_creds_classic:
classic ids as before, the overflow id for UUID and GUID senders.Assisted-by Claude:claude-opus-5-5Signed-off-by Jan Koester <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
RFC PATCH v2 8/41 smb: client: use __kuid_val() for the unix SIDs of the caller
In reply to Jan KoesterThe 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.
--- 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
@@ -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
@@ -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
[email protected]
AI reviewRe: [RFC PATCH v2 08/41] smb: client: use __kuid_val() for the unix SIDs of the caller
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
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-5Signed-off-by Jan Koester <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
RFC PATCH v2 9/41 uidgid: let kuid_t and kgid_t hold a UUID or a GUID
In reply to Jan KoesterMake 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.
--- 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
[email protected]
AI reviewRe: [RFC PATCH v2 09/41] uidgid: let kuid_t and kgid_t hold a UUID or a GUID
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider: - [High] fs: VFSUIDT_INIT_RAW() initializes .type instead of .legacy - [High] quota: qid_has_mapping()…
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [High] fs: VFSUIDT_INIT_RAW() initializes .type instead of .legacy
- [High] quota: qid_has_mapping() returns false for UUID/GUIDs in init_user_ns
- [High] uidgid: 20-byte kuid_t and kgid_t cause torn reads and writes on inode ids
- [High] uidgid: __kid_cmp() ordering breaks fib_rule_match() for UUID/GUID sockets
- [High] audit: broken audit_field union aliasing in audit_krule_to_data()
- [Medium] uidgid: __kid_hash() mismatches __kid_cmp() when !CONFIG_MULTIUSER
- [Low] uidgid: 20-byte kuid_t and kgid_t break READ_ONCE()/WRITE_ONCE() in tun.c --
commit 36d10e56f75840b8f3657151d3427526a39d77ae
Author: Jan Koester <[email protected]>
uidgid: let kuid_t and kgid_t hold a UUID or a GUID
This commit turns kuid_t, kgid_t, vfsuid_t, and vfsgid_t into 20-byte tagged unions capable of holding a classic 32-bit ID, an RFC 9562 UUID, or a Microsoft GUID. It also updates ID comparison, hashing, user namespace mapping, and mount idmapping helpers to handle non-legacy IDs.
Quoted 5 lines
fs/mnt_idmapping.c +0
-0
fs/mnt_idmapping.c vfsuid_t make_vfsuid(struct mnt_idmap *idmap, · line 96
Quoted 10 lines
fs/mnt_idmapping.c +4
-0@@ -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
[Severity: High]
When make_vfsuid() and make_vfsgid() in fs/mnt_idmapping.c map a classic ID on an idmapped mount, they return via VFSUIDT_INIT_RAW() and VFSGIDT_INIT_RAW():
fs/mnt_idmapping.c:
#define VFSUIDT_INIT_RAW(val) (vfsuid_t){ val }
#define VFSGIDT_INIT_RAW(val) (vfsgid_t){ val }
...
return VFSUIDT_INIT_RAW(map_id_down(&idmap->uid_map, uid));Now that vfsuid_t and vfsgid_t in include/linux/mnt_idmapping.h have u32 type as their first struct member, doesn't this positional initializer assign the mapped 32-bit UID or GID to .type while zero-initializing .legacy and .uuid?
When VFS callers on an idmapped mount map an inode's classic ID through i_uid_into_vfsuid() or i_gid_into_vfsgid() (such as acl_permission_check(), inode_owner_or_capable(), may_follow_link(), chown_ok(), and generic_fillattr()):
- Mapped ID 1 sets .type = KID_UUID with an all-zero UUID, and mapped ID 2 sets .type = KID_GUID with an all-zero GUID, allowing a caller with an all-zero UUID or GUID credential to match files owned by mapped UID 1 or 2 in vfsuid_eq_kuid().
- Other non-zero mapped IDs set .type to an unknown tag with .legacy = 0, so vfsuid_is_legacy() returns false and __vfsuid_val() returns (uid_t)-1.
- When map_id_down() returns (uid_t)-1 for an unmapped ID, VFSUIDT_INIT_RAW((uid_t)-1) sets .type = (u32)-1, causing vfsuid_valid() and vfsgid_valid() in include/linux/mnt_idmapping.h:
static inline bool vfsuid_valid(vfsuid_t uid)
{
return !vfsuid_is_legacy(uid) || __vfsuid_val(uid) != (uid_t)-1;
}to see !vfsuid_is_legacy(uid) as true and treat unmapped IDs as valid.
Should VFSUIDT_INIT_RAW() and VFSGIDT_INIT_RAW() initialize .type = KID_LEGACY and .legacy = (val) like KUIDT_INIT() and KGIDT_INIT()?
[ ... ]
Quoted 4 lines
include/linux/uidgid.h +0
-0
[ ... ]
Quoted 11 lines
include/linux/uidgid.h +7
-0@@ -64,64 +69,115 @@ static inline gid_t __kgid_val(kgid_t gid)#define INVALID_UID KUIDT_INIT(-1)#define INVALID_GID KGIDT_INIT(-1) +/* +* Ids are ordered by kind first (legacy ids before UUIDs before GUIDs), +* then by value: numerically for legacy ids, bytewise for the others. +* That keeps sorted id arrays and range checks between legacy ids +* working: a UUID is never inside a range of legacy ids. +*/ +static inline int __kid_cmp(u32 ltype, u32 llegacy, const u8 *lb,
include/linux/uidgid.h static inline gid_t __kgid_val(kgid_t gid) · line 88
Quoted 10 lines
include/linux/uidgid.h +10
-0+ u32 rtype, u32 rlegacy, const u8 *rb) +{ + if (!IS_ENABLED(CONFIG_MULTIUSER)) + return 0; + if (ltype != rtype) + return ltype < rtype ? -1 : 1; + if (ltype == KID_LEGACY) + return llegacy == rlegacy ? 0 : llegacy < rlegacy ? -1 : 1; + return __builtin_memcmp(lb, rb, UUID_SIZE); +}
[Severity: High]
How does this ordering interact with fib_rule_match() in net/core/fib_rules.c when a socket is owned by a KID_UUID or KID_GUID user?
In net/core/fib_rules.c, FIB rules without an explicit FRA_UID_RANGE attribute (including the default local, main, and default table rules added by fib_default_rule_add() and rules created in fib_nl2rule()) initialize rule->uid_range to fib_kuid_range_unset:
net/core/fib_rules.c:
static const struct fib_kuid_range fib_kuid_range_unset = {
KUIDT_INIT(0),
KUIDT_INIT(~0),
};When policy routing is active and fib_rules_lookup() calls fib_rule_match(), it checks fl->flowi_uid (populated from sk_uid(sk) in paths such as build_sk_flow_key() in net/ipv4/route.c and ip6_route_output_flags() in net/ipv6/route.c) unconditionally against rule->uid_range without checking uid_range_set(&rule->uid_range):
net/core/fib_rules.c:fib_rule_match()
if (uid_lt(fl->flowi_uid, rule->uid_range.start) ||
uid_gt(fl->flowi_uid, rule->uid_range.end))
goto out;Because __kid_cmp() orders KID_UUID and KID_GUID after all KID_LEGACY values, uid_gt(fl->flowi_uid, fib_kuid_range_unset.end) will evaluate to true for any UUID or GUID socket, rejecting all unset-UID rules (including the default rules) and failing route lookups with -ESRCH (-ENETUNREACH).
[ ... ]
Quoted 5 lines
include/linux/uidgid.h +5
-0+/* A hash of an id, for hash tables keyed by kuid_t or kgid_t */ +static inline u32 __kid_hash (u32 type,u32 legacy,const u8 *b) +{ +u32 w[4 ]; +
include/linux/uidgid.h static inline gid_t __kgid_val(kgid_t gid) · line 176
Quoted 10 lines
include/linux/uidgid.h +10
-0+if (type ==KID_LEGACY ) +return legacy; +__builtin_memcpy (w, b,sizeof (w)); +return w[0 ] ^ w[1 ] ^ w[2 ] ^ w[3 ] ^ type; +} + +static inline u32 kuid_hash (kuid_t uid) +{ +return __kid_hash (uid.type,__kuid_val (uid), uid.uuid.b); +}
[Severity: Medium]
When CONFIG_MULTIUSER is disabled, __kid_cmp() returns 0 unconditionally so uid_eq() treats all kuid_t values as equal regardless of .type, whereas __kid_hash() still hashes the UUID/GUID bytes when type != KID_LEGACY.
On a !CONFIG_MULTIUSER kernel, if an inode with a KID_UUID or KID_GUID owner (e.g. from a mounted ext4 uid_r filesystem or via chown_r() / fchown_r() in fs/open.c) and S_ISUID set is executed via execve(), bprm_fill_uid() in fs/exec.c sets bprm->cred->euid to that UUID or GUID. When inc_ucount() -> alloc_ucounts() -> find_ucounts() in kernel/ucount.c (or uidhashentry() in kernel/user.c, or later fs/ecryptfs/messaging.c) hashes that kuid_t with kuid_hash(), won't it land in a non-zero bucket, miss init_ucounts (hashed at GLOBAL_ROOT_UID), and allocate duplicate ucounts structures even though uid_eq(init_ucounts.uid, uid) is true?
Should __kid_hash() also return 0 when !IS_ENABLED(CONFIG_MULTIUSER)?
Quoted 19 lines
include/linux/uidgid.h +11
-0+ +static inline u32 kgid_hash (kgid_t gid) +{ +return __kid_hash (gid.type,__kgid_val (gid), gid.uuid.b); +}#ifdef CONFIG_USER_NS @@ -134,13 +190,22 @@ extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);extern uid_t from_kuid_munged (struct user_namespace *to,kuid_t uid);extern gid_t from_kgid_munged (struct user_namespace *to,kgid_t gid); +/* +* UUIDs and GUIDs aren't in any namespace's uid_map or gid_map: they +* exist in the initial user namespace only, and nobody has privilege +* over them through a capability in another one. +*/ static inline bool kuid_has_mapping (struct user_namespace *ns,kuid_t uid) { +if (!uid_is_legacy (uid))
include/linux/uidgid.h extern gid_t from_kgid(struct user_namespace *to, kgid_t gid); · line 210
Quoted 10 lines
include/linux/uidgid.h +3
-0+return ns == &init_user_ns;return from_kuid (ns, uid) != (uid_t) -1 ; }static inline bool kgid_has_mapping (struct user_namespace *ns,kgid_t gid) { +if (!gid_is_legacy (gid)) +return ns == &init_user_ns;return from_kgid (ns, gid) != (gid_t) -1 ; }
[Severity: High]kuid_has_mapping() and kgid_has_mapping() (along with vfsuid_has_mapping() and vfsgid_has_mapping() in include/linux/mnt_idmapping.h) are updated here because from_kuid() and from_kgid() in kernel/user_namespace.c now return (uid_t)-1 and (gid_t)-1 for UUID and GUID IDs even in init_user_ns.
However, qid_has_mapping() in include/linux/quota.h still checks:
include/linux/quota.h:
static inline bool qid_has_mapping(struct user_namespace *ns, struct kqid qid)
{
return from_kqid(ns, qid) != (qid_t) -1;
}Because from_kqid() in fs/quota/kqid.c delegates to from_kuid() and from_kgid(), qid_has_mapping(&init_user_ns, qid) now returns false for all UUID and GUID kqid values.
Although the follow-up commit "fs: keep UUID and GUID owners off filesystems that can't store them" restricts UUID and GUID owners to SB_I_UID_R filesystems, tmpfs with CONFIG_TMPFS_QUOTA (enabled in "shmem, ramfs: allow UUID and GUID owners") and ext4 (enabled in "ext4: add the uid_r feature for UUID and GUID owners") both support VFS quotas and call dquot_initialize() and dquot_transfer(). Furthermore, while "quota: don't account UUID and GUID owners" adds a !qid_is_legacy(qid) check returning ERR_PTR(-ESRCH) in dqget() in fs/quota/dquot.c, it places that check after:
fs/quota/dquot.c:dqget()
if (!qid_has_mapping(sb->s_user_ns, qid))
return ERR_PTR(-EINVAL);without updating qid_has_mapping(). Doesn't this make the !qid_is_legacy(qid) check unreachable and cause dqget() to return -EINVAL instead of -ESRCH, breaking file creation (__ext4_new_inode(), shmem_get_inode()) and ownership changes (ext4_setattr(), shmem_setattr()) for UUID and GUID owners whenever quotas are active?
Quoted 26 lines
include/linux/uidgid_types.h +17
-0@@ -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.
include/linux/uidgid_types.h line 32
Quoted 10 lines
include/linux/uidgid_types.h +7
-1+*/ typedef struct { -uid_t val; +u32 type; +union { +uid_t legacy; +uuid_t uuid; +guid_t guid; + }; }kuid_t ;
[Severity: High]
Placing u32 type at offset 0 and uid_t legacy at offset 4 of kuid_t and kgid_t changes the layout of the anonymous union in struct audit_field in include/linux/audit.h:
include/linux/audit.h:
struct audit_field {
u32 type;
union {
u32 val;
kuid_t uid;
kgid_t gid;
struct {
char *lsm_str;
void *lsm_rule;
};
};
u32 op;
};In kernel/auditfilter.c, audit_data_to_entry() populates f->uid = make_kuid() or f->gid = make_kgid() for UID and GID filter fields (AUDIT_LOGINUID, AUDIT_UID, AUDIT_EUID, AUDIT_SUID, AUDIT_FSUID, AUDIT_OBJ_UID, AUDIT_GID, AUDIT_EGID, AUDIT_SGID, AUDIT_FSGID, AUDIT_OBJ_GID), which now writes KID_LEGACY (0) at offset 0 and the numeric ID at offset 4.
When audit_krule_to_data() in kernel/auditfilter.c serializes rules back to userspace for AUDIT_LIST_RULES:
kernel/auditfilter.c:audit_krule_to_data()
default:
data->values[i] = f->val;
}none of those UID or GID fields have explicit cases in the switch statement, so they all read f->val at offset 0 (f->uid.type == 0). Won't this cause AUDIT_LIST_RULES to report 0 (root) for every UID and GID filter rule?
include/linux/uidgid_types.h line 41
Quoted 10 lines
include/linux/uidgid_types.h +6
-1typedef struct { -gid_t val; +u32 type; +union { +gid_t legacy; +uuid_t uuid; +guid_t guid; + }; }kgid_t ;
[Severity: High]
With kuid_t and kgid_t growing from 4 bytes to 20 bytes, reads and writes of inode->i_uid and inode->i_gid are no longer single-word atomic and compile into multi-instruction memory copies.
In the VFS, writers update inode->i_uid and inode->i_gid in place via notify_change() -> setattr_copy() -> i_uid_update() / i_gid_update() in include/linux/fs.h (holding only inode->i_rwsem), and via lookup_fast() -> pid_revalidate() -> pid_update_inode() -> task_dump_owner() in fs/proc/base.c (under rcu_read_lock() with no inode lock held):
include/linux/fs.h:
static inline void i_uid_update(struct mnt_idmap *idmap,
const struct iattr *attr,
struct inode *inode)
{
if (attr->ia_valid & ATTR_UID)
inode->i_uid = from_vfsuid(idmap, i_user_ns(inode),
attr->ia_vfsuid);
}Meanwhile, lockless readers in acl_permission_check(), may_follow_link(), may_create_in_sticky(), inode_owner_or_capable(), and generic_fillattr() copy inode->i_uid and inode->i_gid by value through i_uid_into_vfsuid() and i_gid_into_vfsgid() without holding inode->i_rwsem or any seqlock:
include/linux/fs.h:
static inline vfsuid_t i_uid_into_vfsuid(struct mnt_idmap *idmap,
const struct inode *inode)
{
return make_vfsuid(idmap, i_user_ns(inode), inode->i_uid);
}Can a concurrent reader racing with chown() / chown_r() or procfs task revalidation observe a torn 20-byte ID—for example, .type == KID_LEGACY paired with the first 4 bytes of a UUID/GUID in .legacy (which can match GLOBAL_ROOT_UID or another local UID), or .type == KID_UUID / KID_GUID paired with stale union bytes—or can concurrent pid_revalidate() calls leave a /proc/<pid> inode's ownership permanently torn?
[Severity: Low]
Also, growing kuid_t and kgid_t to 20 bytes causes READ_ONCE() and WRITE_ONCE() on kuid_t and kgid_t to fail compiletime_assert_rwonce_type() in include/asm-generic/rwonce.h.
Unlike sk->sk_uid (which is converted to a seqcount in the later commit "net: sock: read sk_uid through a seqcount"), drivers/net/tun.c still uses READ_ONCE() and WRITE_ONCE() on tun->owner and tun->group in tun_fill_info() and __tun_chr_ioctl():
drivers/net/tun.c:tun_fill_info()
kuid_t owner = READ_ONCE(tun->owner);
kgid_t group = READ_ONCE(tun->group);drivers/net/tun.c:__tun_chr_ioctl()
WRITE_ONCE(tun->owner, owner);
...
WRITE_ONCE(tun->group, group);Won't this break the build when CONFIG_TUN is enabled?
[ ... ]
Quoted 2 lines
Signature · 1 line
2.51.2
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
RFC PATCH v2 10/41 uidgid: convert between kernel ids and the ids of the *_r system calls
In reply to Jan KoesterAdd 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.
--- 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
@@ -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
@@ -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
[email protected]
AI reviewRe: [RFC PATCH v2 10/41] uidgid: convert between kernel ids and the ids of the *_r system calls
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] uidgid: get_kuid_r() and get_kgid_r() accept nonzero reserved bytes - [Medium] uidgid…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] uidgid: get_kuid_r() and get_kgid_r() accept nonzero reserved bytes
- [Medium] uidgid: get_kuid_r() and get_kgid_r() accept invalid IDs on !CONFIG_MULTIUSER --
commit 991387abfa396e9352b6de3b866ad79653e997ad
Author: Jan Koester <[email protected]>
uidgid: convert between kernel ids and the ids of the *_r system calls
This commit adds helper functions to convert between kernel kuid_t/kgid_t values and the struct __kernel_uid_r representation used by the *_r system calls, along with helpers to copy them to and from userspace and format them as strings.
Quoted 6 lines
kernel/uidgid_r.c new file +0
-0@@ -0,0 +1,323 @@
[ ... ]
Quoted 17 lines
kernel/uidgid_r.c new file +17
-0+/* +* Whether @id is well formed: a known type, reserved bytes zero, a UUID of +* version 4 with the RFC 9562 variant, a GUID other than the nil GUID. +*/ +static bool kid_r_valid (const struct __kernel_uid_r *id) +{ +switch (id->type) { +case UID_R_LEGACY : +return !memchr_inv (id->uuid +sizeof (id->legacy),0 , +UID_R_SIZE -sizeof (id->legacy)); +case UID_R_UUID : +return (id->uuid[6 ] >>4 ) ==4 && (id->uuid[8 ] &0xc0 ) ==0x80 ; +case UID_R_GUID : +return memchr_inv (id->guid,0 ,UID_R_SIZE ); + } +return false; +}
[ ... ]
kernel/uidgid_r.c line 191
Quoted 9 lines
kernel/uidgid_r.c new file +9
-0+/* +* "No id" from userspace: no pointer, UID_R_NONE, or the classic -1. The +* set*id_r() and chown_r() calls take it as "leave unchanged". +*/ +static bool kid_r_is_none (const struct __kernel_uid_r *id) +{ +return id->type ==UID_R_NONE || + (id->type ==UID_R_LEGACY && id->legacy == (u32)-1 ); +}
[Severity: Medium]
Does kid_r_is_none() in kernel/uidgid_r.c allow nonzero reserved bytes in struct __kernel_uid_r to bypass validation in get_kuid_r() and get_kgid_r()?
When userspace passes a struct __kernel_uid_r to get_kuid_r() or get_kgid_r(), kid_r_is_none(&id) is checked before make_kuid_r() or make_kgid_r() (which call kid_r_valid(&id)):
if (kid_r_is_none(&id)) return 0; *kuid = make_kuid_r(from, &id);
If userspace passes id->type == UID_R_NONE with nonzero bytes in id->uuid, or id->type == UID_R_LEGACY with id->legacy == (u32)-1 and nonzero trailing bytes in id->uuid + sizeof(id->legacy), kid_r_is_none() returns true and get_kuid_r() / get_kgid_r() return 0 instead of -EINVAL.
Should kid_r_is_none() also verify that all bytes of id->uuid are zero for UID_R_NONE and that the trailing reserved bytes are zero for UID_R_LEGACY?
Quoted 42 lines
kernel/uidgid_r.c new file +42
-0+ +/** +* get_kuid_r - read a uid of a *_r system call from userspace +* @from: user namespace the uid is in +* @uid: the uid, or NULL +* @kuid: the kuid, INVALID_UID for "no id" (NULL, UID_R_NONE or -1) +* +* Return: 0, -EFAULT, or -EINVAL if the uid is malformed or has no mapping +* in @from. +*/ +int get_kuid_r (struct user_namespace *from, +const struct __kernel_uid_r __user *uid,kuid_t *kuid) +{ +struct __kernel_uid_r id; + + *kuid =INVALID_UID ; +if (!uid) +return 0 ; +if (copy_from_user (&id, uid,sizeof (id))) +return -EFAULT ; +if (kid_r_is_none (&id)) +return 0 ; + *kuid =make_kuid_r (from, &id); +return uid_valid (*kuid) ?0 : -EINVAL ; +} +EXPORT_SYMBOL (get_kuid_r); + +/** +* get_kgid_r - read a gid of a *_r system call from userspace +* @from: user namespace the gid is in +* @gid: the gid, or NULL +* @kgid: the kgid, INVALID_GID for "no id" (NULL, UID_R_NONE or -1) +* +* Return: 0, -EFAULT, or -EINVAL if the gid is malformed or has no mapping +* in @from. +*/ +int get_kgid_r (struct user_namespace *from, +const struct __kernel_uid_r __user *gid,kgid_t *kgid) +{ +struct __kernel_uid_r id; + + *kgid =INVALID_GID ;
kernel/uidgid_r.c line 243
Quoted 10 lines
kernel/uidgid_r.c new file +10
-0+if (!gid) +return 0 ; +if (copy_from_user (&id, gid,sizeof (id))) +return -EFAULT ; +if (kid_r_is_none (&id)) +return 0 ; + *kgid =make_kgid_r (from, &id); +return gid_valid (*kgid) ?0 : -EINVAL ; +} +EXPORT_SYMBOL (get_kgid_r);
[Severity: Medium]
What happens in get_kuid_r() and get_kgid_r() in kernel/uidgid_r.c when CONFIG_MULTIUSER is disabled?
kernel/Makefile builds uidgid_r.o unconditionally via obj-y. When userspace passes a malformed struct __kernel_uid_r (such as an unknown type, nonzero reserved bytes, a non-v4 UUID, or a nil GUID), make_kuid_r() and make_kgid_r() return INVALID_UID and INVALID_GID, and get_kuid_r() and get_kgid_r() then check uid_valid(*kuid) and gid_valid(*kgid).
In include/linux/uidgid.h, when !CONFIG_MULTIUSER, __kuid_val() and __kgid_val() unconditionally return 0:
static inline uid_t __kuid_val(kuid_t uid)
{
return 0;
}static inline bool uid_valid(kuid_t uid)
{
return !uid_is_legacy(uid) || __kuid_val(uid) != (uid_t) -1;
}Because __kuid_val(INVALID_UID) and __kgid_val(INVALID_GID) return 0 under !CONFIG_MULTIUSER, uid_valid(INVALID_UID) and gid_valid(INVALID_GID) always evaluate to true. Will this cause get_kuid_r() and get_kgid_r() to return 0 instead of -EINVAL for malformed IDs on !CONFIG_MULTIUSER builds?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
RFC PATCH v2 11/41 fscrypt: show the whole uid in the description of user key claims
In reply to Jan KoesterThe ".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.
--- fs/crypto/keyring.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/crypto/keyring.c +4 -3
@@ -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
[email protected]
AI reviewRe: [RFC PATCH v2 11/41] fscrypt: show the whole uid in the description of user key claims
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
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/keysshows who the claim belongs to. Lookups compare the kuid itself and are not affected.Assisted-by Claude:claude-opus-5-5Signed-off-by Jan Koester <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
RFC PATCH v2 12/41 keys: name per-user keyrings of UUID and GUID users by the whole uid
In reply to Jan KoesterThe 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.
--- 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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);
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 12/41] keys: name per-user keyrings of UUID and GUID users by the whole uid
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] keys: uid_valid() and gid_valid() break keyctl_chown_kid() on !MULTIUSER --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] keys: uid_valid() and gid_valid() break keyctl_chown_kid() on !MULTIUSER --
commit c0c4afc7a2fd311f54c5213f50fd53f5acbdc3b8
Author: Jan Koester <[email protected]>
keys: name per-user keyrings of UUID and GUID users by the whole uid
This commit names per-user and persistent keyrings of UUID and GUID users using kuid_str() instead of -1, passes the text form to request-key, and adds KEYCTL_CHOWN_R to support changing key ownership using __kernel_uid_r identifiers.
Quoted 93 lines
security/keys/keyctl.c +29
-16@@ -946,26 +946,17 @@ long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)* * If successful, 0 will be returned. */ -long keyctl_chown_key (key_serial_t id,uid_t user,gid_t group) +static long keyctl_chown_kid (key_serial_t id,kuid_t uid,kgid_t gid) {struct key_user *newowner, *zapowner =NULL ;struct key *key;key_ref_t key_ref;long ret; -kuid_t uid; -kgid_t gid;unsigned long flags; - uid =make_kuid (current_user_ns (), user); - gid =make_kgid (current_user_ns (), group); - ret = -EINVAL ; -if ((user != (uid_t) -1 ) && !uid_valid (uid)) - goto error; -if ((group != (gid_t) -1 ) && !gid_valid (gid)) - goto error; - +/* invalid ids leave the owner or group unchanged */ ret =0 ; -if (user == (uid_t) -1 && group == (gid_t) -1 ) +if (!uid_valid (uid) && !gid_valid (gid)) goto error; key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL,@@ -985,12 +976,12 @@ long keyctl_chown_key(key_serial_t id, uid_t user, gid_t group)bool is_privileged_op = false;/* only the sysadmin can chown a key to some other UID */ -if (user != (uid_t) -1 && !uid_eq (key->uid, uid)) +if (uid_valid (uid) && !uid_eq (key->uid, uid)) is_privileged_op = true;/* only the sysadmin can set the key's GID to a group other * than one of those that the current process subscribes to */ -if (group != (gid_t) -1 && !gid_eq (gid, key->gid) && !in_group_p (gid)) +if (gid_valid (gid) && !gid_eq (gid, key->gid) && !in_group_p (gid)) is_privileged_op = true;if (is_privileged_op && !capable (CAP_SYS_ADMIN ))@@ -998,7 +989,7 @@ long keyctl_chown_key(key_serial_t id, uid_t user, gid_t group) }/* change the UID */ -if (user != (uid_t) -1 && !uid_eq (uid, key->uid)) { +if (uid_valid (uid) && !uid_eq (uid, key->uid)) { ret = -ENOMEM ; newowner =key_user_lookup (uid);if (!newowner)@@ -1042,7 +1033,7 @@ long keyctl_chown_key(key_serial_t id, uid_t user, gid_t group) }/* change the GID */ -if (group != (gid_t) -1 ) +if (gid_valid (gid)) key->gid = gid;notify_key (key,NOTIFY_KEY_SETATTR ,0 );@@ -1063,6 +1054,39 @@ long keyctl_chown_key(key_serial_t id, uid_t user, gid_t group) goto error_put; } +long keyctl_chown_key (key_serial_t id,uid_t user,gid_t group) +{ +kuid_t uid =make_kuid (current_user_ns (), user); +kgid_t gid =make_kgid (current_user_ns (), group); + +if ((user != (uid_t) -1 ) && !uid_valid (uid)) +return -EINVAL ; +if ((group != (gid_t) -1 ) && !gid_valid (gid)) +return -EINVAL ; +return keyctl_chown_kid (id, uid, gid); +} + +/* +* KEYCTL_CHOWN with __kernel_uid_r_t ids, which can be UUIDs and GUIDs. A +* NULL pointer, UID_R_NONE or a classic -1 leave the owner or group +* unchanged. +*/ +long keyctl_chown_key_r (key_serial_t id, +const struct __kernel_uid_r __user *user, +const struct __kernel_uid_r __user *group) +{ +kuid_t uid;
security/keys/keyctl.c long keyctl_chown_key(key_serial_t id, uid_t user, gid_t group) · line 1088
Quoted 10 lines
security/keys/keyctl.c +10
-0+kgid_t gid; +long ret; + + ret =get_kuid_r (current_user_ns (), user, &uid); +if (!ret) + ret =get_kgid_r (current_user_ns (), group, &gid); +if (ret) +return ret; +return keyctl_chown_kid (id, uid, gid); +}
[Severity: Medium]
Does replacing the explicit (uid_t)-1 and (gid_t)-1 checks in security/keys/keyctl.c:keyctl_chown_kid() with uid_valid() and gid_valid() introduce a regression when CONFIG_MULTIUSER is disabled?
In include/linux/uidgid.h, when CONFIG_MULTIUSER is not enabled, __kuid_val() and __kgid_val() unconditionally return 0:
#ifdef CONFIG_MULTIUSER
...
#else
static inline uid_t __kuid_val(kuid_t uid)
{
return 0;
}
static inline gid_t __kgid_val(kgid_t gid)
{
return 0;
}
#endif
static inline bool uid_valid(kuid_t uid)
{
return !uid_is_legacy(uid) || __kuid_val(uid) != (uid_t) -1;
}
static inline bool gid_valid(kgid_t gid)
{
return !gid_is_legacy(gid) || __kgid_val(gid) != (gid_t) -1;
}Because INVALID_UID and INVALID_GID have type KID_LEGACY and __kuid_val() / __kgid_val() return 0 under !CONFIG_MULTIUSER, uid_valid(INVALID_UID) and gid_valid(INVALID_GID) always evaluate to true.
When userspace invokes keyctl(KEYCTL_CHOWN) or keyctl(KEYCTL_CHOWN_R) on a kernel built with CONFIG_KEYS=y and CONFIG_MULTIUSER=n:
1. Calling keyctl_chown_key() with user == -1 and group == -1, or calling keyctl_chown_key_r() with NULL, UID_R_NONE, or -1 for both arguments, passes INVALID_UID and INVALID_GID into keyctl_chown_kid(). Because !uid_valid(uid) && !gid_valid(gid) is false, the no-op early return is skipped. It then calls lookup_user_key() with KEY_LOOKUP_CREATE (which can allocate a keyring or fail with -ENOKEY or -EACCES), overwrites key->gid with INVALID_GID, and posts a spurious NOTIFY_KEY_SETATTR watch notification.
2. Calling keyctl_chown_key() or keyctl_chown_key_r() to change only the owner while leaving the group unchanged (-1, NULL, or UID_R_NONE) passes gid = INVALID_GID into keyctl_chown_kid(), where if (gid_valid(gid)) evaluates to true and clobbers key->gid with INVALID_GID.
3. In keyctl_chown_key_r() -> get_kuid_r() / get_kgid_r() in kernel/uidgid_r.c:
*kuid = make_kuid_r(from, &id);
return uid_valid(*kuid) ? 0 : -EINVAL; Malformed __kernel_uid_r inputs that cause make_kuid_r() or make_kgid_r() to return INVALID_UID or INVALID_GID will pass the uid_valid() / gid_valid() check and return 0 instead of -EINVAL.
Would it make sense for uid_valid() and gid_valid() (or __kuid_val() and __kgid_val()) to preserve the -1 check for INVALID_UID and INVALID_GID when !CONFIG_MULTIUSER, or to check for unchanged IDs explicitly?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
RFC PATCH v2 13/41 ublk: refuse unprivileged devices to UUID and GUID users
In reply to Jan KoesterThe 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.
--- drivers/block/ublk_drv.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/block/ublk_drv.c +12 -5
@@ -1324,7 +1324,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;
@@ -1334,6 +1339,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)
@@ -1355,9 +1361,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 ; }
@@ -4744,7 +4749,9 @@ static int ublk_ctrl_add_dev(const struct ublksrv_ctrl_cmd *header) }/* 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",
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 13/41] ublk: refuse unprivileged devices to UUID and GUID users
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
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-5Signed-off-by Jan Koester <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
RFC PATCH v2 14/41 nfsd: don't hand out uid 0 for read layouts of UUID-owned files
In reply to Jan KoesterRead-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.
--- fs/nfsd/flexfilelayout.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/nfsd/flexfilelayout.c +5 -1
@@ -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;
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 14/41] nfsd: don't hand out uid 0 for read layouts of UUID-owned files
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
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-5Signed-off-by Jan Koester <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
RFC PATCH v2 15/41 SUNRPC: name UUID and GUID users to gssd as uid_r=
In reply to Jan Koestergssd 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.
--- net/sunrpc/auth_gss/auth_gss.c | 44 +++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-)
net/sunrpc/auth_gss/auth_gss.c +41 -3
@@ -18,6 +18,7 @@#include <linux/sched.h> #include <linux/pagemap.h> #include <linux/sunrpc/clnt.h> +#include <linux/uidgid_r.h> #include <linux/sunrpc/auth.h> #include <linux/sunrpc/auth_gss.h> #include <linux/sunrpc/gss_krb5.h>
@@ -438,10 +439,23 @@ static int gss_encode_v1_msg(struct gss_upcall_msg *gss_msg,struct gss_api_mech *mech = gss_msg->auth->mech;char *p = gss_msg->databuf;size_t buflen =sizeof (gss_msg->databuf); +char idbuf[KID_STR_LEN ];int len; - len =scnprintf (p, buflen,"mech=%s uid=%d" , mech->gm_name, -from_kuid_munged (userns, gss_msg->uid)); +/* +* A UUID or GUID user is uid_r= in its text form instead of uid=, +* which gssd versions that don't know it reject rather than taking +* an overflow uid. Where gssd can't see the user at all, there is +* neither, and the upcall fails. +*/ +if (uid_is_legacy (gss_msg->uid)) + len =scnprintf (p, buflen,"mech=%s uid=%d" , mech->gm_name, +from_kuid_munged (userns, gss_msg->uid)); +else if (kuid_has_mapping (userns, gss_msg->uid)) + len =scnprintf (p, buflen,"mech=%s uid_r=%s" , mech->gm_name, +kuid_str (gss_msg->uid, idbuf)); +else + len =scnprintf (p, buflen,"mech=%s" , mech->gm_name); buflen -= len; p += len; gss_msg->msg.len = len;
@@ -536,6 +550,15 @@ gss_alloc_msg(struct gss_auth *gss_auth, err = vers;if (err <0 ) goto err_free_msg; +/* +* The binary v0 upcall is a 32 bit uid: UUID and GUID users would +* all be the overflow uid there and share its credentials. +*/ +if (vers ==0 && !uid_is_legacy (uid)) { +put_pipe_version (gss_auth->net); + err = -EACCES ; + goto err_free_msg; + } gss_msg->pipe = gss_auth->gss_pipe[vers]->pipe;INIT_LIST_HEAD (&gss_msg->list);rpc_init_wait_queue (&gss_msg->rpc_waitqueue,"RPCSEC_GSS upcall waitq" );
@@ -752,7 +775,22 @@ gss_pipe_downcall(struct file *filp, const char __user *src, size_t mlen) goto err; } - uid =make_kuid (current_user_ns (), id); +/* +* A uid of -1, never valid, is followed by a __kernel_uid_r_t: the +* reply to a uid_r= upcall of a UUID or GUID user. +*/ +if (id == (uid_t)-1 ) { +struct __kernel_uid_r id_r; + + p =simple_get_bytes (p, end, &id_r,sizeof (id_r)); +if (IS_ERR (p)) { + err =PTR_ERR (p); + goto err; + } + uid =make_kuid_r (current_user_ns (), &id_r); + }else { + uid =make_kuid (current_user_ns (), id); + }if (!uid_valid (uid)) { err = -EINVAL ; goto err;
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 15/41] SUNRPC: name UUID and GUID users to gssd as uid_r=
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] sunrpc: hang and leaked upcall in gss_encode_v1_msg() when uid= is omitted --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] sunrpc: hang and leaked upcall in gss_encode_v1_msg() when uid= is omitted --
commit ca819aaf8bcc6fad14f1ba4a44164f940c6b1b37
Author: Jan Koester <[email protected]>
SUNRPC: name UUID and GUID users to gssd as uid_r=
This commit updates RPCSEC_GSS v1 text upcalls to pass non-legacy user IDs using the uid_r= key and extends gss_pipe_downcall() to accept a __kernel_uid_r payload following a sentinel uid of -1. It also rejects binary v0 upcalls for non-legacy user IDs with -EACCES.
Quoted 25 lines
net/sunrpc/auth_gss/auth_gss.c +6
-2@@ -18,6 +18,7 @@#include <linux/sched.h> #include <linux/pagemap.h> #include <linux/sunrpc/clnt.h> +#include <linux/uidgid_r.h> #include <linux/sunrpc/auth.h> #include <linux/sunrpc/auth_gss.h> #include <linux/sunrpc/gss_krb5.h> @@ -438,10 +439,23 @@ static int gss_encode_v1_msg(struct gss_upcall_msg *gss_msg,struct gss_api_mech *mech = gss_msg->auth->mech;char *p = gss_msg->databuf;size_t buflen =sizeof (gss_msg->databuf); +char idbuf[KID_STR_LEN ];int len; - len =scnprintf (p, buflen,"mech=%s uid=%d" , mech->gm_name, -from_kuid_munged (userns, gss_msg->uid)); +/* +* A UUID or GUID user is uid_r= in its text form instead of uid=, +* which gssd versions that don't know it reject rather than taking +* an overflow uid. Where gssd can't see the user at all, there is
net/sunrpc/auth_gss/auth_gss.c static int gss_encode_v1_msg(struct gss_upcall_msg *gss_msg, · line 458
Quoted 10 lines
net/sunrpc/auth_gss/auth_gss.c +10
-0+* neither, and the upcall fails. +*/ +if (uid_is_legacy (gss_msg->uid)) + len =scnprintf (p, buflen,"mech=%s uid=%d" , mech->gm_name, +from_kuid_munged (userns, gss_msg->uid)); +else if (kuid_has_mapping (userns, gss_msg->uid)) + len =scnprintf (p, buflen,"mech=%s uid_r=%s" , mech->gm_name, +kuid_str (gss_msg->uid, idbuf)); +else + len =scnprintf (p, buflen,"mech=%s" , mech->gm_name);
[Severity: High]
When gssd reads from the v1 pipe via rpc_pipe_read() -> gss_v1_upcall() -> gss_encode_v1_msg(), all three branches return 0 and deliver the upcall text to userspace with msg->errno == 0.
When rpc_pipe_read() then calls gss_pipe_destroy_msg(), gss_msg is only unhashed from pipe->in_downcall if msg->errno < 0:
net/sunrpc/auth_gss/auth_gss.c:gss_pipe_destroy_msg() {
...
if (msg->errno < 0) {
refcount_inc(&gss_msg->count);
gss_unhash_msg(gss_msg);
if (msg->errno == -ETIMEDOUT)
warn_gssd();
gss_release_msg(gss_msg);
}
gss_release_msg(gss_msg);
}Because msg->errno is 0, gss_msg stays on pipe->in_downcall waiting for a downcall. However, gss_pipe_downcall() matches downcalls to pending upcalls on pipe->in_downcall solely by uid in gss_find_downcall():
net/sunrpc/auth_gss/auth_gss.c:gss_find_downcall() {
struct gss_upcall_msg *pos;
list_for_each_entry(pos, &pipe->in_downcall, list) {
if (!uid_eq(pos->uid, uid))
continue;
...
}When !kuid_has_mapping(userns, gss_msg->uid), gss_encode_v1_msg() emits only "mech=%s" without uid= or uid_r=, so gssd is given no user id with which to construct a matching downcall (and in a non-initial user namespace, make_kuid_r() in gss_pipe_downcall() also rejects the namespace). Likewise, an older gssd that does not recognize uid_r= cannot write a __kernel_uid_r downcall that matches the non-legacy pos->uid in gss_find_downcall().
With no matching downcall possible to unhash gss_msg or set gss_msg->msg.errno, won't callers in gss_create_upcall() sleep forever in the wait loop:
net/sunrpc/auth_gss/auth_gss.c:gss_create_upcall() {
...
for (;;) {
prepare_to_wait(&gss_msg->waitqueue, &wait, TASK_KILLABLE);
spin_lock(&pipe->lock);
if (gss_msg->ctx != NULL || gss_msg->msg.errno < 0) {
break;
}
spin_unlock(&pipe->lock);
if (fatal_signal_pending(current)) {
err = -ERESTARTSYS;
goto out_intr;
}
schedule();
}
}while leaving gss_msg (along with its references to gss_auth->kref and sn->pipe_users) stranded on pipe->in_downcall until the pipe is closed, causing subsequent upcalls for the same user to coalesce onto the dead gss_msg in gss_add_msg() and hang as well?
Quoted 3 lines
net/sunrpc/auth_gss/auth_gss.c +0
-0buflen -= len; p += len; gss_msg->msg.len = len;
[ ... ]
Quoted 1 line
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
RFC PATCH v2 16/41 ecryptfs: hash daemons by kuid_hash()
In reply to Jan KoesterThe 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().
--- fs/ecryptfs/messaging.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ecryptfs/messaging.c +1 -1
@@ -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;
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 16/41] ecryptfs: hash daemons by kuid_hash()
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
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; usekuid_hash().Assisted-by Claude:claude-opus-5-5Signed-off-by Jan Koester <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=16
RFC PATCH v2 17/41 quota: don't account UUID and GUID owners
In reply to Jan KoesterQuota 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.
--- fs/quota/dquot.c | 3 +++ include/linux/quota.h | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+)
fs/quota/dquot.c +3 -0
@@ -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
@@ -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
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 17/41] quota: don't account UUID and GUID owners
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] quota: dqget() checks qid_has_mapping() before qid_is_legacy() - [High] quota: stale dquot…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] quota: dqget() checks qid_has_mapping() before qid_is_legacy()
- [High] quota: stale dquot retention in dquot_transfer() for UUID and GUID owners
- [Medium] quota: dquot_initialize_needed() stays true for UUID and GUID owners --
commit 56b2ebaac3515c69a008f64fd7b2eb53fda044a8
Author: Jan Koester <[email protected]>
quota: don't account UUID and GUID owners
This commit adds a qid_is_legacy() helper and updates dqget() to return -ESRCH for UUID and GUID owners so that non-legacy 128-bit identifiers are not accounted in 32-bit quota files.
Quoted 5 lines
fs/quota/dquot.c +0
-0
fs/quota/dquot.c struct dquot *dqget(struct super_block *sb, struct kqid qid) · line 962
Quoted 9 lines
fs/quota/dquot.c +3
-0@@ -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 );
[Severity: High]
Can the !qid_is_legacy(qid) check here ever be reached for a UUID or GUID owner?
Prior to this check, dqget() calls qid_has_mapping(sb->s_user_ns, qid):
include/linux/quota.h:qid_has_mapping()
return from_kqid(ns, qid) != (qid_t) -1;
from_kqid() delegates to from_kuid() and from_kgid(), which unconditionally return (uid_t)-1 and (gid_t)-1 for non-legacy identifiers even in init_user_ns:
kernel/user_namespace.c:from_kuid()
if (!uid_is_legacy(kuid)) return (uid_t) -1;
Because qid_has_mapping() always returns false for UUID and GUID owners, dqget() returns ERR_PTR(-EINVAL) before reaching !qid_is_legacy(qid). Callers such as __dquot_initialize() and dquot_transfer() only treat -ESRCH as non-fatal and propagate -EINVAL, causing file creation, open for write, and ownership changes involving UUID or GUID owners to fail on quota-enabled filesystems.
Should the !qid_is_legacy(qid) check be placed before qid_has_mapping()?
[Severity: High]
When an inode is chowned from a legacy 32-bit owner to a UUID or GUID owner, will leaving the inode charged to the previous owner in dquot_transfer() leak quota accounting once the inode is evicted from the icache?
In dquot_transfer() -> __dquot_transfer(), returning -ESRCH from dqget() sets transfer_to[cnt] = NULL:
fs/quota/dquot.c:__dquot_transfer()
for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
/*
* Skip changes for same uid or gid or for turned off quota-type.
*/
if (!transfer_to[cnt])
continue;This skips uncharging transfer_from[cnt] and leaves i_dquot(inode)[cnt] pointing to the previous owner's dquot while inode->i_uid or inode->i_gid is updated to the UUID or GUID.
While the inode remains cached, subsequent block allocations by the new owner are still charged to the previous owner's dquot via __dquot_alloc_space() and can fail with -EDQUOT against the previous owner's limits.
Once the inode is evicted from memory, dquot_drop() -> __dquot_drop() drops the in-memory i_dquot(inode)[cnt] reference without uncharging the quota. When the inode is later re-read from disk, __dquot_initialize() sees the UUID or GUID owner and leaves i_dquot(inode)[cnt] as NULL. Subsequent truncation or unlink (__dquot_free_space(), dquot_free_inode()) will then never decrement the previous owner's dquot, permanently leaking those blocks and inodes in the on-disk quota file (or double-charging if chowned back to a legacy owner).
Should __dquot_transfer() uncharge transfer_from[cnt] and clear dquots[cnt] when transferring ownership to an unquoted UUID or GUID owner?
[Severity: Medium]
How does returning -ESRCH for UUID and GUID owners interact with dquot_initialize_needed()?
When dqget() returns -ESRCH while sb_has_quota_active(sb, qid.type) is true, __dquot_initialize() leaves i_dquot(inode)[cnt] as NULL. However, dquot_initialize_needed() (as well as dqinit_needed()) assumes that any NULL slot for an active quota type means the inode still needs quota initialization:
fs/quota/dquot.c:dquot_initialize_needed()
dquots = i_dquot(inode); for (i = 0; i < MAXQUOTAS; i++) if (!dquots[i] && sb_has_quota_active(inode->i_sb, i)) return true;
For an inode with a UUID or GUID owner or group, dquot_initialize_needed() remains permanently true even after dquot_initialize() has been called.
In ext4, this causes __ext4_expand_extra_isize() to always bail out with -EAGAIN:
fs/ext4/inode.c:__ext4_expand_extra_isize()
if (dquot_initialize_needed(inode)) return -EAGAIN;
It also triggers WARN_ON_ONCE(dquot_initialize_needed(inode)) in ext4_xattr_block_set() when EXT4_XATTR_DEBUG is enabled, and causes every call to __dquot_initialize() on the inode to bypass the fast path and acquire dq_data_lock.
Should dquot_initialize_needed(), dqinit_needed(), and the loop in __dquot_initialize() also account for non-legacy identifiers?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
RFC PATCH v2 18/41 fs: keep UUID and GUID owners off filesystems that can't store them
In reply to Jan KoesterFilesystems 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.
--- 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
@@ -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
@@ -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
@@ -352,5 +352,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 */
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 18/41] fs: keep UUID and GUID owners off filesystems that can't store them
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] fs: vfs_rename() with RENAME_WHITEOUT skips fsuidgid_has_mapping() when target exists - [Medium]…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] fs: vfs_rename() with RENAME_WHITEOUT skips fsuidgid_has_mapping() when target exists
- [Medium] fs: UUID/GUID owner check bypassed in ocfs2_may_create() and f2fs atomic write --
commit 3d0ae6a640c537e68d1d11095789815bcc76e4cd
Author: Jan Koester <[email protected]>
fs: keep UUID and GUID owners off filesystems that can't store them
This commit adds the SB_I_UID_R superblock flag for filesystems that can store UUID and GUID inode owners, and updates notify_change() and fsuidgid_has_mapping() to reject UUID and GUID owners on filesystems without that flag.
Quoted 43 lines
include/linux/fs.h +23
-2@@ -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. */
include/linux/fs.h static inline bool fsuidgid_has_mapping(struct super_block *sb, · line 1607
Quoted 6 lines
include/linux/fs.h +1
-1@@ -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;
[Severity: High]
Can a caller with a UUID or GUID fsuid or fsgid bypass fsuidgid_has_mapping() during a whiteout rename when the target dentry already exists?
In fs/namei.c, sys_renameat2() -> filename_renameat2() -> vfs_rename() only calls may_create_dentry() (which checks fsuidgid_has_mapping()) when target is NULL:
fs/namei.c:vfs_rename() {
...
if (!target) {
error = may_create_dentry(rd->mnt_idmap, new_dir, new_dentry);
} else {
new_is_dir = d_is_dir(new_dentry);
if (!(flags & RENAME_EXCHANGE))
error = may_delete_dentry(rd->mnt_idmap, new_dir,
new_dentry, is_dir);
else
error = may_delete_dentry(rd->mnt_idmap, new_dir,
new_dentry, new_is_dir);
}
...
}When target is non-NULL and flags includes RENAME_WHITEOUT, vfs_rename() only calls may_delete_dentry() on old_dentry and new_dentry, which validates the existing victim inodes and directory permissions without checking fsuidgid_has_mapping(old_dir->i_sb, rd->mnt_idmap).
vfs_rename() then invokes old_dir->i_op->rename(..., RENAME_WHITEOUT), which allocates a new whiteout inode in old_dir and initializes its i_uid and i_gid from current_fsuid() and current_fsgid() via inode_init_owner(), such as in fs/ext4/namei.c:
fs/ext4/namei.c:ext4_rename() {
...
if (!(flags & RENAME_WHITEOUT)) {
handle = ext4_journal_start(old.dir, EXT4_HT_DIR, credits);
if (IS_ERR(handle)) {
retval = PTR_ERR(handle);
goto release_bh;
}
} else {
whiteout = ext4_whiteout_for_rename(idmap, &old, credits, &handle);
if (IS_ERR(whiteout)) {
retval = PTR_ERR(whiteout);
goto release_bh;
}
}
...
}The same whiteout creation occurs in ext4_rename() -> ext4_whiteout_for_rename() -> __ext4_new_inode(), btrfs_rename() -> new_whiteout_inode(), f2fs_rename() -> f2fs_create_whiteout(), and xfs_rename() -> xfs_rename_alloc_whiteout().
On filesystems without SB_I_UID_R (such as btrfs, f2fs, xfs, ubifs, and ext4 prior to the later commit "ext4: add the uid_r feature for UUID and GUID owners"), the whiteout inode's owner is written to disk via i_uid_read() and i_gid_read() as (uid_t)-1 / (gid_t)-1 (0xffffffff). When read back from disk, that becomes INVALID_UID / INVALID_GID and leaves the whiteout entry undeletable because may_delete_dentry() rejects inodes with invalid vfsuid or vfsgid with -EOVERFLOW.
Additionally, once the later commit "ext4: add the uid_r feature for UUID and GUID owners" is applied, __ext4_new_inode() -> ext4_mark_inode_dirty() -> ext4_do_update_inode() -> ext4_fill_raw_inode() -> ext4_inode_set_id_r() fails with -EOVERFLOW on an ext4 filesystem without the uid_r feature and calls EXT4_ERROR_INODE() and ext4_std_error(), aborting the journal and remounting the filesystem read-only (or panicking when mounted with errors=panic).
Should vfs_rename() also check fsuidgid_has_mapping(old_dir->i_sb, rd->mnt_idmap) when flags & RENAME_WHITEOUT is set?
include/linux/fs.h static inline bool fsuidgid_has_mapping(struct super_block *sb, · line 1610
Quoted 4 lines
include/linux/fs.h +1
-1kgid =mapped_fsgid (idmap, fs_userns); -if (!gid_valid (kgid)) +if (!gid_valid (kgid) || !sb_can_own_kgid (sb, kgid))return false;
[Severity: Medium]
Are there also filesystem-internal inode creation paths that initialize new inodes with inode_init_owner() without going through fsuidgid_has_mapping()?
Because sb_can_own_kuid() and sb_can_own_kgid() are only checked in fsuidgid_has_mapping() (called by may_create_dentry(), may_o_create(), and vfs_tmpfile()), callers that allocate new inodes through private helpers skip this check:
1. In fs/ocfs2/refcounttree.c, ioctl(OCFS2_IOC_REFLINK) -> ocfs2_reflink_ioctl() -> ocfs2_vfs_reflink() checks permissions with ocfs2_may_create() rather than may_create_dentry():
fs/ocfs2/refcounttree.c:ocfs2_may_create() {
if (d_really_is_positive(child))
return -EEXIST;
if (IS_DEADDIR(dir))
return -ENOENT;
return inode_permission(&nop_mnt_idmap, dir, MAY_WRITE | MAY_EXEC);
}When preserve is false, a caller with a UUID or GUID fsuid or fsgid creates a new inode via ocfs2_reflink() -> ocfs2_create_inode_in_orphan() -> ocfs2_get_init_inode() -> inode_init_owner() in fs/ocfs2/namei.c. __ocfs2_mknod_locked() then writes i_uid_read(inode) and i_gid_read(inode) as -1 to fe->i_uid and fe->i_gid on disk and calls ocfs2_populate_inode(), which sets the in-memory inode's i_uid and i_gid to INVALID_UID and INVALID_GID before ocfs2_mv_orphaned_inode_to_new() links it into the target directory.
2. In fs/f2fs/file.c, f2fs_ioc_start_atomic_write() checks inode_owner_or_capable() (which does not check fsgid, and permits a UUID or GUID fsuid if the caller has CAP_FOWNER) and then allocates a COW inode via f2fs_get_tmpfile() -> __f2fs_tmpfile() -> f2fs_new_inode() -> inode_init_owner() without calling vfs_tmpfile() or fsuidgid_has_mapping():
fs/f2fs/file.c:f2fs_ioc_start_atomic_write() {
...
if (fi->cow_inode == NULL) {
struct dentry *dentry = file_dentry(filp);
struct inode *dir = d_inode(dentry->d_parent);
ret = f2fs_get_tmpfile(idmap, dir, &fi->cow_inode);
...
}This causes f2fs_update_inode() to write (uid_t)-1 / (gid_t)-1 to the on-disk COW inode.
Should ocfs2_may_create() and f2fs_ioc_start_atomic_write() (or the common inode allocation path) also verify fsuidgid_has_mapping()?
Quoted 2 lines
include/linux/fs.h +0
-0return kuid_has_mapping (fs_userns, kuid) &&kgid_has_mapping (fs_userns, kgid);
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=18
RFC PATCH v2 19/41 cred: add the *_r variants of the get/set*id() system calls
In reply to Jan KoesterAdd 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.
--- 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
@@ -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 ;
@@ -967,6 +968,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
@@ -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);
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 19/41] cred: add the *_r variants of the get/set*id() system calls
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] cred: setfsuid_r() and setfsgid_r() commit creds before copying old id --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] cred: setfsuid_r() and setfsgid_r() commit creds before copying old id --
commit ce14b103e65ee744fe87b48cff6d5ebb9dda8c50
Author: Jan Koester <[email protected]>
cred: add the *_r variants of the get/set*id() system calls
This patch adds *_r variants of the get/set*id() system calls that accept and return pointers to __kernel_uid_r so processes can use UUID or GUID user and group identifiers. It also splits the classic syscall implementations into argument conversion helpers and shared do_*() functions operating on kuid_t and kgid_t.
Quoted 4 lines
kernel/sys.c +0
-0
[ ... ]
Quoted 49 lines
kernel/sys.c +15
-15@@ -901,40 +933,44 @@ SYSCALL_DEFINE3(getresgid, gid_t __user *, rgidp, gid_t __user *, egidp, gid_t _* whatever uid it wants to). It normally shadows "euid", except when * explicitly set by setfsuid() or for access.. */ -long __sys_setfsuid (uid_t uid) +/* +* Sets the fsuid to @kuid, unless it is invalid; 0 or -EPERM. The fsuid +* before the call goes to @old. +*/ +static long do_setfsuid (kuid_t kuid,kuid_t *old_fsuid) {const struct cred *old;struct cred *new; -uid_t old_fsuid; -kuid_t kuid; old =current_cred (); - old_fsuid =from_kuid_munged (old->user_ns, old->fsuid); + *old_fsuid = old->fsuid; - kuid =make_kuid (old->user_ns, uid); -if (!uid_valid (kuid)) -return old_fsuid; +if (!uid_valid (kuid) ||uid_eq (kuid, old->fsuid)) +return 0 ; new =prepare_creds ();if (!new) -return old_fsuid; +return -ENOMEM ;if (uid_eq (kuid, old->uid) ||uid_eq (kuid, old->euid) || -uid_eq (kuid, old->suid) ||uid_eq (kuid, old->fsuid) || +uid_eq (kuid, old->suid) ||ns_capable_setid (old->user_ns,CAP_SETUID )) { -if (!uid_eq (kuid, old->fsuid)) { - new->fsuid = kuid; -if (security_task_fix_setuid (new, old,LSM_SETID_FS ) ==0 ) - goto change_okay; - } + new->fsuid = kuid; +if (security_task_fix_setuid (new, old,LSM_SETID_FS ) ==0 ) +return commit_creds (new); }abort_creds (new); -return old_fsuid; +return -EPERM ; +}
[ ... ]
Quoted 49 lines
kernel/sys.c +15
-15@@ -945,46 +981,214 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)/* * Samma på svenska.. */ -long __sys_setfsgid (gid_t gid) +/* +* Sets the fsgid to @kgid, unless it is invalid; 0 or -EPERM. The fsgid +* before the call goes to @old. +*/ +static long do_setfsgid (kgid_t kgid,kgid_t *old_fsgid) {const struct cred *old;struct cred *new; -gid_t old_fsgid; -kgid_t kgid; old =current_cred (); - old_fsgid =from_kgid_munged (old->user_ns, old->fsgid); + *old_fsgid = old->fsgid; - kgid =make_kgid (old->user_ns, gid); -if (!gid_valid (kgid)) -return old_fsgid; +if (!gid_valid (kgid) ||gid_eq (kgid, old->fsgid)) +return 0 ; new =prepare_creds ();if (!new) -return old_fsgid; +return -ENOMEM ;if (gid_eq (kgid, old->gid) ||gid_eq (kgid, old->egid) || -gid_eq (kgid, old->sgid) ||gid_eq (kgid, old->fsgid) || +gid_eq (kgid, old->sgid) ||ns_capable_setid (old->user_ns,CAP_SETGID )) { -if (!gid_eq (kgid, old->fsgid)) { - new->fsgid = kgid; -if (security_task_fix_setgid (new,old,LSM_SETID_FS ) ==0 ) - goto change_okay; - } + new->fsgid = kgid; +if (security_task_fix_setgid (new, old,LSM_SETID_FS ) ==0 ) +return commit_creds (new); }abort_creds (new); -return old_fsgid; +return -EPERM ; +}
[ ... ]
Quoted 27 lines
kernel/sys.c +27
-0+/* +* Unlike setfsuid(), which returns the old fsuid whatever happens, +* setfsuid_r() reports failure: 0, or -EPERM if the caller may not use +* @uid. The fsuid before the call goes to @old_uid unless it is NULL; a +* NULL @uid only queries it. +*/ +SYSCALL_DEFINE2(setfsuid_r, const struct __kernel_uid_r __user *, uid, + struct __kernel_uid_r __user *, old_uid) +{ +struct user_namespace *ns =current_user_ns (); +kuid_t kuid, old_fsuid; +int err; + + err =get_kuid_r (ns, uid, &kuid); +if (err) +return err; + err =do_setfsuid (kuid, &old_fsuid); +if (!err && old_uid) + err =put_kuid_r (ns, old_fsuid, old_uid); +return err; +} + +SYSCALL_DEFINE2(setfsgid_r, const struct __kernel_uid_r __user *, gid, + struct __kernel_uid_r __user *, old_gid) +{ +struct user_namespace *ns =current_user_ns (); +kgid_t kgid, old_fsgid;
kernel/sys.c SYSCALL_DEFINE1(setfsuid, uid_t, uid) · line 1191
Quoted 10 lines
kernel/sys.c +10
-0+int err; + + err =get_kgid_r (ns, gid, &kgid); +if (err) +return err; + err =do_setfsgid (kgid, &old_fsgid); +if (!err && old_gid) + err =put_kgid_r (ns, old_fsgid, old_gid); +return err; +}
[Severity: Medium]
In kernel/sys.c, if a caller invokes setfsuid_r() or setfsgid_r() with a valid, permitted uid or gid that differs from the current fsuid or fsgid and passes a non-NULL old_uid or old_gid pointer that faults during copy_to_user(), will the syscall return -EFAULT after the new credentials have already been irreversibly installed?
Specifically, setfsuid_r() calls do_setfsuid(), which updates new->fsuid, runs security_task_fix_setuid(new, old, LSM_SETID_FS), and calls commit_creds(new) before put_kuid_r() copies old_fsuid to old_uid (and similarly for setfsgid_r(), do_setfsgid(), and put_kgid_r()).
If copy_to_user() inside put_kuid_r() or put_kgid_r() fails, the task is left with its mutated fsuid or fsgid, altered filesystem capabilities, updated dumpability, and updated thread keyrings even though the syscall reports failure and the previous ID is lost. Could old_fsuid and old_fsgid be copied to userspace before committing the new credentials?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=19
RFC PATCH v2 20/41 groups: add getgroups_r() and setgroups_r()
In reply to Jan KoesterSupplementary 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.
--- 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
@@ -994,6 +994,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
@@ -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);
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 20/41] groups: add getgroups_r() and setgroups_r()
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
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-5Signed-off-by Jan Koester <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=20
RFC PATCH v2 21/41 fs: add chown_r(), lchown_r(), fchown_r() and fchownat_r()
In reply to Jan KoesterThe 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.
--- fs/open.c | 144 +++++++++++++++++++++++++++++++++++---- include/linux/syscalls.h | 13 ++++ 2 files changed, 145 insertions(+), 12 deletions(-)
fs/open.c +132 -12
@@ -785,7 +785,46 @@ static inline bool setattr_vfsgid(struct iattr *attr, kgid_t kgid)return true; } -int chown_common (const struct path *path,uid_t user,gid_t group) +/* +* The new owner and group of a chown. Invalid ids stand for "unchanged"; +* @err is an error of their conversion, reported once the path is found, +* which keeps the classic calls' order of errors. +*/ +struct chown_ids { +kuid_t uid; +kgid_t gid; +int err; +}; + +static struct chown_ids chown_ids_classic (uid_t user,gid_t group) +{ +struct user_namespace *ns =current_user_ns (); +struct chown_ids ids = { + .uid =make_kuid (ns, user), + .gid =make_kgid (ns, group), + }; + +if ((user != (uid_t)-1 && !uid_valid (ids.uid)) || + (group != (gid_t)-1 && !gid_valid (ids.gid))) + ids.err = -EINVAL ; +return ids; +} + +static int chown_ids_r (const struct __kernel_uid_r __user *user, +const struct __kernel_uid_r __user *group, +struct chown_ids *ids) +{ +struct user_namespace *ns =current_user_ns (); +int err; + + ids->err =0 ; + err =get_kuid_r (ns, user, &ids->uid); +if (!err) + err =get_kgid_r (ns, group, &ids->gid); +return err; +} + +static int chown_path (const struct path *path,const struct chown_ids *ids) {struct mnt_idmap *idmap;struct user_namespace *fs_userns;
@@ -793,11 +832,9 @@ int chown_common(const struct path *path, uid_t user, gid_t group)struct delegated_inode delegated_inode = { };int error;struct iattr newattrs; -kuid_t uid; -kgid_t gid; - uid =make_kuid (current_user_ns (), user); - gid =make_kgid (current_user_ns (), group); +if (ids->err) +return ids->err; idmap =mnt_idmap (path->mnt); fs_userns =i_user_ns (inode);
@@ -806,9 +843,9 @@ int chown_common(const struct path *path, uid_t user, gid_t group) newattrs.ia_vfsuid =INVALID_VFSUID ; newattrs.ia_vfsgid =INVALID_VFSGID ; newattrs.ia_valid =ATTR_CTIME ; -if ((user != (uid_t)-1 ) && !setattr_vfsuid (&newattrs, uid)) +if (uid_valid (ids->uid) && !setattr_vfsuid (&newattrs, ids->uid))return -EINVAL ; -if ((group != (gid_t)-1 ) && !setattr_vfsgid (&newattrs, gid)) +if (gid_valid (ids->gid) && !setattr_vfsgid (&newattrs, ids->gid))return -EINVAL ; error =inode_lock_killable (inode);if (error)
@@ -833,8 +870,15 @@ int chown_common(const struct path *path, uid_t user, gid_t group)return error; } -int do_fchownat (int dfd,const char __user *filename,uid_t user,gid_t group, -int flag) +int chown_common (const struct path *path,uid_t user,gid_t group) +{ +struct chown_ids ids =chown_ids_classic (user, group); + +return chown_path (path, &ids); +} + +static int fchownat_ids (int dfd,const char __user *filename, +const struct chown_ids *ids,int flag) {struct path path;int error;
@@ -850,7 +894,7 @@ int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group,if (!error) { error =mnt_want_write (path.mnt);if (!error) { - error =chown_common (&path, user, group); + error =chown_path (&path, ids);mnt_drop_write (path.mnt); }path_put (&path);
@@ -862,6 +906,14 @@ int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group,return error; } +int do_fchownat (int dfd,const char __user *filename,uid_t user,gid_t group, +int flag) +{ +struct chown_ids ids =chown_ids_classic (user, group); + +return fchownat_ids (dfd, filename, &ids, flag); +} + SYSCALL_DEFINE5(fchownat, int, dfd, const char __user *, filename, uid_t, user, gid_t, group, int, flag) {
@@ -879,7 +931,7 @@ SYSCALL_DEFINE3(lchown, const char __user *, filename, uid_t, user, gid_t, group AT_SYMLINK_NOFOLLOW); } -int vfs_fchown (struct file *file,uid_t user,gid_t group) +static int fchown_ids (struct file *file,const struct chown_ids *ids) {int error;
@@ -887,11 +939,18 @@ int vfs_fchown(struct file *file, uid_t user, gid_t group)if (error)return error;audit_file (file); - error =chown_common (&file->f_path, user, group); + error =chown_path (&file->f_path, ids);mnt_drop_write_file (file);return error; } +int vfs_fchown (struct file *file,uid_t user,gid_t group) +{ +struct chown_ids ids =chown_ids_classic (user, group); + +return fchown_ids (file, &ids); +} +int ksys_fchown (unsigned int fd,uid_t user,gid_t group) {CLASS (fd, f)(fd);
@@ -907,6 +966,67 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)return ksys_fchown (fd, user, group); } +/* +* The *_r variants take __kernel_uid_r_t ids, which can also be UUIDs or +* GUIDs. A NULL pointer, UID_R_NONE or a classic -1 leave the owner or +* group unchanged. +*/ +SYSCALL_DEFINE5(fchownat_r, int, dfd, const char __user *, filename, + const struct __kernel_uid_r __user *, user, + const struct __kernel_uid_r __user *, group, int, flag) +{ +struct chown_ids ids; +int error; + + error =chown_ids_r (user, group, &ids); +if (error) +return error; +return fchownat_ids (dfd, filename, &ids, flag); +} + +SYSCALL_DEFINE3(chown_r, const char __user *, filename, + const struct __kernel_uid_r __user *, user, + const struct __kernel_uid_r __user *, group) +{ +struct chown_ids ids; +int error; + + error =chown_ids_r (user, group, &ids); +if (error) +return error; +return fchownat_ids (AT_FDCWD , filename, &ids,0 ); +} + +SYSCALL_DEFINE3(lchown_r, const char __user *, filename, + const struct __kernel_uid_r __user *, user, + const struct __kernel_uid_r __user *, group) +{ +struct chown_ids ids; +int error; + + error =chown_ids_r (user, group, &ids); +if (error) +return error; +return fchownat_ids (AT_FDCWD , filename, &ids,AT_SYMLINK_NOFOLLOW ); +} + +SYSCALL_DEFINE3(fchown_r, unsigned int, fd, + const struct __kernel_uid_r __user *, user, + const struct __kernel_uid_r __user *, group) +{ +struct chown_ids ids; +int error; + + error =chown_ids_r (user, group, &ids); +if (error) +return error; + +CLASS (fd, f)(fd); +if (fd_empty (f)) +return -EBADF ; +return fchown_ids (fd_file (f), &ids); +} +static inline int file_get_write_access (struct file *f) {int error;
include/linux/syscalls.h +13 -0
@@ -998,6 +998,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,
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 21/41] fs: add chown_r(), lchown_r(), fchown_r() and fchownat_r()
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] fs: broken unchanged and malformed ID handling in chown_path() for !MULTIUSER - [High] fs: missing…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] fs: broken unchanged and malformed ID handling in chown_path() for !MULTIUSER
- [High] fs: missing s_user_ns mapping check for UUID/GUID in chown_path()
- [Medium] fs: chown_ids_r() accepts nonzero reserved bytes for UID_R_NONE and -1 --
commit c1c7ee0a217eb922615794b81d3b58341468ee6f
Author: Jan Koester <[email protected]>
fs: add chown_r(), lchown_r(), fchown_r() and fchownat_r()
This commit adds the chown_r(), lchown_r(), fchown_r(), and fchownat_r() system calls accepting struct __kernel_uid_r owners and groups, and refactors the classic chown paths to share lookup and setattr logic via struct chown_ids and chown_path().
Quoted 37 lines
fs/open.c +28
-1@@ -785,7 +785,46 @@ static inline bool setattr_vfsgid(struct iattr *attr, kgid_t kgid)return true; } -int chown_common (const struct path *path,uid_t user,gid_t group) +/* +* The new owner and group of a chown. Invalid ids stand for "unchanged"; +* @err is an error of their conversion, reported once the path is found, +* which keeps the classic calls' order of errors. +*/ +struct chown_ids { +kuid_t uid; +kgid_t gid; +int err; +}; + +static struct chown_ids chown_ids_classic (uid_t user,gid_t group) +{ +struct user_namespace *ns =current_user_ns (); +struct chown_ids ids = { + .uid =make_kuid (ns, user), + .gid =make_kgid (ns, group), + }; + +if ((user != (uid_t)-1 && !uid_valid (ids.uid)) || + (group != (gid_t)-1 && !gid_valid (ids.gid))) + ids.err = -EINVAL ; +return ids; +} + +static int chown_ids_r (const struct __kernel_uid_r __user *user, +const struct __kernel_uid_r __user *group, +struct chown_ids *ids)
fs/open.c static inline bool setattr_vfsgid(struct iattr *attr, kgid_t kgid) · line 825
Quoted 10 lines
fs/open.c +10
-0+{ +struct user_namespace *ns =current_user_ns (); +int err; + + ids->err =0 ; + err =get_kuid_r (ns, user, &ids->uid); +if (!err) + err =get_kgid_r (ns, group, &ids->gid); +return err; +}
[Severity: Medium]
When userspace calls sys_chown_r(), sys_lchown_r(), sys_fchown_r(), or sys_fchownat_r() with a struct __kernel_uid_r whose type is UID_R_NONE or UID_R_LEGACY with legacy == (u32)-1, can non-zero bytes in the reserved union area bypass validation?
In include/uapi/linux/uidgid_r.h, struct __kernel_uid_r documents:
/*
* Bytes past the member .type selects are reserved and must be zero.
*/However, chown_ids_r() delegates to get_kuid_r() and get_kgid_r() in kernel/uidgid_r.c, which return 0 as soon as kid_r_is_none(&id) matches, before make_kuid_r() or make_kgid_r() calls kid_r_valid(&id):
static bool kid_r_is_none(const struct __kernel_uid_r *id)
{
return id->type == UID_R_NONE ||
(id->type == UID_R_LEGACY && id->legacy == (u32)-1);
}
int get_kuid_r(struct user_namespace *from,
const struct __kernel_uid_r __user *uid, kuid_t *kuid)
{
...
if (kid_r_is_none(&id))
return 0;
*kuid = make_kuid_r(from, &id);
return uid_valid(*kuid) ? 0 : -EINVAL;
}Because kid_r_is_none() does not check the 16 union bytes for UID_R_NONE or the 12 trailing bytes (id->uuid + sizeof(id->legacy)) for UID_R_LEGACY with legacy == (u32)-1, shouldn't those reserved bytes be verified to be zero so that non-zero trailing bytes are rejected with -EINVAL?
Quoted 20 lines
fs/open.c +4
-4+ +static int chown_path (const struct path *path,const struct chown_ids *ids) {struct mnt_idmap *idmap;struct user_namespace *fs_userns;@@ -793,11 +832,9 @@ int chown_common(const struct path *path, uid_t user, gid_t group)struct delegated_inode delegated_inode = { };int error;struct iattr newattrs; -kuid_t uid; -kgid_t gid; - uid =make_kuid (current_user_ns (), user); - gid =make_kgid (current_user_ns (), group); +if (ids->err) +return ids->err; idmap =mnt_idmap (path->mnt); fs_userns =i_user_ns (inode);
fs/open.c int chown_common(const struct path *path, uid_t user, gid_t group) · line 849
Quoted 9 lines
fs/open.c +2
-2@@ -806,9 +843,9 @@ int chown_common(const struct path *path, uid_t user, gid_t group) newattrs.ia_vfsuid =INVALID_VFSUID ; newattrs.ia_vfsgid =INVALID_VFSGID ; newattrs.ia_valid =ATTR_CTIME ; -if ((user != (uid_t)-1 ) && !setattr_vfsuid (&newattrs, uid)) +if (uid_valid (ids->uid) && !setattr_vfsuid (&newattrs, ids->uid))return -EINVAL ; -if ((group != (gid_t)-1 ) && !setattr_vfsgid (&newattrs, gid)) +if (gid_valid (ids->gid) && !setattr_vfsgid (&newattrs, ids->gid))return -EINVAL ;
[Severity: High]
How does chown_path() handle unchanged IDs (-1, NULL, or UID_R_NONE) and malformed IDs when CONFIG_MULTIUSER is disabled?
Previously, chown_common() checked (user != (uid_t)-1) and
(group != (gid_t)-1) before calling setattr_vfsuid() and setattr_vfsgid(). With this change, chown_ids_classic() and chown_ids_r() encode an unchanged owner or group as INVALID_UID / INVALID_GID, and chown_path() uses uid_valid(ids->uid) and gid_valid(ids->gid) to decide whether to set ATTR_UID and ATTR_GID.
In include/linux/uidgid.h, when !CONFIG_MULTIUSER, __kuid_val() and __kgid_val() always return 0:
static inline uid_t __kuid_val(kuid_t uid)
{
return 0;
}
static inline bool uid_valid(kuid_t uid)
{
return !uid_is_legacy(uid) || __kuid_val(uid) != (uid_t) -1;
}As a result, uid_valid(INVALID_UID) and gid_valid(INVALID_GID) always return true on !CONFIG_MULTIUSER builds:
1. Calling chown(), lchown(), fchown(), or fchownat() with -1, or calling chown_r(), lchown_r(), fchown_r(), or fchownat_r() with NULL, UID_R_NONE, or legacy -1 causes chown_path() to call setattr_vfsuid() and setattr_vfsgid() with INVALID_UID and INVALID_GID. That sets ATTR_UID and ATTR_GID in newattrs.ia_valid and copies VFSUIDT_INIT(INVALID_UID) and VFSGIDT_INIT(INVALID_GID) (with .legacy = -1) into newattrs.ia_vfsuid and newattrs.ia_vfsgid, causing notify_change() -> may_setattr() to reject no-op chown calls on immutable/append-only files with -EPERM and causing setattr_copy() to write INVALID_UID / INVALID_GID into inode->i_uid and inode->i_gid.
2. In chown_ids_r() -> get_kuid_r() / get_kgid_r(), malformed struct __kernel_uid_r inputs for which make_kuid_r() or make_kgid_r() returns INVALID_UID / INVALID_GID pass uid_valid(*kuid) / gid_valid(*kgid) and return 0 instead of -EINVAL.
3. In chown_path(), because setattr_vfsuid() and setattr_vfsgid() only return false when !uid_valid() or !gid_valid(), gating them with uid_valid(ids->uid) and gid_valid(ids->gid) also makes the two return -EINVAL branches unreachable.
fs/open.c int chown_common(const struct path *path, uid_t user, gid_t group) · line 851
Quoted 2 lines
fs/open.c +0
-0error =inode_lock_killable (inode);if (error)
[Severity: High]
What prevents chown_path() from setting a UUID or GUID owner or group on a non-idmapped mount of a filesystem mounted in a non-initial user namespace (inode->i_sb->s_user_ns != &init_user_ns)?
When a process in init_user_ns calls chown_r(), lchown_r(), fchown_r(), or fchownat_r() with a UUID or GUID on a regular mount (idmap == &nop_mnt_idmap) of a filesystem with SB_I_UID_R mounted in a child user namespace (such as tmpfs, ramfs, devpts, or overlayfs), chown_path() calls security_path_chown() with from_vfsuid() / from_vfsgid() and then calls notify_change().
In fs/attr.c:notify_change(), the superblock namespace check uses vfsuid_has_fsmapping() and vfsgid_has_fsmapping():
if (ia_valid & ATTR_UID &&
!vfsuid_has_fsmapping(idmap, inode->i_sb->s_user_ns,
attr->ia_vfsuid))
return -EOVERFLOW;However, vfsuid_has_fsmapping() in include/linux/mnt_idmapping.h simply checks uid_valid(from_vfsuid(idmap, fs_userns, vfsuid)), and from_vfsuid() in fs/mnt_idmapping.c returns early for nop_mnt_idmap before checking kuid_has_mapping(fs_userns, ...):
kuid_t from_vfsuid(struct mnt_idmap *idmap,
struct user_namespace *fs_userns, vfsuid_t vfsuid)
{
uid_t uid;
if (idmap == &nop_mnt_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;Because UUID and GUID identities only have mappings in init_user_ns, shouldn't non-legacy IDs also be checked against fs_userns when idmap == &nop_mnt_idmap so that notify_change() rejects them with -EOVERFLOW instead of writing an unmapped UUID or GUID to the inode?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=21
RFC PATCH v2 22/41 arch: wire up the *_r uid and gid system calls
In reply to Jan KoesterAssign 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.
--- 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 | 43 ++++++++++++++++++++- scripts/syscall.tbl | 20 ++++++++++ 18 files changed, 382 insertions(+), 1 deletion(-)
arch/alpha/kernel/syscalls/syscall.tbl +20 -0
@@ -512,3 +512,23 @@ 580 common listns sys_listns 581 common rseq_slice_yield sys_rseq_slice_yield 582 common fchroot sys_fchroot +583 common getuid_r sys_getuid_r +584 common geteuid_r sys_geteuid_r +585 common getgid_r sys_getgid_r +586 common getegid_r sys_getegid_r +587 common setuid_r sys_setuid_r +588 common setgid_r sys_setgid_r +589 common setreuid_r sys_setreuid_r +590 common setregid_r sys_setregid_r +591 common setresuid_r sys_setresuid_r +592 common getresuid_r sys_getresuid_r +593 common setresgid_r sys_setresgid_r +594 common getresgid_r sys_getresgid_r +595 common setfsuid_r sys_setfsuid_r +596 common setfsgid_r sys_setfsgid_r +597 common getgroups_r sys_getgroups_r +598 common setgroups_r sys_setgroups_r +599 common chown_r sys_chown_r +600 common lchown_r sys_lchown_r +601 common fchown_r sys_fchown_r +602 common fchownat_r sys_fchownat_r
arch/arm/tools/syscall.tbl +20 -0
@@ -487,3 +487,23 @@ 470 common listns sys_listns 471 common rseq_slice_yield sys_rseq_slice_yield 472 common fchroot sys_fchroot +473 common getuid_r sys_getuid_r +474 common geteuid_r sys_geteuid_r +475 common getgid_r sys_getgid_r +476 common getegid_r sys_getegid_r +477 common setuid_r sys_setuid_r +478 common setgid_r sys_setgid_r +479 common setreuid_r sys_setreuid_r +480 common setregid_r sys_setregid_r +481 common setresuid_r sys_setresuid_r +482 common getresuid_r sys_getresuid_r +483 common setresgid_r sys_setresgid_r +484 common getresgid_r sys_getresgid_r +485 common setfsuid_r sys_setfsuid_r +486 common setfsgid_r sys_setfsgid_r +487 common getgroups_r sys_getgroups_r +488 common setgroups_r sys_setgroups_r +489 common chown_r sys_chown_r +490 common lchown_r sys_lchown_r +491 common fchown_r sys_fchown_r +492 common fchownat_r sys_fchownat_r
arch/arm64/tools/syscall_32.tbl +20 -0
@@ -484,3 +484,23 @@ 470 common listns sys_listns 471 common rseq_slice_yield sys_rseq_slice_yield 472 common fchroot sys_fchroot +473 common getuid_r sys_getuid_r +474 common geteuid_r sys_geteuid_r +475 common getgid_r sys_getgid_r +476 common getegid_r sys_getegid_r +477 common setuid_r sys_setuid_r +478 common setgid_r sys_setgid_r +479 common setreuid_r sys_setreuid_r +480 common setregid_r sys_setregid_r +481 common setresuid_r sys_setresuid_r +482 common getresuid_r sys_getresuid_r +483 common setresgid_r sys_setresgid_r +484 common getresgid_r sys_getresgid_r +485 common setfsuid_r sys_setfsuid_r +486 common setfsgid_r sys_setfsgid_r +487 common getgroups_r sys_getgroups_r +488 common setgroups_r sys_setgroups_r +489 common chown_r sys_chown_r +490 common lchown_r sys_lchown_r +491 common fchown_r sys_fchown_r +492 common fchownat_r sys_fchownat_r
arch/m68k/kernel/syscalls/syscall.tbl +20 -0
@@ -472,3 +472,23 @@ 470 common listns sys_listns 471 common rseq_slice_yield sys_rseq_slice_yield 472 common fchroot sys_fchroot +473 common getuid_r sys_getuid_r +474 common geteuid_r sys_geteuid_r +475 common getgid_r sys_getgid_r +476 common getegid_r sys_getegid_r +477 common setuid_r sys_setuid_r +478 common setgid_r sys_setgid_r +479 common setreuid_r sys_setreuid_r +480 common setregid_r sys_setregid_r +481 common setresuid_r sys_setresuid_r +482 common getresuid_r sys_getresuid_r +483 common setresgid_r sys_setresgid_r +484 common getresgid_r sys_getresgid_r +485 common setfsuid_r sys_setfsuid_r +486 common setfsgid_r sys_setfsgid_r +487 common getgroups_r sys_getgroups_r +488 common setgroups_r sys_setgroups_r +489 common chown_r sys_chown_r +490 common lchown_r sys_lchown_r +491 common fchown_r sys_fchown_r +492 common fchownat_r sys_fchownat_r
arch/microblaze/kernel/syscalls/syscall.tbl +20 -0
@@ -478,3 +478,23 @@ 470 common listns sys_listns 471 common rseq_slice_yield sys_rseq_slice_yield 472 common fchroot sys_fchroot +473 common getuid_r sys_getuid_r +474 common geteuid_r sys_geteuid_r +475 common getgid_r sys_getgid_r +476 common getegid_r sys_getegid_r +477 common setuid_r sys_setuid_r +478 common setgid_r sys_setgid_r +479 common setreuid_r sys_setreuid_r +480 common setregid_r sys_setregid_r +481 common setresuid_r sys_setresuid_r +482 common getresuid_r sys_getresuid_r +483 common setresgid_r sys_setresgid_r +484 common getresgid_r sys_getresgid_r +485 common setfsuid_r sys_setfsuid_r +486 common setfsgid_r sys_setfsgid_r +487 common getgroups_r sys_getgroups_r +488 common setgroups_r sys_setgroups_r +489 common chown_r sys_chown_r +490 common lchown_r sys_lchown_r +491 common fchown_r sys_fchown_r +492 common fchownat_r sys_fchownat_r
arch/mips/kernel/syscalls/syscall_n32.tbl +20 -0
@@ -411,3 +411,23 @@ 470 n32 listns sys_listns 471 n32 rseq_slice_yield sys_rseq_slice_yield 472 n32 fchroot sys_fchroot +473 n32 getuid_r sys_getuid_r +474 n32 geteuid_r sys_geteuid_r +475 n32 getgid_r sys_getgid_r +476 n32 getegid_r sys_getegid_r +477 n32 setuid_r sys_setuid_r +478 n32 setgid_r sys_setgid_r +479 n32 setreuid_r sys_setreuid_r +480 n32 setregid_r sys_setregid_r +481 n32 setresuid_r sys_setresuid_r +482 n32 getresuid_r sys_getresuid_r +483 n32 setresgid_r sys_setresgid_r +484 n32 getresgid_r sys_getresgid_r +485 n32 setfsuid_r sys_setfsuid_r +486 n32 setfsgid_r sys_setfsgid_r +487 n32 getgroups_r sys_getgroups_r +488 n32 setgroups_r sys_setgroups_r +489 n32 chown_r sys_chown_r +490 n32 lchown_r sys_lchown_r +491 n32 fchown_r sys_fchown_r +492 n32 fchownat_r sys_fchownat_r
arch/mips/kernel/syscalls/syscall_n64.tbl +20 -0
@@ -387,3 +387,23 @@ 470 n64 listns sys_listns 471 n64 rseq_slice_yield sys_rseq_slice_yield 472 n64 fchroot sys_fchroot +473 n64 getuid_r sys_getuid_r +474 n64 geteuid_r sys_geteuid_r +475 n64 getgid_r sys_getgid_r +476 n64 getegid_r sys_getegid_r +477 n64 setuid_r sys_setuid_r +478 n64 setgid_r sys_setgid_r +479 n64 setreuid_r sys_setreuid_r +480 n64 setregid_r sys_setregid_r +481 n64 setresuid_r sys_setresuid_r +482 n64 getresuid_r sys_getresuid_r +483 n64 setresgid_r sys_setresgid_r +484 n64 getresgid_r sys_getresgid_r +485 n64 setfsuid_r sys_setfsuid_r +486 n64 setfsgid_r sys_setfsgid_r +487 n64 getgroups_r sys_getgroups_r +488 n64 setgroups_r sys_setgroups_r +489 n64 chown_r sys_chown_r +490 n64 lchown_r sys_lchown_r +491 n64 fchown_r sys_fchown_r +492 n64 fchownat_r sys_fchownat_r
arch/mips/kernel/syscalls/syscall_o32.tbl +20 -0
@@ -460,3 +460,23 @@ 470 o32 listns sys_listns 471 o32 rseq_slice_yield sys_rseq_slice_yield 472 o32 fchroot sys_fchroot +473 o32 getuid_r sys_getuid_r +474 o32 geteuid_r sys_geteuid_r +475 o32 getgid_r sys_getgid_r +476 o32 getegid_r sys_getegid_r +477 o32 setuid_r sys_setuid_r +478 o32 setgid_r sys_setgid_r +479 o32 setreuid_r sys_setreuid_r +480 o32 setregid_r sys_setregid_r +481 o32 setresuid_r sys_setresuid_r +482 o32 getresuid_r sys_getresuid_r +483 o32 setresgid_r sys_setresgid_r +484 o32 getresgid_r sys_getresgid_r +485 o32 setfsuid_r sys_setfsuid_r +486 o32 setfsgid_r sys_setfsgid_r +487 o32 getgroups_r sys_getgroups_r +488 o32 setgroups_r sys_setgroups_r +489 o32 chown_r sys_chown_r +490 o32 lchown_r sys_lchown_r +491 o32 fchown_r sys_fchown_r +492 o32 fchownat_r sys_fchownat_r
arch/parisc/kernel/syscalls/syscall.tbl +20 -0
@@ -471,3 +471,23 @@ 470 common listns sys_listns 471 common rseq_slice_yield sys_rseq_slice_yield 472 common fchroot sys_fchroot +473 common getuid_r sys_getuid_r +474 common geteuid_r sys_geteuid_r +475 common getgid_r sys_getgid_r +476 common getegid_r sys_getegid_r +477 common setuid_r sys_setuid_r +478 common setgid_r sys_setgid_r +479 common setreuid_r sys_setreuid_r +480 common setregid_r sys_setregid_r +481 common setresuid_r sys_setresuid_r +482 common getresuid_r sys_getresuid_r +483 common setresgid_r sys_setresgid_r +484 common getresgid_r sys_getresgid_r +485 common setfsuid_r sys_setfsuid_r +486 common setfsgid_r sys_setfsgid_r +487 common getgroups_r sys_getgroups_r +488 common setgroups_r sys_setgroups_r +489 common chown_r sys_chown_r +490 common lchown_r sys_lchown_r +491 common fchown_r sys_fchown_r +492 common fchownat_r sys_fchownat_r
arch/powerpc/kernel/syscalls/syscall.tbl +20 -0
@@ -563,3 +563,23 @@ 470 common listns sys_listns 471 nospu rseq_slice_yield sys_rseq_slice_yield 472 common fchroot sys_fchroot +473 nospu getuid_r sys_getuid_r +474 nospu geteuid_r sys_geteuid_r +475 nospu getgid_r sys_getgid_r +476 nospu getegid_r sys_getegid_r +477 nospu setuid_r sys_setuid_r +478 nospu setgid_r sys_setgid_r +479 nospu setreuid_r sys_setreuid_r +480 nospu setregid_r sys_setregid_r +481 nospu setresuid_r sys_setresuid_r +482 nospu getresuid_r sys_getresuid_r +483 nospu setresgid_r sys_setresgid_r +484 nospu getresgid_r sys_getresgid_r +485 nospu setfsuid_r sys_setfsuid_r +486 nospu setfsgid_r sys_setfsgid_r +487 nospu getgroups_r sys_getgroups_r +488 nospu setgroups_r sys_setgroups_r +489 nospu chown_r sys_chown_r +490 nospu lchown_r sys_lchown_r +491 nospu fchown_r sys_fchown_r +492 nospu fchownat_r sys_fchownat_r
arch/s390/kernel/syscalls/syscall.tbl +20 -0
@@ -399,3 +399,23 @@ 470 common listns sys_listns 471 common rseq_slice_yield sys_rseq_slice_yield 472 common fchroot sys_fchroot +473 common getuid_r sys_getuid_r +474 common geteuid_r sys_geteuid_r +475 common getgid_r sys_getgid_r +476 common getegid_r sys_getegid_r +477 common setuid_r sys_setuid_r +478 common setgid_r sys_setgid_r +479 common setreuid_r sys_setreuid_r +480 common setregid_r sys_setregid_r +481 common setresuid_r sys_setresuid_r +482 common getresuid_r sys_getresuid_r +483 common setresgid_r sys_setresgid_r +484 common getresgid_r sys_getresgid_r +485 common setfsuid_r sys_setfsuid_r +486 common setfsgid_r sys_setfsgid_r +487 common getgroups_r sys_getgroups_r +488 common setgroups_r sys_setgroups_r +489 common chown_r sys_chown_r +490 common lchown_r sys_lchown_r +491 common fchown_r sys_fchown_r +492 common fchownat_r sys_fchownat_r
arch/sh/kernel/syscalls/syscall.tbl +20 -0
@@ -476,3 +476,23 @@ 470 common listns sys_listns 471 common rseq_slice_yield sys_rseq_slice_yield 472 common fchroot sys_fchroot +473 common getuid_r sys_getuid_r +474 common geteuid_r sys_geteuid_r +475 common getgid_r sys_getgid_r +476 common getegid_r sys_getegid_r +477 common setuid_r sys_setuid_r +478 common setgid_r sys_setgid_r +479 common setreuid_r sys_setreuid_r +480 common setregid_r sys_setregid_r +481 common setresuid_r sys_setresuid_r +482 common getresuid_r sys_getresuid_r +483 common setresgid_r sys_setresgid_r +484 common getresgid_r sys_getresgid_r +485 common setfsuid_r sys_setfsuid_r +486 common setfsgid_r sys_setfsgid_r +487 common getgroups_r sys_getgroups_r +488 common setgroups_r sys_setgroups_r +489 common chown_r sys_chown_r +490 common lchown_r sys_lchown_r +491 common fchown_r sys_fchown_r +492 common fchownat_r sys_fchownat_r
arch/sparc/kernel/syscalls/syscall.tbl +20 -0
@@ -518,3 +518,23 @@ 470 common listns sys_listns 471 common rseq_slice_yield sys_rseq_slice_yield 472 common fchroot sys_fchroot +473 common getuid_r sys_getuid_r +474 common geteuid_r sys_geteuid_r +475 common getgid_r sys_getgid_r +476 common getegid_r sys_getegid_r +477 common setuid_r sys_setuid_r +478 common setgid_r sys_setgid_r +479 common setreuid_r sys_setreuid_r +480 common setregid_r sys_setregid_r +481 common setresuid_r sys_setresuid_r +482 common getresuid_r sys_getresuid_r +483 common setresgid_r sys_setresgid_r +484 common getresgid_r sys_getresgid_r +485 common setfsuid_r sys_setfsuid_r +486 common setfsgid_r sys_setfsgid_r +487 common getgroups_r sys_getgroups_r +488 common setgroups_r sys_setgroups_r +489 common chown_r sys_chown_r +490 common lchown_r sys_lchown_r +491 common fchown_r sys_fchown_r +492 common fchownat_r sys_fchownat_r
arch/x86/entry/syscalls/syscall_32.tbl +20 -0
@@ -478,3 +478,23 @@ 470 i386 listns sys_listns 471 i386 rseq_slice_yield sys_rseq_slice_yield 472 i386 fchroot sys_fchroot +473 i386 getuid_r sys_getuid_r +474 i386 geteuid_r sys_geteuid_r +475 i386 getgid_r sys_getgid_r +476 i386 getegid_r sys_getegid_r +477 i386 setuid_r sys_setuid_r +478 i386 setgid_r sys_setgid_r +479 i386 setreuid_r sys_setreuid_r +480 i386 setregid_r sys_setregid_r +481 i386 setresuid_r sys_setresuid_r +482 i386 getresuid_r sys_getresuid_r +483 i386 setresgid_r sys_setresgid_r +484 i386 getresgid_r sys_getresgid_r +485 i386 setfsuid_r sys_setfsuid_r +486 i386 setfsgid_r sys_setfsgid_r +487 i386 getgroups_r sys_getgroups_r +488 i386 setgroups_r sys_setgroups_r +489 i386 chown_r sys_chown_r +490 i386 lchown_r sys_lchown_r +491 i386 fchown_r sys_fchown_r +492 i386 fchownat_r sys_fchownat_r
arch/x86/entry/syscalls/syscall_64.tbl +20 -0
@@ -397,6 +397,26 @@ 470 common listns sys_listns 471 common rseq_slice_yield sys_rseq_slice_yield 472 common fchroot sys_fchroot +473 common getuid_r sys_getuid_r +474 common geteuid_r sys_geteuid_r +475 common getgid_r sys_getgid_r +476 common getegid_r sys_getegid_r +477 common setuid_r sys_setuid_r +478 common setgid_r sys_setgid_r +479 common setreuid_r sys_setreuid_r +480 common setregid_r sys_setregid_r +481 common setresuid_r sys_setresuid_r +482 common getresuid_r sys_getresuid_r +483 common setresgid_r sys_setresgid_r +484 common getresgid_r sys_getresgid_r +485 common setfsuid_r sys_setfsuid_r +486 common setfsgid_r sys_setfsgid_r +487 common getgroups_r sys_getgroups_r +488 common setgroups_r sys_setgroups_r +489 common chown_r sys_chown_r +490 common lchown_r sys_lchown_r +491 common fchown_r sys_fchown_r +492 common fchownat_r sys_fchownat_r # # Due to a historical design error, certain syscalls are numbered differently
arch/xtensa/kernel/syscalls/syscall.tbl +20 -0
@@ -443,3 +443,23 @@ 470 common listns sys_listns 471 common rseq_slice_yield sys_rseq_slice_yield 472 common fchroot sys_fchroot +473 common getuid_r sys_getuid_r +474 common geteuid_r sys_geteuid_r +475 common getgid_r sys_getgid_r +476 common getegid_r sys_getegid_r +477 common setuid_r sys_setuid_r +478 common setgid_r sys_setgid_r +479 common setreuid_r sys_setreuid_r +480 common setregid_r sys_setregid_r +481 common setresuid_r sys_setresuid_r +482 common getresuid_r sys_getresuid_r +483 common setresgid_r sys_setresgid_r +484 common getresgid_r sys_getresgid_r +485 common setfsuid_r sys_setfsuid_r +486 common setfsgid_r sys_setfsgid_r +487 common getgroups_r sys_getgroups_r +488 common setgroups_r sys_setgroups_r +489 common chown_r sys_chown_r +490 common lchown_r sys_lchown_r +491 common fchown_r sys_fchown_r +492 common fchownat_r sys_fchownat_r
include/uapi/asm-generic/unistd.h +42 -1
50 lines not on this page · raw message
scripts/syscall.tbl +20 -0
@@ -413,3 +413,23 @@ 470 common listns sys_listns 471 common rseq_slice_yield sys_rseq_slice_yield 472 common fchroot sys_fchroot +473 common getuid_r sys_getuid_r +474 common geteuid_r sys_geteuid_r +475 common getgid_r sys_getgid_r +476 common getegid_r sys_getegid_r +477 common setuid_r sys_setuid_r +478 common setgid_r sys_setgid_r +479 common setreuid_r sys_setreuid_r +480 common setregid_r sys_setregid_r +481 common setresuid_r sys_setresuid_r +482 common getresuid_r sys_getresuid_r +483 common setresgid_r sys_setresgid_r +484 common getresgid_r sys_getresgid_r +485 common setfsuid_r sys_setfsuid_r +486 common setfsgid_r sys_setfsgid_r +487 common getgroups_r sys_getgroups_r +488 common setgroups_r sys_setgroups_r +489 common chown_r sys_chown_r +490 common lchown_r sys_lchown_r +491 common fchown_r sys_fchown_r +492 common fchownat_r sys_fchownat_r
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 22/41] arch: wire up the *_r uid and gid system calls
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] audit: missing chown_r family syscalls in audit_change_attr.h - [Low] arch: commit message…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] audit: missing chown_r family syscalls in audit_change_attr.h
- [Low] arch: commit message states wrong syscall number ranges for *_r syscalls --
commit de1d2caf3a9cdd09efea2705dc6569ed00a466b1
Author: Jan Koester <[email protected]>
arch: wire up the *_r uid and gid system calls
This commit wires up the 20 extended uid and gid system calls (getuid_r through fchownat_r) in the generic syscall header and across architecture syscall tables.
Quoted 8 lines
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_randfchownat_r.
Quoted 6 lines
__kernel_uid_r_thas the same layout on all ABIs, so the compat ABIs use the native entry points.Assisted-by Claude:claude-opus-5-5Signed-off-by Jan Koester <[email protected]>
[Severity: Low]
Should the syscall number ranges in the commit message be 473-492 (and 583-602 on alpha) instead of 472-491 (and 582-601 on alpha)?
Syscall 472 is already assigned to fchroot ininclude/uapi/asm-generic/unistd.h (and 582 inarch/alpha/kernel/syscalls/syscall.tbl):
arch/alpha/kernel/syscalls/syscall.tbl:
582 common fchroot sys_fchroot
583 common getuid_r sys_getuid_r
...
602 common fchownat_r sys_fchownat_r[ ... ]
Quoted 10 lines
include/uapi/asm-generic/unistd.h +2
-0@@ -867,8 +867,49 @@ __SYSCALL(__NR_rseq_slice_yield, sys_rseq_slice_yield)#define __NR_fchroot 472 __SYSCALL(__NR_fchroot, sys_fchroot) +#define __NR_getuid_r 473 +__SYSCALL (__NR_getuid_r, sys_getuid_r)
[ ... ]
include/uapi/asm-generic/unistd.h __SYSCALL(__NR_rseq_slice_yield, sys_rseq_slice_yield) · line 909
Quoted 8 lines
include/uapi/asm-generic/unistd.h +8
-0+#define __NR_chown_r 489 +__SYSCALL(__NR_chown_r, sys_chown_r) +#define __NR_lchown_r 490 +__SYSCALL(__NR_lchown_r, sys_lchown_r) +#define __NR_fchown_r 491 +__SYSCALL(__NR_fchown_r, sys_fchown_r) +#define __NR_fchownat_r 492 +__SYSCALL (__NR_fchownat_r, sys_fchownat_r)
[Severity: Medium]
When wiring up chown_r, lchown_r, fchown_r, and fchownat_r, should these new syscall numbers also be added to include/asm-generic/audit_change_attr.h?
Currently include/asm-generic/audit_change_attr.h lists the existing ownership-changing syscalls to populate chattr_class[] in lib/audit.c and compat_chattr_class[] in lib/compat_audit.c:
include/asm-generic/audit_change_attr.h:
#ifdef __NR_chown
__NR_chown,
__NR_lchown,
#endif
#ifdef __NR_fchown
__NR_fchown,
#endif
...
#ifdef __NR_fchownat
__NR_fchownat,
__NR_fchmodat,
#endifWhen an audit watch or directory rule monitors attribute changes, audit_to_entry_common() in kernel/auditfilter.c expands those classes into entry->rule.mask[], and __audit_filter_op() -> audit_match_perm() in kernel/auditsc.c checks whether the syscall number belongs to the attribute change class:
kernel/auditsc.c:audit_match_perm() {
...
switch (audit_classify_syscall(ctx->arch, n)) {
case AUDITSC_NATIVE:
...
if ((mask & AUDIT_PERM_ATTR) &&
audit_match_class(AUDIT_CLASS_CHATTR, n))
return 1;
return 0;
case AUDITSC_COMPAT: /* 32bit on biarch */
...
if ((mask & AUDIT_PERM_ATTR) &&
audit_match_class(AUDIT_CLASS_CHATTR_32, n))
return 1;
return 0;
...
}Without the *_r ownership syscalls in include/asm-generic/audit_change_attr.h, ownership changes made via sys_chown_r(), sys_lchown_r(), sys_fchown_r(), or sys_fchownat_r() will not match attribute-change audit watch rules.
[ ... ]
Quoted 4 lines
#undef
__NR_syscallsinclude/uapi/asm-generic/unistd.h +1
-1-#define __NR_syscalls 473 +#define __NR_syscalls 493
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=22
RFC PATCH v2 23/41 statx: report UUID and GUID owners
In reply to Jan KoesterAdd 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.
--- fs/stat.c | 24 +++++++++++++++++++++++- include/uapi/linux/stat.h | 10 +++++++++- 2 files changed, 32 insertions(+), 2 deletions(-)
fs/stat.c +23 -1
@@ -185,7 +185,7 @@ int vfs_getattr_nosec(const struct path *path, struct kstat *stat,struct inode *inode =d_backing_inode (path->dentry);memset (stat,0 ,sizeof (*stat)); - stat->result_mask |=STATX_BASIC_STATS ; + stat->result_mask |=STATX_BASIC_STATS |STATX_UID_R |STATX_GID_R ; query_flags &=AT_STATX_SYNC_TYPE ;/* allow the fs to override these if it really wants to */
@@ -206,6 +206,17 @@ int vfs_getattr_nosec(const struct path *path, struct kstat *stat, stat->attributes_mask |= (STATX_ATTR_AUTOMOUNT |STATX_ATTR_DAX ); +/* +* STATX_UID_R and STATX_GID_R are another view of the owner: ask the +* filesystem for STATX_UID and STATX_GID, and report them whenever +* those are valid, also from a ->getattr() that sets result_mask on +* its own. +*/ +if (request_mask &STATX_UID_R ) + request_mask |=STATX_UID ; +if (request_mask &STATX_GID_R ) + request_mask |=STATX_GID ; + idmap =mnt_idmap (path->mnt);if (inode->i_op->getattr) {int ret;
@@ -218,6 +229,15 @@ int vfs_getattr_nosec(const struct path *path, struct kstat *stat,generic_fillattr (idmap, request_mask, inode, stat); } +if (stat->result_mask &STATX_UID ) + stat->result_mask |=STATX_UID_R ; +else + stat->result_mask &= ~STATX_UID_R ; +if (stat->result_mask &STATX_GID ) + stat->result_mask |=STATX_GID_R ; +else + stat->result_mask &= ~STATX_GID_R ; +/* * If this is a block device inode, override the filesystem attributes * with the block device specific parameters that need to be obtained
@@ -711,6 +731,8 @@ cp_statx(const struct kstat *stat, struct statx __user *buffer) tmp.stx_nlink = stat->nlink; tmp.stx_uid =from_kuid_munged (current_user_ns (), stat->uid); tmp.stx_gid =from_kgid_munged (current_user_ns (), stat->gid); +from_kuid_r_munged (current_user_ns (), stat->uid, &tmp.stx_uid_r); +from_kgid_r_munged (current_user_ns (), stat->gid, &tmp.stx_gid_r); tmp.stx_mode = stat->mode; tmp.stx_ino = stat->ino; tmp.stx_size = stat->size;
include/uapi/linux/stat.h +9 -1
@@ -3,6 +3,7 @@#define _UAPI_LINUX_STAT_H#include <linux/types.h> +#include <linux/uidgid_r.h> #if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ <2 )
@@ -187,7 +188,12 @@ struct statx {__u32 __spare2[1 ];/* 0xc0 */ -__u64 __spare3[8 ];/* Spare space for future expansion */ +/* Owner and group, also UUIDs and GUIDs [STATX_UID_R, STATX_GID_R] */ +__kernel_uid_r_t stx_uid_r; +__kernel_gid_r_t stx_gid_r; + +/* 0xe8 */ +__u64 __spare3[3 ];/* Spare space for future expansion */ /* 0x100 */ };
@@ -219,6 +225,8 @@ struct statx {#define STATX_SUBVOL 0x00008000U/* Want/got stx_subvol */ #define STATX_WRITE_ATOMIC 0x00010000U/* Want/got atomic_write_* fields */ #define STATX_DIO_READ_ALIGN 0x00020000U/* Want/got dio read alignment info */ +#define STATX_UID_R 0x00040000U/* Want/got stx_uid_r */ +#define STATX_GID_R 0x00080000U/* Want/got stx_gid_r */ #define STATX__RESERVED 0x80000000U/* Reserved for future struct statx expansion */
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 23/41] statx: report UUID and GUID owners
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Add
stx_uid_randstx_gid_r, the owner and group as__kernel_uid_r_t, taking 40 of the 64 spare bytes at the end of struct statx, andSTATX_UID_RandSTATX_GID_Rfor them. Every filesystem provides them, from the kstat the VFS has anyway.stx_uidandstx_gidkeep showing a UUID or GUID as the overflow id.
Quoted 6 lines
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-5Signed-off-by Jan Koester <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=23
RFC PATCH v2 24/41 shmem, ramfs: allow UUID and GUID owners
In reply to Jan KoesterBoth 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.
--- fs/ramfs/inode.c | 1 + mm/shmem.c | 2 ++ 2 files changed, 3 insertions(+)
fs/ramfs/inode.c +1 -0
@@ -269,6 +269,7 @@ static int ramfs_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_op = &ramfs_ops; sb->s_d_flags =DCACHE_DONTCACHE ; sb->s_time_gran =1 ; + sb->s_iflags |=SB_I_UID_R ; inode =ramfs_get_inode (sb,NULL ,S_IFDIR | fsi->mount_opts.mode,0 ); sb->s_root =d_make_root (inode);
mm/shmem.c +2 -0
@@ -4988,6 +4988,8 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) } sb->s_export_op = &shmem_export_ops; sb->s_flags |=SB_NOSEC ; +/* owners live in the inode only: UUIDs and GUIDs need no format */ + sb->s_iflags |=SB_I_UID_R ;#if IS_ENABLED (CONFIG_UNICODE )if (!ctx->encoding && ctx->strict_encoding) {
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 24/41] shmem, ramfs: allow UUID and GUID owners
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] mm: shmem_fill_super() omits SB_I_UID_R when CONFIG_TMPFS is disabled - [Medium] mm: shmem…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] mm: shmem_fill_super() omits SB_I_UID_R when CONFIG_TMPFS is disabled
- [Medium] mm: shmem: broken tmpfs quota accounting and transfer with SB_I_UID_R --
commit a299bb3c86efdb02b056108e4776b749d61cb7ed
Author: Jan Koester <[email protected]>
shmem, ramfs: allow UUID and GUID owners
This commit sets SB_I_UID_R on ramfs and shmem superblocks so that inodes on these in-memory filesystems can be owned by UUID and GUID values.
mm/shmem.c static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) · line 4992
Quoted 10 lines
mm/shmem.c +2
-0@@ -4988,6 +4988,8 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) } sb->s_export_op = &shmem_export_ops; sb->s_flags |=SB_NOSEC ; +/* owners live in the inode only: UUIDs and GUIDs need no format */ + sb->s_iflags |=SB_I_UID_R ;
[Severity: Medium]
Should SB_I_UID_R be set outside the #ifdef CONFIG_TMPFS block in mm/shmem.c:shmem_fill_super()?
In shmem_fill_super(), this assignment is placed inside the #ifdef CONFIG_TMPFS branch:
sb->s_export_op = &shmem_export_ops; sb->s_flags |= SB_NOSEC; /* owners live in the inode only: UUIDs and GUIDs need no format */ sb->s_iflags |= SB_I_UID_R; ... #else sb->s_flags |= SB_NOUSER; #endif /* CONFIG_TMPFS */ sb->s_d_flags |= DCACHE_DONTCACHE;
When CONFIG_SHMEM=y and CONFIG_TMPFS=n, shmem_init() mounts shm_mnt via kern_mount(&shmem_fs_type) -> shmem_fill_super(), taking the #else branch without setting SB_I_UID_R. Inodes allocated on shm_mnt via shmem_get_inode() (such as memfd_create() files) still use shmem_inode_operations with .setattr = shmem_setattr. Calling fchown_r() or fchownat_r() with a UUID or GUID on those file descriptors will then fail with -EOVERFLOW in fs/attr.c:notify_change():
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;
[Severity: Medium]
How does setting SB_I_UID_R interact with tmpfs quotas when CONFIG_TMPFS_QUOTA is enabled?
The commit message notes that quotas of tmpfs do not account such owners, because dqget() returns -ESRCH for UUID and GUID owners or groups. However, allowing UUID and GUID ownership on a quota-enabled tmpfs mount appears to cause three issues in the quota paths:
1. In mm/shmem.c:shmem_get_inode(), dquot_initialize(inode) leaves SHMEM_I(inode)->i_dquot[cnt] as NULL when dqget() returns -ESRCH, allowing UUID/GUID users and groups to bypass default tmpfs mount hard limits (usrquota_block_hardlimit, usrquota_inode_hardlimit, grpquota_block_hardlimit, and grpquota_inode_hardlimit).
2. When an existing inode owned by a classic UID/GID A is chowned via chown_r() or fchown_r() to a UUID/GUID U, mm/shmem.c:shmem_setattr() calls dquot_transfer() before setattr_copy():
if (i_uid_needs_update(idmap, attr, inode) ||
i_gid_needs_update(idmap, attr, inode)) {
error = dquot_transfer(idmap, inode, attr);
if (error)
return error;
}
setattr_copy(idmap, inode, attr);In fs/quota/dquot.c:dquot_transfer(), dqget() returns -ESRCH for U and sets transfer_to[cnt] = NULL:
dquot = dqget(sb, make_kqid_uid(kuid));
if (IS_ERR(dquot)) {
if (PTR_ERR(dquot) != -ESRCH) {
ret = PTR_ERR(dquot);
goto out_put;
}
dquot = NULL;
}
transfer_to[USRQUOTA] = dquot;Then fs/quota/dquot.c:__dquot_transfer() treats a NULL transfer_to[cnt] as no UID/GID change and skips detaching the old dquot:
for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
/*
* Skip changes for same uid or gid or for turned off quota-type.
*/
if (!transfer_to[cnt])
continue;As a result, inode->i_uid or inode->i_gid is updated to U, but SHMEM_I(inode)->i_dquot[cnt] remains attached to classic owner A's dquot, so subsequent block allocations via shmem_inode_acct_blocks() -> dquot_alloc_block_nodirty() continue charging A's quota.
3. If that inode is later chowned back from UUID/GUID U to the original classic UID/GID A, i_uid_needs_update() or i_gid_needs_update() is true, so dquot_transfer() sets transfer_to[cnt] = dquot(A) while transfer_from[cnt] is still dquot(A). Because __dquot_transfer() does not check for transfer_to[cnt] == transfer_from[cnt], it calls dquot_add_inodes() and dquot_add_space() on dquot(A) before subtracting from transfer_from[cnt], temporarily double-charging dquot(A) for the file's usage and failing with -EDQUOT if A's hard limit cannot fit twice the file's usage.
Quoted 3 lines
mm/shmem.c +0
-0#if IS_ENABLED (CONFIG_UNICODE )if (!ctx->encoding && ctx->strict_encoding) {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=24
RFC PATCH v2 25/41 uidgid: parse and print ids in their text form
In reply to Jan KoesterAdd 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.
--- include/linux/uidgid.h | 19 ++++++ kernel/uidgid_r.c | 152 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 167 insertions(+), 4 deletions(-)
include/linux/uidgid.h +19 -0
@@ -190,6 +190,25 @@ static inline u32 kgid_hash(kgid_t gid)char *kuid_str (kuid_t uid,char buf[KID_STR_LEN ]);char *kgid_str (kgid_t gid,char buf[KID_STR_LEN ]); +char *kuid_str_signed (kuid_t uid,char buf[KID_STR_LEN ]); +char *kgid_str_signed (kgid_t gid,char buf[KID_STR_LEN ]); + +/* +* The text form of an id as an expression, in a buffer that lives until +* the end of the enclosing block -- for "%s" in place of "%u" (or "%d", +* with the _D variants, which write a legacy id as a signed number) of +* from_kuid(&init_user_ns, uid) in printf-like calls. +*/ +#define KUID_STR (uid) kuid_str(uid, (char [KID_STR_LEN]) {}) +#define KGID_STR (gid) kgid_str(gid, (char [KID_STR_LEN]) {}) +#define KUID_STR_D (uid) kuid_str_signed(uid, (char [KID_STR_LEN]) {}) +#define KGID_STR_D (gid) kgid_str_signed(gid, (char [KID_STR_LEN]) {}) +char *kuid_str_munged (struct user_namespace *to,kuid_t uid, +char buf[KID_STR_LEN ]); +char *kgid_str_munged (struct user_namespace *to,kgid_t gid, +char buf[KID_STR_LEN ]); +kuid_t make_kuid_str (struct user_namespace *from,const char *str); +kgid_t make_kgid_str (struct user_namespace *from,const char *str);#ifdef CONFIG_USER_NS
kernel/uidgid_r.c +148 -4
178 lines not on this page · raw message
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 25/41] uidgid: parse and print ids in their text form
Sashiko has reviewed this patch and found no issues.
Quoted 13 lines
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.
Quoted 3 lines
Assisted-by Claude:claude-opus-5-5Signed-off-by Jan Koester <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=25
RFC PATCH v2 26/41 proc: show UUID and GUID ids in status, accept them for loginuid
In reply to Jan Koester/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".
--- fs/proc/array.c | 17 ++++++++++++++++- fs/proc/base.c | 38 ++++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 15 deletions(-)
fs/proc/array.c +16 -1
@@ -156,6 +156,7 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,const struct cred *cred;pid_t ppid, tpid =0 , tgid, ngid;unsigned int max_fds =0 ; +char idbuf[KID_STR_LEN ];rcu_read_lock (); tracer =ptrace_parent (p);
@@ -200,10 +201,24 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,for (g =0 ; g < group_info->ngroups; g++)seq_put_decimal_ull (m, g ?" " :"" ,from_kgid_munged (user_ns, group_info->gid[g])); -put_cred (cred);/* Trailing space shouldn't have been added in the first place. */ seq_putc (m,' ' ); +/* The same ids including UUIDs and GUIDs, as kuid_str() writes them */ +seq_printf (m,"\nUid_r:\t%s" ,kuid_str_munged (user_ns, cred->uid, idbuf)); +seq_printf (m,"\t%s" ,kuid_str_munged (user_ns, cred->euid, idbuf)); +seq_printf (m,"\t%s" ,kuid_str_munged (user_ns, cred->suid, idbuf)); +seq_printf (m,"\t%s" ,kuid_str_munged (user_ns, cred->fsuid, idbuf)); +seq_printf (m,"\nGid_r:\t%s" ,kgid_str_munged (user_ns, cred->gid, idbuf)); +seq_printf (m,"\t%s" ,kgid_str_munged (user_ns, cred->egid, idbuf)); +seq_printf (m,"\t%s" ,kgid_str_munged (user_ns, cred->sgid, idbuf)); +seq_printf (m,"\t%s" ,kgid_str_munged (user_ns, cred->fsgid, idbuf)); +seq_puts (m,"\nGroups_r:\t" ); +for (g =0 ; g < group_info->ngroups; g++) +seq_printf (m,"%s%s" , g ?" " :"" , +kgid_str_munged (user_ns, group_info->gid[g], idbuf)); +put_cred (cred); +#ifdef CONFIG_PID_NS seq_puts (m,"\nNStgid:" );for (g = ns->level; g <= pid->level; g++)
fs/proc/base.c +24 -14
@@ -1290,20 +1290,26 @@ static const struct file_operations proc_oom_score_adj_operations = { };#ifdef CONFIG_AUDIT -#define TMPBUFLEN 11 +#define TMPBUFLEN KID_STR_LENstatic ssize_t proc_loginuid_read (struct file * file,char __user * buf,size_t count,loff_t *ppos) {struct inode * inode =file_inode (file);struct task_struct *task =get_proc_task (inode); +struct user_namespace *ns = file->f_cred->user_ns;ssize_t length;char tmpbuf[TMPBUFLEN ]; +kuid_t loginuid;if (!task)return -ESRCH ; - length =scnprintf (tmpbuf,TMPBUFLEN ,"%u" , -from_kuid (file->f_cred->user_ns, -audit_get_loginuid (task))); + loginuid =audit_get_loginuid (task); +/* a UUID or GUID loginuid as text, if @ns can see it */ +if (!uid_is_legacy (loginuid) &&kuid_has_mapping (ns, loginuid)) + length =strlen (kuid_str (loginuid, tmpbuf)); +else + length =scnprintf (tmpbuf,TMPBUFLEN ,"%u" , +from_kuid (ns, loginuid));put_task_struct (task);return simple_read_from_buffer (buf, count, ppos, tmpbuf, length); }
@@ -1312,7 +1318,7 @@ static ssize_t proc_loginuid_write(struct file * file, const char __user * buf, size_t count, loff_t *ppos) { struct inode * inode = file_inode(file); -uid_t loginuid; +char tmpbuf[TMPBUFLEN ];kuid_t kloginuid;int rv;
@@ -1332,16 +1338,20 @@ static ssize_t proc_loginuid_write(struct file * file, const char __user * buf,return -EINVAL ; } - rv =kstrtou32_from_user (buf, count,10 , &loginuid); -if (rv <0 ) -return rv; +/* a decimal uid, a UUID or a GUID in braces */ +if (count >=sizeof (tmpbuf)) +return -EINVAL ; +if (copy_from_user (tmpbuf, buf, count)) +return -EFAULT ; + tmpbuf[count] ='\0' ; -/* is userspace tring to explicitly UNSET the loginuid? */ -if (loginuid ==AUDIT_UID_UNSET ) { - kloginuid =INVALID_UID ; - }else { - kloginuid =make_kuid (file->f_cred->user_ns, loginuid); -if (!uid_valid (kloginuid)) + kloginuid =make_kuid_str (file->f_cred->user_ns, tmpbuf); +if (!uid_valid (kloginuid)) { +u32 loginuid; + +/* is userspace tring to explicitly UNSET the loginuid? */ +if (kstrtou32 (tmpbuf,10 , &loginuid) || + loginuid !=AUDIT_UID_UNSET )return -EINVAL ; }
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 26/41] proc: show UUID and GUID ids in status, accept them for loginuid
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] proc: off-by-one TMPBUFLEN in proc_loginuid_write() rejects GUID with newline - [Medium] proc…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] proc: off-by-one TMPBUFLEN in proc_loginuid_write() rejects GUID with newline
- [Medium] proc: torn read of 20-byte loginuid in proc_loginuid_read()
--
commit 272e06b9ffc63c454062912295a6fc0f1ae20fab
Author: Jan Koester <[email protected]>
proc: show UUID and GUID ids in status, accept them for loginuid
This commit adds Uid_r, Gid_r, and Groups_r lines to /proc/<pid>/status to display user and group ids in text form via kuid_str_munged() and kgid_str_munged(). It also updates /proc/<pid>/loginuid to accept and display text-formatted uuid and guid ids alongside classic numeric uids.
Quoted 22 lines
fs/proc/base.c +3
-1@@ -1290,20 +1290,26 @@ static const struct file_operations proc_oom_score_adj_operations = { };#ifdef CONFIG_AUDIT -#define TMPBUFLEN 11 +#define TMPBUFLEN KID_STR_LENstatic ssize_t proc_loginuid_read (struct file * file,char __user * buf,size_t count,loff_t *ppos) {struct inode * inode =file_inode (file);struct task_struct *task =get_proc_task (inode); +struct user_namespace *ns = file->f_cred->user_ns;ssize_t length;char tmpbuf[TMPBUFLEN ]; +kuid_t loginuid;if (!task)return -ESRCH ;
fs/proc/base.c static const struct file_operations proc_oom_score_adj_operations = { · line 1312
Quoted 10 lines
fs/proc/base.c +7
-3- length =scnprintf (tmpbuf,TMPBUFLEN ,"%u" , -from_kuid (file->f_cred->user_ns, -audit_get_loginuid (task))); + loginuid =audit_get_loginuid (task); +/* a UUID or GUID loginuid as text, if @ns can see it */ +if (!uid_is_legacy (loginuid) &&kuid_has_mapping (ns, loginuid)) + length =strlen (kuid_str (loginuid, tmpbuf)); +else + length =scnprintf (tmpbuf,TMPBUFLEN ,"%u" , +from_kuid (ns, loginuid));
[Severity: Medium]
Can proc_loginuid_read() observe a torn 20-byte kuid_t when reading task->loginuid concurrently with proc_loginuid_write() -> audit_set_loginuid()?
In kernel/audit.c:audit_set_loginuid():
current->sessionid = sessionid; current->loginuid = loginuid;
Updating current->loginuid is an unsynchronized 20-byte struct store, and audit_get_loginuid(task) in proc_loginuid_read() copies task->loginuid from a potentially running target task without a lock or seqcount retry loop.
When transitioning between a legacy id (such as INVALID_UID) and a uuid or guid id, a concurrent reader of /proc/<pid>/loginuid could see the new .type before all 16 bytes of .uuid/.guid are written (or after .legacy is overwritten when unsetting), causing kuid_str() to format a corrupted uuid or guid string. Conversely, seeing the old KID_LEGACY .type with the first 4 bytes of the new .uuid/.guid already stored would cause from_kuid() to return a bogus numeric uid to userspace.
Would a seqcount or lock around task->loginuid be needed here to prevent torn reads?
Quoted 23 lines
fs/proc/base.c +5
-4put_task_struct (task);return simple_read_from_buffer (buf, count, ppos, tmpbuf, length); }@@ -1312,7 +1318,7 @@ static ssize_t proc_loginuid_write(struct file * file, const char __user * buf, size_t count, loff_t *ppos) { struct inode * inode = file_inode(file); -uid_t loginuid; +char tmpbuf[TMPBUFLEN ];kuid_t kloginuid;int rv;@@ -1332,16 +1338,20 @@ static ssize_t proc_loginuid_write(struct file * file, const char __user * buf,return -EINVAL ; } - rv =kstrtou32_from_user (buf, count,10 , &loginuid); -if (rv <0 ) -return rv; +/* a decimal uid, a UUID or a GUID in braces */ +if (count >=sizeof (tmpbuf)) +return -EINVAL ; +if (copy_from_user (tmpbuf, buf, count))
fs/proc/base.c static ssize_t proc_loginuid_write(struct file * file, const char __user * buf, · line 1348
Quoted 10 lines
fs/proc/base.c +3
-6+return -EFAULT ; + tmpbuf[count] ='\0' ; -/* is userspace tring to explicitly UNSET the loginuid? */ -if (loginuid ==AUDIT_UID_UNSET ) { - kloginuid =INVALID_UID ; - }else { - kloginuid =make_kuid (file->f_cred->user_ns, loginuid); -if (!uid_valid (kloginuid)) + kloginuid =make_kuid_str (file->f_cred->user_ns, tmpbuf);
[Severity: Medium]
Does this size check in proc_loginuid_write() reject a guid in braces when written with a trailing newline?
In include/linux/uidgid.h, KID_STR_LEN is 39, which is the exact size of a 38-character guid in braces ("{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}") plus the terminating nul byte.
Meanwhile, make_kuid_str() -> kid_r_from_str() in kernel/uidgid_r.c is designed to accept an optional trailing newline before checking the length against KID_STR_LEN:
if (len && str[len - 1] == '\n') len--; if (!len || len >= sizeof(buf)) return -EINVAL;
Because TMPBUFLEN is defined as KID_STR_LEN (39), writing a 38-byte guid in braces followed by '\n' passes count == 39 to proc_loginuid_write(), which hits count >= sizeof(tmpbuf) and returns -EINVAL before reaching make_kuid_str().
Should tmpbuf in proc_loginuid_write() (or TMPBUFLEN) be sized to KID_STR_LEN + 1 so that a guid in braces with a trailing newline is accepted just like decimal uids and uuids with a trailing newline?
Quoted 9 lines
fs/proc/base.c +6
-0+if (!uid_valid (kloginuid)) { +u32 loginuid; + +/* is userspace tring to explicitly UNSET the loginuid? */ +if (kstrtou32 (tmpbuf,10 , &loginuid) || + loginuid !=AUDIT_UID_UNSET )return -EINVAL ; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=26
RFC PATCH v2 27/41 audit: log UUID and GUID ids in full
In reply to Jan KoesterAudit 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.
--- 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
@@ -65,8 +65,6 @@ static void tty_audit_log(const char *description, dev_t dev, {struct audit_buffer *ab;pid_t pid =task_pid_nr (current); -uid_t uid =from_kuid (&init_user_ns,task_uid (current)); -uid_t loginuid =from_kuid (&init_user_ns,audit_get_loginuid (current));unsigned int sessionid =audit_get_sessionid (current);char name[TASK_COMM_LEN ];
@@ -74,8 +72,9 @@ static void tty_audit_log(const char *description, dev_t dev,if (!ab)return ; -audit_log_format (ab,"%s pid=%u uid=%u auid=%u ses=%u major=%d minor=%d comm=" , - description, pid, uid, loginuid, sessionid, +audit_log_format (ab,"%s pid=%u uid=%s auid=%s ses=%u major=%d minor=%d comm=" , + description, pid,KUID_STR (task_uid (current)), +KUID_STR (audit_get_loginuid (current)), sessionid,MAJOR (dev),MINOR (dev));get_task_comm (name, current);audit_log_untrustedstring (ab, name);
kernel/audit.c +23 -27
98 lines not on this page · raw message
kernel/auditsc.c +27 -28
104 lines not on this page · raw message
net/core/dev.c +4 -4
@@ -9718,12 +9718,12 @@ int __dev_set_promiscuity(struct net_device *dev, int inc, bool notify)current_uid_gid (&uid, &gid);audit_log (audit_context (),GFP_ATOMIC ,AUDIT_ANOM_PROMISCUOUS , -"dev=%s prom=%d old_prom=%d auid=%u uid=%u gid=%u ses=%u" , +"dev=%s prom=%d old_prom=%d auid=%s uid=%s gid=%s ses=%u" , dev->name, (dev->flags &IFF_PROMISC ), (old_flags &IFF_PROMISC ), -from_kuid (&init_user_ns,audit_get_loginuid (current)), -from_kuid (&init_user_ns, uid), -from_kgid (&init_user_ns, gid), +KUID_STR (audit_get_loginuid (current)), +KUID_STR (uid), +KGID_STR (gid),audit_get_sessionid (current)); }
net/netlabel/netlabel_user.c +2 -2
@@ -92,8 +92,8 @@ struct audit_buffer *netlbl_audit_start_common(int type,if (audit_buf ==NULL )return NULL ; -audit_log_format (audit_buf,"netlabel: auid=%u ses=%u" , -from_kuid (&init_user_ns, audit_info->loginuid), +audit_log_format (audit_buf,"netlabel: auid=%s ses=%u" , +KUID_STR (audit_info->loginuid), audit_info->sessionid);audit_log_subj_ctx (audit_buf, &audit_info->prop);
security/apparmor/file.c +4 -4
@@ -60,10 +60,10 @@ static void file_audit_cb(struct audit_buffer *ab, void *va)audit_log_format (ab," denied_mask=\"%s\"" , str); }if (ad->request &AA_AUDIT_FILE_MASK ) { -audit_log_format (ab," fsuid=%d" , -from_kuid (&init_user_ns, fsuid)); -audit_log_format (ab," ouid=%d" , -from_kuid (&init_user_ns, ad->fs.ouid)); +audit_log_format (ab," fsuid=%s" , +KUID_STR_D (fsuid)); +audit_log_format (ab," ouid=%s" , +KUID_STR_D (ad->fs.ouid)); }if (ad->peer) {
security/integrity/integrity_audit.c +3 -3
@@ -47,10 +47,10 @@ void integrity_audit_message(int audit_msgno, struct inode *inode, ab =audit_log_start (audit_context (),GFP_KERNEL , audit_msgno);if (!ab)return ; -audit_log_format (ab,"pid=%d uid=%u auid=%u ses=%u" , +audit_log_format (ab,"pid=%d uid=%s auid=%s ses=%u" ,task_pid_nr (current), -from_kuid (&init_user_ns,current_uid ()), -from_kuid (&init_user_ns,audit_get_loginuid (current)), +KUID_STR (current_uid ()), +KUID_STR (audit_get_loginuid (current)),audit_get_sessionid (current));audit_log_task_context (ab);audit_log_format (ab," op=%s cause=%s comm=" , op, cause);
security/ipe/audit.c +6 -6
@@ -220,8 +220,8 @@ void ipe_audit_policy_activation(const struct ipe_policy *const op,audit_log_format (ab," " ); }audit_policy (ab,AUDIT_NEW_ACTIVE_POLICY_FMT , np); -audit_log_format (ab," auid=%u ses=%u lsm=ipe res=1" , -from_kuid (&init_user_ns,audit_get_loginuid (current)), +audit_log_format (ab," auid=%s ses=%u lsm=ipe res=1" , +KUID_STR (audit_get_loginuid (current)),audit_get_sessionid (current));audit_log_end (ab);
@@ -248,8 +248,8 @@ void ipe_audit_policy_load(const struct ipe_policy *const p) err =PTR_ERR (p); } -audit_log_format (ab," auid=%u ses=%u lsm=ipe res=%d errno=%d" , -from_kuid (&init_user_ns,audit_get_loginuid (current)), +audit_log_format (ab," auid=%s ses=%u lsm=ipe res=%d errno=%d" , +KUID_STR (audit_get_loginuid (current)),audit_get_sessionid (current), !err, err);audit_log_end (ab);
@@ -269,10 +269,10 @@ void ipe_audit_enforce(bool new_enforce, bool old_enforce)return ;audit_log (audit_context (),GFP_KERNEL ,AUDIT_MAC_STATUS , -"enforcing=%d old_enforcing=%d auid=%u ses=%u" +"enforcing=%d old_enforcing=%d auid=%s ses=%u" " enabled=1 old-enabled=1 lsm=ipe res=1" , new_enforce, old_enforce, -from_kuid (&init_user_ns,audit_get_loginuid (current)), +KUID_STR (audit_get_loginuid (current)),audit_get_sessionid (current));audit_log_end (ab);
security/selinux/selinuxfs.c +4 -4
@@ -163,10 +163,10 @@ static ssize_t sel_write_enforce(struct file *file, const char __user *buf,if (length) goto out;audit_log (audit_context (),GFP_KERNEL ,AUDIT_MAC_STATUS , -"enforcing=%d old_enforcing=%d auid=%u ses=%u" +"enforcing=%d old_enforcing=%d auid=%s ses=%u" " enabled=1 old-enabled=1 lsm=selinux res=1" , new_value, old_value, -from_kuid (&init_user_ns,audit_get_loginuid (current)), +KUID_STR (audit_get_loginuid (current)),audit_get_sessionid (current));enforcing_set (new_value);if (new_value)
@@ -581,8 +581,8 @@ static ssize_t sel_write_load(struct file *file, const char __user *buf,selinux_policy_commit (&load_state); length = count;audit_log (audit_context (),GFP_KERNEL ,AUDIT_MAC_POLICY_LOAD , -"auid=%u ses=%u lsm=selinux res=1" , -from_kuid (&init_user_ns,audit_get_loginuid (current)), +"auid=%s ses=%u lsm=selinux res=1" , +KUID_STR (audit_get_loginuid (current)),audit_get_sessionid (current)); out_unlock:
security/selinux/ss/services.c +2 -2
@@ -3012,11 +3012,11 @@ int security_set_bools(u32 len, const int *values)if (new_state != old_state) {audit_log (audit_context (),GFP_ATOMIC ,AUDIT_MAC_CONFIG_CHANGE , -"bool=%s val=%d old_val=%d auid=%u ses=%u" , +"bool=%s val=%d old_val=%d auid=%s ses=%u" ,sym_name (&newpolicy->policydb,SYM_BOOLS , i), new_state, old_state, -from_kuid (&init_user_ns,audit_get_loginuid (current)), +KUID_STR (audit_get_loginuid (current)),audit_get_sessionid (current)); newpolicy->policydb.bool_val_to_struct[i]->state = new_state; }
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 27/41] audit: log UUID and GUID ids in full
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] audit: xfrm_audit_helper_usrinfo() still logs UUID/GUID auid as 4294967295 - [Medium] audit…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] audit: xfrm_audit_helper_usrinfo() still logs UUID/GUID auid as 4294967295
- [Medium] audit: Landlock log_domain() still logs UUID/GUID creator uid as 4294967295 --
commit 91e2cc101c7d60a9061395bf85632c87b9500902
Author: Jan Koester <[email protected]>
audit: log UUID and GUID ids in full
This commit replaces from_kuid() and from_kgid() calls in audit record formatting with KUID_STR() and KGID_STR() so that uuid and guid user and group identifiers are logged in their text form rather than as -1 (4294967295).
Quoted 6 lines
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.
Quoted 8 lines
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_INFOreply keeps its 32 bit field.Assisted-by Claude:claude-opus-5-5Signed-off-by Jan Koester <[email protected]>
[Severity: Medium]
Should xfrm_audit_helper_usrinfo() in include/net/xfrm.h also be converted to use KUID_STR()?
When a task running under a uuid or guid loginuid adds or deletes an ipsec policy or state, xfrm_audit_policy_add(), xfrm_audit_policy_delete(), xfrm_audit_state_add(), or xfrm_audit_state_delete() calls xfrm_audit_helper_usrinfo() with task_valid set to true:
include/net/xfrm.h:xfrm_audit_helper_usrinfo() {
const unsigned int auid = from_kuid(&init_user_ns, task_valid ?
audit_get_loginuid(current) :
INVALID_UID);
const unsigned int ses = task_valid ? audit_get_sessionid(current) :
AUDIT_SID_UNSET;
audit_log_format(audit_buf, " auid=%u ses=%u", auid, ses);
audit_log_task_context(audit_buf);
}Because from_kuid(&init_user_ns, ...) returns (uid_t)-1 for a uuid or guid, AUDIT_MAC_IPSEC_EVENT records will still log auid=4294967295 (unset) instead of formatting task_valid ? audit_get_loginuid(current) : INVALID_UID with KUID_STR() and %s.
[Severity: Medium]
What about Landlock domain audit logging in security/landlock/domain.c, security/landlock/domain.h, and security/landlock/audit.c?
When a task with a uuid or guid current_uid() restricts itself via landlock_restrict_self() -> landlock_init_hierarchy_log() -> get_current_details(), the creator's uid is converted with from_kuid() and stored as a 32-bit uid_t in struct landlock_details:
security/landlock/domain.h:
struct landlock_details {
struct pid *pid;
uid_t uid;
char comm[TASK_COMM_LEN];
char exe_path[];
};security/landlock/domain.c:get_current_details() {
...
memcpy(details->exe_path, path_str, path_size);
details->pid = get_pid(task_tgid(current));
details->uid = from_kuid(&init_user_ns, current_uid());
get_task_comm(details->comm, current);
return details;
}When log_domain() in security/landlock/audit.c later emits the AUDIT_LANDLOCK_DOMAIN record, it logs hierarchy->details->uid with %u:
security/landlock/audit.c:log_domain() {
...
audit_log_format(
ab,
"domain=%llx status=allocated mode=enforcing pid=%d uid=%u exe=",
hierarchy->id, pid_nr(hierarchy->details->pid),
hierarchy->details->uid);
...
}For a uuid or guid user, from_kuid(&init_user_ns, current_uid()) yields (uid_t)-1, causing log_domain() to log uid=4294967295. Could struct landlock_details store a kuid_t instead and format it with KUID_STR() and uid=%s in log_domain()?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=27
RFC PATCH v2 28/41 net: add SO_PEERCRED_R, SO_PEERGROUPS_R and SCM_CREDENTIALS_R
In reply to Jan KoesterServices 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.
--- arch/alpha/include/uapi/asm/socket.h | 5 ++ arch/mips/include/uapi/asm/socket.h | 5 ++ arch/parisc/include/uapi/asm/socket.h | 5 ++ arch/sparc/include/uapi/asm/socket.h | 5 ++ include/linux/socket.h | 1 + include/net/sock.h | 4 +- include/uapi/asm-generic/socket.h | 5 ++ 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, 186 insertions(+), 34 deletions(-)
arch/alpha/include/uapi/asm/socket.h +5 -0
@@ -153,10 +153,15 @@#define SO_PASSRIGHTS 83#define SO_INQ 84 +#define SCM_INQ SO_INQ#define SO_RIGHTS_NOTRUNC 85 +#define SO_PEERCRED_R 86 +#define SO_PEERGROUPS_R 87 +#define SO_PASSCRED_R 88 +#if !defined(__KERNEL__)#if __BITS_PER_LONG ==64
arch/mips/include/uapi/asm/socket.h +5 -0
@@ -164,10 +164,15 @@#define SO_PASSRIGHTS 83#define SO_INQ 84 +#define SCM_INQ SO_INQ#define SO_RIGHTS_NOTRUNC 85 +#define SO_PEERCRED_R 86 +#define SO_PEERGROUPS_R 87 +#define SO_PASSCRED_R 88 +#if !defined(__KERNEL__)#if __BITS_PER_LONG ==64
arch/parisc/include/uapi/asm/socket.h +5 -0
@@ -145,10 +145,15 @@#define SO_PASSRIGHTS 0x4051#define SO_INQ 0x4052 +#define SCM_INQ SO_INQ#define SO_RIGHTS_NOTRUNC 0x4053 +#define SO_PEERCRED_R 0x4054 +#define SO_PEERGROUPS_R 0x4055 +#define SO_PASSCRED_R 0x4056 +#if !defined(__KERNEL__)#if __BITS_PER_LONG ==64
arch/sparc/include/uapi/asm/socket.h +5 -0
@@ -146,10 +146,15 @@#define SO_PASSRIGHTS 0x005c#define SO_INQ 0x005d +#define SCM_INQ SO_INQ#define SO_RIGHTS_NOTRUNC 0x005e +#define SO_PEERCRED_R 0x005f +#define SO_PEERGROUPS_R 0x0060 +#define SO_PASSCRED_R 0x0061 +#if !defined(__KERNEL__)
include/linux/socket.h +1 -0
@@ -193,6 +193,7 @@ static inline size_t msg_data_left(const struct msghdr *msg)#define SCM_CREDENTIALS 0x02/* rw: struct ucred */ #define SCM_SECURITY 0x03/* rw: security label */ #define SCM_PIDFD 0x04/* ro: pidfd (int) */ +#define SCM_CREDENTIALS_R 0x05/* rw: struct __kernel_ucred_r */ struct ucred {__u32 pid;
include/net/sock.h +3 -1
@@ -358,6 +358,7 @@ struct sk_filter;* @sk_scm_security: flagged by SO_PASSSEC to recv SCM_SECURITY * @sk_scm_pidfd: flagged by SO_PASSPIDFD to recv SCM_PIDFD * @sk_scm_rights: flagged by SO_PASSRIGHTS to recv SCM_RIGHTS +* @sk_scm_credentials_r: flagged by SO_PASSCRED_R to recv SCM_CREDENTIALS_R * @sk_scm_unused: unused flags for scm_recv() * @ns_tracker: tracker for netns reference * @sk_user_frags: xarray of pages the user is holding a reference on.
@@ -565,7 +566,8 @@ struct sock { sk_scm_security : 1, sk_scm_pidfd : 1, sk_scm_rights : 1, - sk_scm_unused : 4; + sk_scm_credentials_r : 1, + sk_scm_unused : 3; }; };u8 sk_clockid;
include/uapi/asm-generic/socket.h +5 -0
@@ -148,10 +148,15 @@#define SO_PASSRIGHTS 83#define SO_INQ 84 +#define SCM_INQ SO_INQ#define SO_RIGHTS_NOTRUNC 85 +#define SO_PEERCRED_R 86 +#define SO_PEERGROUPS_R 87 +#define SO_PASSCRED_R 88 +#if !defined(__KERNEL__)#if __BITS_PER_LONG ==64 || (defined(__x86_64__) && defined(__ILP32__))
include/uapi/linux/socket.h +9 -0
@@ -2,6 +2,8 @@#ifndef _UAPI_LINUX_SOCKET_H#define _UAPI_LINUX_SOCKET_H +#include <linux/uidgid_r.h> +/* * Desired design of maximum size and alignment (see RFC2553) */
@@ -35,4 +37,11 @@ struct __kernel_sockaddr_storage {#define SOCK_TXREHASH_DISABLED 0#define SOCK_TXREHASH_ENABLED 1 +/* SO_PEERCRED_R and SCM_CREDENTIALS_R: struct ucred with UUIDs and GUIDs */ +struct __kernel_ucred_r { +__u32 pid; +__kernel_uid_r_t uid; +__kernel_gid_r_t gid; +}; +#endif /* _UAPI_LINUX_SOCKET_H */
net/core/scm.c +62 -32
139 lines not on this page · raw message
net/core/sock.c +84 -0
114 lines not on this page · raw message
net/unix/af_unix.c +2 -1
@@ -803,7 +803,8 @@ static void copy_peercred(struct sock *sk, struct sock *peersk)static bool unix_may_passcred (const struct sock *sk) { -return sk->sk_scm_credentials || sk->sk_scm_pidfd; +return sk->sk_scm_credentials || sk->sk_scm_credentials_r || + sk->sk_scm_pidfd; }static int unix_listen (struct socket *sock,int backlog)
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 28/41] net: add SO_PEERCRED_R, SO_PEERGROUPS_R and SCM_CREDENTIALS_R
Sashiko has reviewed this patch and found no issues.
Quoted 14 lines
Services authenticate
AF_UNIXpeers withSO_PEERCRED,SO_PEERGROUPSandSCM_CREDENTIALS, which carry 32 bit ids: a UUID or GUID user shows up as the overflow id there.Add variants with
__kernel_uid_r_tids:-
SO_PEERCRED_Rreturns a struct__kernel_ucred_rof the peer,
-SO_PEERGROUPS_Rits supplementary groups as__kernel_gid_r_t,
-SO_PASSCRED_Rasks forSCM_CREDENTIALS_Rmessages, with a struct__kernel_ucred_r, next to or instead ofSCM_CREDENTIALS(a separate option, so receivers sizing their control buffer forSCM_CREDENTIALSdon't get truncated), andSCM_CREDENTIALS_Rcan be sent with the same privilege rules asSCM_CREDENTIALS.
Quoted 7 lines
The classic
SCM_CREDENTIALSsending 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 inSCM_CREDENTIALS_Rtoo.Assisted-by Claude:claude-opus-5-5Signed-off-by Jan Koester <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=28
RFC PATCH v2 29/41 signal: report the sender's UUID or GUID uid in si_uid_r
In reply to Jan Koestersi_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.
--- 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 | 48 ++++++++++++++++++++---------- 13 files changed, 129 insertions(+), 36 deletions(-)
fs/signalfd.c +3 -0
@@ -90,6 +90,7 @@ static int signalfd_copyinfo(struct iov_iter *to, kernel_siginfo_t const *kinfo)case SIL_KILL : new.ssi_pid = kinfo->si_pid; new.ssi_uid = kinfo->si_uid; + new.ssi_uid_r = kinfo->si_uid_r;break ;case SIL_TIMER : new.ssi_tid = kinfo->si_tid;
@@ -125,6 +126,7 @@ static int signalfd_copyinfo(struct iov_iter *to, kernel_siginfo_t const *kinfo)case SIL_CHLD : new.ssi_pid = kinfo->si_pid; new.ssi_uid = kinfo->si_uid; + new.ssi_uid_r = kinfo->si_uid_r; new.ssi_status = kinfo->si_status; new.ssi_utime = kinfo->si_utime; new.ssi_stime = kinfo->si_stime;
@@ -135,6 +137,7 @@ static int signalfd_copyinfo(struct iov_iter *to, kernel_siginfo_t const *kinfo)*/ new.ssi_pid = kinfo->si_pid; new.ssi_uid = kinfo->si_uid; + new.ssi_uid_r = kinfo->si_uid_r; new.ssi_ptr = (long ) kinfo->si_ptr; new.ssi_int = kinfo->si_int;break ;
include/linux/compat.h +6 -0
@@ -169,6 +169,12 @@ typedef struct compat_siginfo {union {int _pad[128 /sizeof (int ) -3 ]; +/* si_uid_r, at __SI_UID_R_OFFSET like in siginfo_t */ +struct { +int _uid_r_pad[__SI_UID_R_OFFSET /sizeof (int ) -3 ]; +__kernel_uid_r_t _uid_r; + } _sir; +/* kill() */ struct {compat_pid_t _pid;/* sender's pid */
include/linux/ptrace.h +1 -1
@@ -347,7 +347,7 @@ static inline void user_single_step_report(struct pt_regs *regs) info.si_errno =0 ; info.si_code =SI_USER ; info.si_pid =0 ; - info.si_uid =0 ; +siginfo_set_kernel_uid (&info); force_sig_info(&info); }#endif
include/linux/signal.h +22 -0
@@ -6,6 +6,7 @@#include <linux/list.h> #include <linux/signal_types.h> #include <linux/string.h> +#include <linux/uidgid.h> struct task_struct ;
@@ -23,6 +24,27 @@ static inline void clear_siginfo(kernel_siginfo_t *info)memset (info,0 ,sizeof (*info)); } +struct user_namespace ; + +/* +* Sets si_uid and si_uid_r to @uid as seen from @ns (the receiver's user +* namespace), the overflow id if it has no mapping there. +*/ +static inline void siginfo_set_uid (kernel_siginfo_t *info, +struct user_namespace *ns,kuid_t uid) +{ + info->si_uid =from_kuid_munged (ns, uid); +from_kuid_r_munged (ns, uid, &info->si_uid_r); +} + +/* si_uid and si_uid_r of a signal from the kernel: 0 */ +static inline void siginfo_set_kernel_uid (kernel_siginfo_t *info) +{ + info->si_uid =0 ; +memset (&info->si_uid_r,0 ,sizeof (info->si_uid_r)); + info->si_uid_r.type =UID_R_LEGACY ; +} +#define SI_EXPANSION_SIZE (sizeof(struct siginfo) - sizeof(struct kernel_siginfo)) static inline void copy_siginfo_to_external(siginfo_t *to,
include/linux/signal_types.h +4 -1
@@ -10,7 +10,10 @@#include <uapi/linux/signal.h> typedef struct kernel_siginfo { -__SIGINFO ; +union { +__SIGINFO ; +__SIGINFO_UID_R ; + }; }kernel_siginfo_t ;struct ucounts ;
include/uapi/asm-generic/siginfo.h +17 -0
@@ -4,6 +4,7 @@#include <linux/compiler.h> #include <linux/types.h> +#include <linux/uidgid_r.h> typedef union sigval { int sival_int;
@@ -131,9 +132,24 @@ struct { \ }#endif /* __ARCH_HAS_SWAPPED_SIGINFO */ +/* +* The sender's uid as __kernel_uid_r_t (a UUID or GUID too), for the +* signals with si_pid and si_uid. It lives at the same offset in every +* layout and ABI, past the end of union __sifields; UID_R_NONE where the +* kernel doesn't set it. +*/ +#define __SI_UID_R_OFFSET 96 + +#define __SIGINFO_UID_R \ +struct { \ + int _uid_r_pad[__SI_UID_R_OFFSET / sizeof(int)]; \ + __kernel_uid_r_t _uid_r; \ +} _sir +typedef struct siginfo {union {__SIGINFO ; +__SIGINFO_UID_R ;int _si_pad[SI_MAX_SIZE /sizeof (int )]; }; } __ARCH_SI_ATTRIBUTES siginfo_t;
@@ -143,6 +159,7 @@ typedef struct siginfo {*/ #define si_pid _sifields._kill._pid#define si_uid _sifields._kill._uid +#define si_uid_r _sir._uid_r#define si_tid _sifields._timer._tid#define si_overrun _sifields._timer._overrun#define si_sys_private _sifields._timer._sys_private
include/uapi/linux/signalfd.h +3 -1
@@ -10,6 +10,7 @@#define _UAPI_LINUX_SIGNALFD_H#include <linux/types.h> +#include <linux/uidgid_r.h> /* For O_CLOEXEC and O_NONBLOCK */ #include <linux/fcntl.h>
@@ -39,6 +40,7 @@ struct signalfd_siginfo {__s32 ssi_syscall;__u64 ssi_call_addr;__u32 ssi_arch; +__kernel_uid_r_t ssi_uid_r;/* sender's uid, also a UUID or GUID */ /* * Pad strcture to 128 bytes. Remember to update the
@@ -49,7 +51,7 @@ struct signalfd_siginfo {* comes out of a read(2) and we really don't want to have * a compat on read(2). */ -__u8 __pad[28 ]; +__u8 __pad[8 ]; };
io_uring/waitid.c +19 -13
@@ -29,7 +29,6 @@ struct io_waitid {atomic_t refs;struct wait_queue_head *head;struct siginfo __user *infop; -struct waitid_info info; };static void io_waitid_free (struct io_kiocb *req)
@@ -40,8 +39,10 @@ static void io_waitid_free(struct io_kiocb *req)io_req_async_data_free (req); } -static bool io_waitid_compat_copy_si (struct io_waitid *iw,int signo) +static bool io_waitid_compat_copy_si (struct io_kiocb *req,int signo) { + struct io_waitid *iw = io_kiocb_to_cmd(req, struct io_waitid); +struct io_waitid_async *iwa = req->async_data;struct compat_siginfo __user *infop;bool ret;
@@ -52,10 +53,12 @@ static bool io_waitid_compat_copy_si(struct io_waitid *iw, int signo)unsafe_put_user (signo, &infop->si_signo, Efault);unsafe_put_user (0 , &infop->si_errno, Efault); -unsafe_put_user (iw->info.cause, &infop->si_code, Efault); -unsafe_put_user (iw->info.pid, &infop->si_pid, Efault); -unsafe_put_user (iw->info.uid, &infop->si_uid, Efault); -unsafe_put_user (iw->info.status, &infop->si_status, Efault); +unsafe_put_user (iwa->info.cause, &infop->si_code, Efault); +unsafe_put_user (iwa->info.pid, &infop->si_pid, Efault); +unsafe_put_user (iwa->info.uid, &infop->si_uid, Efault); +unsafe_copy_to_user ((char __user *)&infop->_sifields._sir._uid_r, + (const char *)&iwa->info.uid_r,sizeof (iwa->info.uid_r), Efault); +unsafe_put_user (iwa->info.status, &infop->si_status, Efault); ret = true; done:user_write_access_end ();
@@ -68,23 +71,26 @@ static bool io_waitid_compat_copy_si(struct io_waitid *iw, int signo)static bool io_waitid_copy_si (struct io_kiocb *req,int signo) { struct io_waitid *iw = io_kiocb_to_cmd(req, struct io_waitid); +struct io_waitid_async *iwa = req->async_data;bool ret;if (!iw->infop)return true;if (io_is_compat (req->ctx)) -return io_waitid_compat_copy_si (iw, signo); +return io_waitid_compat_copy_si (req, signo);if (!user_write_access_begin (iw->infop,sizeof (*iw->infop)))return false;unsafe_put_user (signo, &iw->infop->si_signo, Efault);unsafe_put_user (0 , &iw->infop->si_errno, Efault); -unsafe_put_user (iw->info.cause, &iw->infop->si_code, Efault); -unsafe_put_user (iw->info.pid, &iw->infop->si_pid, Efault); -unsafe_put_user (iw->info.uid, &iw->infop->si_uid, Efault); -unsafe_put_user (iw->info.status, &iw->infop->si_status, Efault); +unsafe_put_user (iwa->info.cause, &iw->infop->si_code, Efault); +unsafe_put_user (iwa->info.pid, &iw->infop->si_pid, Efault); +unsafe_put_user (iwa->info.uid, &iw->infop->si_uid, Efault); +unsafe_copy_to_user ((char __user *)&iw->infop->si_uid_r, + (const char *)&iwa->info.uid_r,sizeof (iwa->info.uid_r), Efault); +unsafe_put_user (iwa->info.status, &iw->infop->si_status, Efault); ret = true; done:user_write_access_end ();
@@ -294,7 +300,7 @@ int io_waitid_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) iw->options =READ_ONCE (sqe->file_index); iw->head =NULL ; iw->infop =u64_to_user_ptr (READ_ONCE (sqe->addr2)); -memset (&iw->info,0 ,sizeof (iw->info)); +memset (&iwa->info,0 ,sizeof (iwa->info));return 0 ; }
@@ -305,7 +311,7 @@ int io_waitid(struct io_kiocb *req, unsigned int issue_flags)struct io_ring_ctx *ctx = req->ctx;int ret; - ret =kernel_waitid_prepare (&iwa->wo, iw->which, iw->upid, &iw->info, + ret =kernel_waitid_prepare (&iwa->wo, iw->which, iw->upid, &iwa->info, iw->options,NULL );if (ret) goto done;
io_uring/waitid.h +1 -0
@@ -5,6 +5,7 @@struct io_waitid_async {struct io_kiocb *req;struct wait_opts wo; +struct waitid_info info; };int io_waitid_prep (struct io_kiocb *req,const struct io_uring_sqe *sqe);
ipc/mqueue.c +2 -2
@@ -802,8 +802,8 @@ static void __do_notify(struct mqueue_inode_info *info)/* map current pid/uid into info->owner's namespaces */ sig_i.si_pid =task_tgid_nr_ns (current,ns_of_pid (info->notify_owner)); - sig_i.si_uid =from_kuid_munged (info->notify_user_ns, -current_uid ()); +siginfo_set_uid (&sig_i, info->notify_user_ns, +current_uid ());/* * We can't use kill_pid_info(), this signal should * bypass check_kill_permission(). It is from kernel
kernel/exit.c +15 -3
@@ -1185,7 +1185,8 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p) {int state, status;pid_t pid =task_pid_vnr (p); -uid_t uid =from_kuid_munged (current_user_ns (),task_uid (p)); +kuid_t kuid =task_uid (p); +uid_t uid =from_kuid_munged (current_user_ns (), kuid);struct waitid_info *infop;if (!likely (wo->wo_flags &WEXITED ))
@@ -1302,6 +1303,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p) } infop->pid = pid; infop->uid = uid; +from_kuid_r_munged (current_user_ns (), kuid, &infop->uid_r); }return pid;
@@ -1343,6 +1345,7 @@ static int wait_task_stopped(struct wait_opts *wo,struct waitid_info *infop;int exit_code, *p_code, why;uid_t uid =0 ;/* unneeded, required by compiler */ +kuid_t kuid =INVALID_UID ;pid_t pid;/*
@@ -1368,7 +1371,8 @@ static int wait_task_stopped(struct wait_opts *wo,if (!unlikely (wo->wo_flags &WNOWAIT )) *p_code =0 ; - uid =from_kuid_munged (current_user_ns (),task_uid (p)); + kuid =task_uid (p); + uid =from_kuid_munged (current_user_ns (), kuid); unlock_sig:spin_unlock_irq (&p->sighand->siglock);if (!exit_code)
@@ -1399,6 +1403,7 @@ static int wait_task_stopped(struct wait_opts *wo, infop->status = exit_code; infop->pid = pid; infop->uid = uid; +from_kuid_r_munged (current_user_ns (), kuid, &infop->uid_r); }return pid; }
@@ -1414,6 +1419,7 @@ static int wait_task_continued(struct wait_opts *wo, struct task_struct *p)struct waitid_info *infop;pid_t pid;uid_t uid; +kuid_t kuid;if (!unlikely (wo->wo_flags &WCONTINUED ))return 0 ;
@@ -1429,7 +1435,8 @@ static int wait_task_continued(struct wait_opts *wo, struct task_struct *p) }if (!unlikely (wo->wo_flags &WNOWAIT )) p->signal->flags &= ~SIGNAL_STOP_CONTINUED ; - uid =from_kuid_munged (current_user_ns (),task_uid (p)); + kuid =task_uid (p); + uid =from_kuid_munged (current_user_ns (), kuid);spin_unlock_irq (&p->sighand->siglock); pid =task_pid_vnr (p);
@@ -1447,6 +1454,7 @@ static int wait_task_continued(struct wait_opts *wo, struct task_struct *p) infop->cause =CLD_CONTINUED ; infop->pid = pid; infop->uid = uid; +from_kuid_r_munged (current_user_ns (), kuid, &infop->uid_r); infop->status =SIGCONT ; }return pid;
@@ -1846,6 +1854,8 @@ SYSCALL_DEFINE5(waitid, int, which, pid_t, upid, struct siginfo __user *,unsafe_put_user (info.cause, &infop->si_code, Efault);unsafe_put_user (info.pid, &infop->si_pid, Efault);unsafe_put_user (info.uid, &infop->si_uid, Efault); +unsafe_copy_to_user ((char __user *)&infop->si_uid_r, + (const char *)&info.uid_r,sizeof (info.uid_r), Efault);unsafe_put_user (info.status, &infop->si_status, Efault);user_write_access_end ();return err;
@@ -1989,6 +1999,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,unsafe_put_user (info.cause, &infop->si_code, Efault);unsafe_put_user (info.pid, &infop->si_pid, Efault);unsafe_put_user (info.uid, &infop->si_uid, Efault); +unsafe_copy_to_user ((char __user *)&infop->_sifields._sir._uid_r, + (const char *)&info.uid_r,sizeof (info.uid_r), Efault);unsafe_put_user (info.status, &infop->si_status, Efault);user_write_access_end ();return err;
kernel/exit.h +3 -0
@@ -2,9 +2,12 @@#ifndef LINUX_WAITID_H #define LINUX_WAITID_H +#include <linux/uidgid_r.h> +struct waitid_info {pid_t pid;uid_t uid; +__kernel_uid_r_t uid_r;/* uid as __kernel_uid_r_t */ int status;int cause; };
kernel/signal.c +33 -15
162 lines not on this page · raw message
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 29/41] signal: report the sender's UUID or GUID uid in si_uid_r
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] signal: broken userns UID mapping in send_signal_locked() and callers - [Medium] bpf: missing…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] signal: broken userns UID mapping in send_signal_locked() and callers
- [Medium] bpf: missing siginfo_set_kernel_uid() call in bpf_send_signal_common() --
commit 3fc8400fa91445ed3a591553195996d33af32cb3
Author: Jan Koester <[email protected]>
signal: report the sender's UUID or GUID uid in si_uid_r
This commit adds si_uid_r (__kernel_uid_r_t) at offset 96 in siginfo_t and compat_siginfo_t, along with ssi_uid_r in signalfd_siginfo, to report the sender's UUID or GUID UID for signals and waitid(). It introduces siginfo_set_uid() and siginfo_set_kernel_uid() to populate and translate si_uid and si_uid_r across signal generation, delivery, and wait paths.
Quoted 26 lines
include/linux/signal.h +11
-0@@ -6,6 +6,7 @@#include <linux/list.h> #include <linux/signal_types.h> #include <linux/string.h> +#include <linux/uidgid.h> struct task_struct ;@@ -23,6 +24,27 @@ static inline void clear_siginfo(kernel_siginfo_t *info)memset (info,0 ,sizeof (*info)); } +struct user_namespace ; + +/* +* Sets si_uid and si_uid_r to @uid as seen from @ns (the receiver's user +* namespace), the overflow id if it has no mapping there. +*/ +static inline void siginfo_set_uid (kernel_siginfo_t *info, +struct user_namespace *ns,kuid_t uid) +{ + info->si_uid =from_kuid_munged (ns, uid);
include/linux/signal.h static inline void clear_siginfo(kernel_siginfo_t *info) · line 46
Quoted 10 lines
include/linux/signal.h +10
-0+from_kuid_r_munged (ns, uid, &info->si_uid_r); +} + +/* si_uid and si_uid_r of a signal from the kernel: 0 */ +static inline void siginfo_set_kernel_uid (kernel_siginfo_t *info) +{ + info->si_uid =0 ; +memset (&info->si_uid_r,0 ,sizeof (info->si_uid_r)); + info->si_uid_r.type =UID_R_LEGACY ; +}
[Severity: Medium]
Should bpf_send_signal_common() in kernel/trace/bpf_trace.c also call siginfo_set_kernel_uid(&info) when sending a signal to a specific task?
When a BPF program invokes bpf_send_signal_task() with a non-NULL task, bpf_send_signal_common() takes the else branch and initializes info manually:
kernel/trace/bpf_trace.c:bpf_send_signal_common() {
if (!task) {
task = current;
siginfo = SEND_SIG_PRIV;
} else {
clear_siginfo(&info);
info.si_signo = sig;
info.si_errno = 0;
info.si_code = SI_KERNEL;
info.si_pid = 0;
info.si_uid = 0;
info.si_value.sival_ptr = (void __user __force *)(unsigned long)value;
siginfo = &info;
}
}Because info.si_uid = 0 is set directly after clear_siginfo(&info), info.si_uid_r remains UID_R_NONE instead of UID_R_LEGACY with uid 0, whereas calling bpf_send_signal() or bpf_send_signal_thread() (where task is NULL) uses SEND_SIG_PRIV and sets info.si_uid_r via siginfo_set_kernel_uid().
[ ... ]
Quoted 15 lines
ipc/mqueue.c +2
-2@@ -802,8 +802,8 @@ static void __do_notify(struct mqueue_inode_info *info)/* map current pid/uid into info->owner's namespaces */ sig_i.si_pid =task_tgid_nr_ns (current,ns_of_pid (info->notify_owner)); - sig_i.si_uid =from_kuid_munged (info->notify_user_ns, -current_uid ()); +siginfo_set_uid (&sig_i, info->notify_user_ns, +current_uid ());/* * We can't use kill_pid_info(), this signal should * bypass check_kill_permission(). It is from kernel
[ ... ]
Quoted 4 lines
kernel/signal.c +0
-0
[ ... ]
Quoted 4 lines
kernel/signal.c +0
-0@@ -1229,6 +1228,13 @@ int send_signal_locked(int sig, struct kernel_siginfo *info, info = &rewritten; uid =make_kuid (current_user_ns (), info->si_uid); rewritten.si_uid =from_kuid_munged (t_user_ns, uid);
kernel/signal.c int send_signal_locked(int sig, struct kernel_siginfo *info, · line 1240
Quoted 10 lines
kernel/signal.c +7
-0+if (rewritten.si_uid_r.type !=UID_R_NONE ) { +kuid_t uid_r =make_kuid_r (current_user_ns (), + &rewritten.si_uid_r); + +from_kuid_r_munged (t_user_ns, uid_r, + &rewritten.si_uid_r); + } }rcu_read_unlock ();#endif
[Severity: High]
Can this cross-user-namespace translation in send_signal_locked() corrupt both si_uid and si_uid_r in several signal delivery paths?
First, in send_signal_locked(), rewritten.si_uid is still derived from the 32-bit info->si_uid via make_kuid(current_user_ns(), info->si_uid) rather than from uid_r. When a process with a UUID or GUID UID in init_user_ns signals a task in a child user namespace t_user_ns (via prepare_kill_siginfo() in tkill(), tgkill(), or pidfd_send_signal() with info == NULL, or via rt_sigqueueinfo()), info->si_uid has already been munged to overflowuid (65534). make_kuid(&init_user_ns, 65534) then fabricates the legacy host UID KUIDT_INIT(65534). If t_user_ns maps legacy host UID 65534 to a valid container UID, rewritten.si_uid is set to that container UID instead of overflowuid, while rewritten.si_uid_r is munged to overflowuid.
Second, prepare_kill_siginfo() in kernel/signal.c pre-maps current_uid() into current_user_ns() before send_signal_locked() knows the target's user namespace:
kernel/signal.c:prepare_kill_siginfo() {
clear_siginfo(info);
info->si_signo = sig;
info->si_errno = 0;
info->si_code = (type == PIDTYPE_PID) ? SI_TKILL : SI_USER;
info->si_pid = task_tgid_vnr(current);
siginfo_set_uid(info, current_user_ns(), current_uid());
}If a task with a UUID or GUID UID enters a child user namespace via unshare(CLONE_NEWUSER) or setns() and calls tkill(), tgkill(), or pidfd_send_signal() (with info == NULL) targeting a task in init_user_ns, siginfo_set_uid() in prepare_kill_siginfo() immediately munges info->si_uid_r to UID_R_LEGACY / overflowuid because current_user_ns() != &init_user_ns. When send_signal_locked() subsequently translates from current_user_ns() to t_user_ns (&init_user_ns), the original UUID or GUID has already been lost.
Third, both do_notify_parent_cldstop() in kernel/signal.c and __do_notify() in ipc/mqueue.c already translate the sender's kuid_t into the receiver's user namespace via siginfo_set_uid(), but then pass the resulting siginfo to send_signal_locked():
kernel/signal.c:do_notify_parent_cldstop()
-> siginfo_set_uid(&info, task_cred_xxx(parent, user_ns), task_uid(tsk)) -> send_signal_locked(SIGCHLD, &info, parent, PIDTYPE_TGID)
ipc/mqueue.c:__do_notify()
-> siginfo_set_uid(&sig_i, info->notify_user_ns, current_uid()) -> do_send_sig_info(info->notify.sigev_signo, &sig_i, task, PIDTYPE_TGID)
-> send_signal_locked(sig, info, p, type)
When current_user_ns() != t_user_ns, send_signal_locked() translates si_uid and si_uid_r a second time assuming they were formatted in current_user_ns(). For example, if a child or mqueue sender with a UUID or GUID UID is in a child user namespace and the parent or notify_owner is in init_user_ns, siginfo_set_uid() writes the UUID or GUID into si_uid_r, and send_signal_locked() then calls make_kuid_r(current_user_ns(), ...), which fails in kid_r_to_128() and returns INVALID_UID, overwriting the valid UUID or GUID with overflowuid.
[ ... ]
完美! Let's double check everything before finalizing. Everything adheres strictly to the guidelines.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=29
RFC PATCH v2 30/41 ipc: add IPC_STAT_R and IPC_SET_R
In reply to Jan KoesterThe 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.
--- 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
@@ -428,7 +428,7 @@ static inline void audit_ptrace(struct task_struct *t)/* Private API (for audit.c only) */ extern void __audit_ipc_obj (struct kern_ipc_perm *ipcp); -extern void __audit_ipc_set_perm (unsigned long qbytes,uid_t uid,gid_t gid,umode_t mode); +extern void __audit_ipc_set_perm (unsigned long qbytes,kuid_t uid,kgid_t gid,umode_t mode);extern void __audit_bprm (struct linux_binprm *bprm);extern int __audit_socketcall (int nargs,unsigned long *args);extern int __audit_sockaddr (int len,void *addr);
@@ -460,7 +460,7 @@ static inline void audit_fd_pair(int fd1, int fd2)if (unlikely (!audit_dummy_context ()))__audit_fd_pair (fd1, fd2); } -static inline void audit_ipc_set_perm (unsigned long qbytes,uid_t uid,gid_t gid,umode_t mode) +static inline void audit_ipc_set_perm (unsigned long qbytes,kuid_t uid,kgid_t gid,umode_t mode) {if (unlikely (!audit_dummy_context ()))__audit_ipc_set_perm (qbytes, uid, gid, mode);
@@ -652,8 +652,8 @@ static inline void audit_seccomp_actions_logged(const char *names, { }static inline void audit_ipc_obj (struct kern_ipc_perm *ipcp) { } -static inline void audit_ipc_set_perm (unsigned long qbytes,uid_t uid, -gid_t gid,umode_t mode) +static inline void audit_ipc_set_perm (unsigned long qbytes,kuid_t uid, +kgid_t gid,umode_t mode) { }static inline void audit_bprm (struct linux_binprm *bprm) { }
include/uapi/linux/ipc.h +17 -0
@@ -3,6 +3,7 @@#define _UAPI_LINUX_IPC_H#include <linux/types.h> +#include <linux/uidgid_r.h> #define IPC_PRIVATE ((__kernel_key_t) 0)
@@ -40,6 +41,22 @@ struct ipc_perm#define IPC_SET 1/* set ipc_perm options */ #define IPC_STAT 2/* get ipc_perm options */ #define IPC_INFO 3/* see ipcs */ +#define IPC_SET_R 21/* set uid, gid and mode from struct ipc_perm_r */ +#define IPC_STAT_R 22/* get struct ipc_perm_r */ + +/* +* The ids and mode of an ipc object for IPC_STAT_R and IPC_SET_R, which +* also hold UUIDs and GUIDs; IPC_SET_R uses uid, gid and mode. The other +* attributes of the object come from IPC_STAT. +*/ +struct ipc_perm_r { +__kernel_key_t key; +__u32 mode; +__kernel_uid_r_t uid; +__kernel_gid_r_t gid; +__kernel_uid_r_t cuid; +__kernel_gid_r_t cgid; +};/* * Version flags for semctl, msgctl, and shmctl commands
ipc/msg.c +30 -10
@@ -398,8 +398,10 @@ copy_msqid_from_user(struct msqid64_ds *out, void __user *buf, int version)* to be held in write mode. * NOTE: no locks must be held, the rwsem is taken inside this function. */ +/* IPC_SET_R is IPC_SET without a new queue size */ static int msgctl_down (struct ipc_namespace *ns,int msqid,int cmd, -struct ipc64_perm *perm,int msg_qbytes) +const struct ipc_set_ids *set,int msg_qbytes, +bool set_qbytes) {struct kern_ipc_perm *ipcp;struct msg_queue *msq;
@@ -409,7 +411,7 @@ static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd,rcu_read_lock (); ipcp =ipcctl_obtain_check (ns, &msg_ids (ns), msqid, cmd, - perm, msg_qbytes); + set, msg_qbytes);if (IS_ERR (ipcp)) { err =PTR_ERR (ipcp); goto out_unlock1;
@@ -431,18 +433,19 @@ static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd, {DEFINE_WAKE_Q (wake_q); -if (msg_qbytes > ns->msg_ctlmnb && +if (set_qbytes && msg_qbytes > ns->msg_ctlmnb && !capable (CAP_SYS_RESOURCE )) { err = -EPERM ; goto out_unlock1; }ipc_lock_object (&msq->q_perm); - err =ipc_update_perm (perm, ipcp); + err =ipc_update_perm (set, ipcp);if (err) goto out_unlock0; - msq->q_qbytes = msg_qbytes; +if (set_qbytes) + msq->q_qbytes = msg_qbytes; msq->q_ctime =ktime_get_real_seconds ();/*
@@ -598,6 +601,7 @@ static long ksys_msgctl(int msqid, int cmd, struct msqid_ds __user *buf, int ver {struct ipc_namespace *ns;struct msqid64_ds msqid64; +struct ipc_set_ids set;int err;if (msqid <0 || cmd <0 )
@@ -628,10 +632,17 @@ static long ksys_msgctl(int msqid, int cmd, struct msqid_ds __user *buf, int vercase IPC_SET :if (copy_msqid_from_user (&msqid64, buf, version))return -EFAULT ; -return msgctl_down (ns, msqid, cmd, &msqid64.msg_perm, - msqid64.msg_qbytes); +ipc64_perm_to_set_ids (&msqid64.msg_perm, &set); +return msgctl_down (ns, msqid, cmd, &set, msqid64.msg_qbytes, true); +case IPC_SET_R : +if (ipc_perm_r_to_set_ids ((void __user *)buf, &set)) +return -EFAULT ; +return msgctl_down (ns, msqid,IPC_SET , &set,0 , false); +case IPC_STAT_R : +return ipc_stat_r (ns, &msg_ids (ns), msqid, + security_msg_queue_msgctl, (void __user *)buf);case IPC_RMID : -return msgctl_down (ns, msqid, cmd,NULL ,0 ); +return msgctl_down (ns, msqid, cmd,NULL ,0 , false);default :return -EINVAL ; }
@@ -734,6 +745,7 @@ static long compat_ksys_msgctl(int msqid, int cmd, void __user *uptr, int versiostruct ipc_namespace *ns;int err;struct msqid64_ds msqid64; +struct ipc_set_ids set; ns = current->nsproxy->ipc_ns;
@@ -763,9 +775,17 @@ static long compat_ksys_msgctl(int msqid, int cmd, void __user *uptr, int versiocase IPC_SET :if (copy_compat_msqid_from_user (&msqid64, uptr, version))return -EFAULT ; -return msgctl_down (ns, msqid, cmd, &msqid64.msg_perm, msqid64.msg_qbytes); +ipc64_perm_to_set_ids (&msqid64.msg_perm, &set); +return msgctl_down (ns, msqid, cmd, &set, msqid64.msg_qbytes, true); +case IPC_SET_R : +if (ipc_perm_r_to_set_ids (uptr, &set)) +return -EFAULT ; +return msgctl_down (ns, msqid,IPC_SET , &set,0 , false); +case IPC_STAT_R : +return ipc_stat_r (ns, &msg_ids (ns), msqid, + security_msg_queue_msgctl, uptr);case IPC_RMID : -return msgctl_down (ns, msqid, cmd,NULL ,0 ); +return msgctl_down (ns, msqid, cmd,NULL ,0 , false);default :return -EINVAL ; }
ipc/sem.c +23 -8
@@ -1599,7 +1599,7 @@ copy_semid_from_user(struct semid64_ds *out, void __user *buf, int version)* NOTE: no locks must be held, the rwsem is taken inside this function. */ static int semctl_down (struct ipc_namespace *ns,int semid, -int cmd,struct semid64_ds *semid64) +int cmd,const struct ipc_set_ids *set) {struct sem_array *sma;int err;
@@ -1608,8 +1608,7 @@ static int semctl_down(struct ipc_namespace *ns, int semid,down_write (&sem_ids (ns).rwsem);rcu_read_lock (); - ipcp =ipcctl_obtain_check (ns, &sem_ids (ns), semid, cmd, - &semid64->sem_perm,0 ); + ipcp =ipcctl_obtain_check (ns, &sem_ids (ns), semid, cmd, set,0 );if (IS_ERR (ipcp)) { err =PTR_ERR (ipcp); goto out_unlock1;
@@ -1629,7 +1628,7 @@ static int semctl_down(struct ipc_namespace *ns, int semid, goto out_up;case IPC_SET :sem_lock (sma,NULL ,-1 ); - err =ipc_update_perm (&semid64->sem_perm, ipcp); + err =ipc_update_perm (set, ipcp);if (err) goto out_unlock0; sma->sem_ctime =ktime_get_real_seconds ();
@@ -1653,6 +1652,7 @@ static long ksys_semctl(int semid, int semnum, int cmd, unsigned long arg, int vstruct ipc_namespace *ns;void __user *p = (void __user *)arg;struct semid64_ds semid64; +struct ipc_set_ids set;int err;if (semid <0 )
@@ -1694,9 +1694,16 @@ static long ksys_semctl(int semid, int semnum, int cmd, unsigned long arg, int vcase IPC_SET :if (copy_semid_from_user (&semid64, p, version))return -EFAULT ; - fallthrough; +ipc64_perm_to_set_ids (&semid64.sem_perm, &set); +return semctl_down (ns, semid, cmd, &set); +case IPC_SET_R : +if (ipc_perm_r_to_set_ids (p, &set)) +return -EFAULT ; +return semctl_down (ns, semid,IPC_SET , &set); +case IPC_STAT_R : +return ipc_stat_r (ns, &sem_ids (ns), semid, security_sem_semctl, p);case IPC_RMID : -return semctl_down (ns, semid, cmd, &semid64); +return semctl_down (ns, semid, cmd,NULL );default :return -EINVAL ; }
@@ -1776,6 +1783,7 @@ static long compat_ksys_semctl(int semid, int semnum, int cmd, int arg, int versvoid __user *p =compat_ptr (arg);struct ipc_namespace *ns;struct semid64_ds semid64; +struct ipc_set_ids set;int err; ns = current->nsproxy->ipc_ns;
@@ -1808,9 +1816,16 @@ static long compat_ksys_semctl(int semid, int semnum, int cmd, int arg, int verscase IPC_SET :if (copy_compat_semid_from_user (&semid64, p, version))return -EFAULT ; - fallthrough; +ipc64_perm_to_set_ids (&semid64.sem_perm, &set); +return semctl_down (ns, semid, cmd, &set); +case IPC_SET_R : +if (ipc_perm_r_to_set_ids (p, &set)) +return -EFAULT ; +return semctl_down (ns, semid,IPC_SET , &set); +case IPC_STAT_R : +return ipc_stat_r (ns, &sem_ids (ns), semid, security_sem_semctl, p);case IPC_RMID : -return semctl_down (ns, semid, cmd, &semid64); +return semctl_down (ns, semid, cmd,NULL );default :return -EINVAL ; }
ipc/shm.c +24 -8
@@ -993,7 +993,7 @@ static void shm_get_stat(struct ipc_namespace *ns, unsigned long *rss,* NOTE: no locks must be held, the rwsem is taken inside this function. */ static int shmctl_down (struct ipc_namespace *ns,int shmid,int cmd, -struct shmid64_ds *shmid64) +const struct ipc_set_ids *set) {struct kern_ipc_perm *ipcp;struct shmid_kernel *shp;
@@ -1002,8 +1002,7 @@ static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd,down_write (&shm_ids (ns).rwsem);rcu_read_lock (); - ipcp =ipcctl_obtain_check (ns, &shm_ids (ns), shmid, cmd, - &shmid64->shm_perm,0 ); + ipcp =ipcctl_obtain_check (ns, &shm_ids (ns), shmid, cmd, set,0 );if (IS_ERR (ipcp)) { err =PTR_ERR (ipcp); goto out_unlock1;
@@ -1023,7 +1022,7 @@ static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd, goto out_up;case IPC_SET :ipc_lock_object (&shp->shm_perm); - err =ipc_update_perm (&shmid64->shm_perm, ipcp); + err =ipc_update_perm (set, ipcp);if (err) goto out_unlock0; shp->shm_ctim =ktime_get_real_seconds ();
@@ -1246,6 +1245,7 @@ static long ksys_shmctl(int shmid, int cmd, struct shmid_ds __user *buf, int verint err;struct ipc_namespace *ns;struct shmid64_ds sem64; +struct ipc_set_ids set;if (cmd <0 || shmid <0 )return -EINVAL ;
@@ -1284,9 +1284,17 @@ static long ksys_shmctl(int shmid, int cmd, struct shmid_ds __user *buf, int vercase IPC_SET :if (copy_shmid_from_user (&sem64, buf, version))return -EFAULT ; - fallthrough; +ipc64_perm_to_set_ids (&sem64.shm_perm, &set); +return shmctl_down (ns, shmid, cmd, &set); +case IPC_SET_R : +if (ipc_perm_r_to_set_ids ((void __user *)buf, &set)) +return -EFAULT ; +return shmctl_down (ns, shmid,IPC_SET , &set); +case IPC_STAT_R : +return ipc_stat_r (ns, &shm_ids (ns), shmid, security_shm_shmctl, + (void __user *)buf);case IPC_RMID : -return shmctl_down (ns, shmid, cmd, &sem64); +return shmctl_down (ns, shmid, cmd,NULL );case SHM_LOCK :case SHM_UNLOCK :return shmctl_do_lock (ns, shmid, cmd);
@@ -1440,6 +1448,7 @@ static long compat_ksys_shmctl(int shmid, int cmd, void __user *uptr, int versio {struct ipc_namespace *ns;struct shmid64_ds sem64; +struct ipc_set_ids set;int err; ns = current->nsproxy->ipc_ns;
@@ -1479,9 +1488,16 @@ static long compat_ksys_shmctl(int shmid, int cmd, void __user *uptr, int versiocase IPC_SET :if (copy_compat_shmid_from_user (&sem64, uptr, version))return -EFAULT ; - fallthrough; +ipc64_perm_to_set_ids (&sem64.shm_perm, &set); +return shmctl_down (ns, shmid, cmd, &set); +case IPC_SET_R : +if (ipc_perm_r_to_set_ids (uptr, &set)) +return -EFAULT ; +return shmctl_down (ns, shmid,IPC_SET , &set); +case IPC_STAT_R : +return ipc_stat_r (ns, &shm_ids (ns), shmid, security_shm_shmctl, uptr);case IPC_RMID : -return shmctl_down (ns, shmid, cmd, &sem64); +return shmctl_down (ns, shmid, cmd,NULL );case SHM_LOCK :case SHM_UNLOCK :return shmctl_do_lock (ns, shmid, cmd);
ipc/util.c +101 -11
144 lines not on this page · raw message
ipc/util.h +21 -2
@@ -177,10 +177,29 @@ struct kern_ipc_perm *ipc_obtain_object_idr(struct ipc_ids *ids, int id);void kernel_to_ipc64_perm (struct kern_ipc_perm *in,struct ipc64_perm *out);void ipc64_perm_to_ipc_perm (struct ipc64_perm *in,struct ipc_perm *out); -int ipc_update_perm (struct ipc64_perm *in,struct kern_ipc_perm *out); + +/* +* The new owner, group and mode of IPC_SET/IPC_SET_R. @err is an error of +* their conversion, reported once the object has been found. +*/ +struct ipc_set_ids { +kuid_t uid; +kgid_t gid; +umode_t mode; +int err; +}; + +void ipc64_perm_to_set_ids (const struct ipc64_perm *in,struct ipc_set_ids *out); +int ipc_perm_r_to_set_ids (const struct ipc_perm_r __user *in, +struct ipc_set_ids *out); +int ipc_update_perm (const struct ipc_set_ids *in,struct kern_ipc_perm *out);struct kern_ipc_perm *ipcctl_obtain_check (struct ipc_namespace *ns,struct ipc_ids *ids,int id,int cmd, -struct ipc64_perm *perm,int extra_perm); +const struct ipc_set_ids *set, +int extra_perm); +int ipc_stat_r (struct ipc_namespace *ns,struct ipc_ids *ids,int id, +int (*security)(struct kern_ipc_perm *,int ), +struct ipc_perm_r __user *buf);static inline void ipc_update_pid (struct pid **pos,struct pid *pid) {
kernel/audit.h +2 -2
@@ -168,8 +168,8 @@ struct audit_context {umode_t mode;struct lsm_prop oprop;int has_perm; -uid_t perm_uid; -gid_t perm_gid; +kuid_t perm_uid; +kgid_t perm_gid;umode_t perm_mode;unsigned long qbytes; } ipc;
kernel/auditsc.c +4 -4
@@ -1395,10 +1395,10 @@ static void show_special(struct audit_context *context, int *call_panic)if (unlikely (!ab))return ;audit_log_format (ab, -"qbytes=%lx ouid=%u ogid=%u mode=%#ho" , +"qbytes=%lx ouid=%s ogid=%s mode=%#ho" , context->ipc.qbytes, - context->ipc.perm_uid, - context->ipc.perm_gid, +KUID_STR (context->ipc.perm_uid), +KGID_STR (context->ipc.perm_gid), context->ipc.perm_mode); }break ;
@@ -2585,7 +2585,7 @@ void __audit_ipc_obj(struct kern_ipc_perm *ipcp)* * Called only after audit_ipc_obj(). */ -void __audit_ipc_set_perm (unsigned long qbytes,uid_t uid,gid_t gid,umode_t mode) +void __audit_ipc_set_perm (unsigned long qbytes,kuid_t uid,kgid_t gid,umode_t mode) {struct audit_context *context =audit_context ();
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 30/41] ipc: add IPC_STAT_R and IPC_SET_R
Sashiko has reviewed this patch and found no issues.
Quoted 12 lines
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 bymsgctl(),semctl()andshmctl()that work on a structipc_perm_rwith key, mode, and uid, gid, cuid and cgid as__kernel_uid_r_t:-
IPC_STAT_Rreads it, with the permission checks ofIPC_STAT,
-IPC_SET_Rsets uid, gid and mode likeIPC_SETdoes (a message queue keeps its size).
Quoted 8 lines
The
IPC_SETpath now works on the kernel ids of a structipc_set_ids, which the classic command fills from itsipc64_perm. The audit record ofIPC_SEThas 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-5Signed-off-by Jan Koester <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=30
RFC PATCH v2 31/41 ext4: add the uid_r feature for UUID and GUID owners
In reply to Jan KoesterAdd 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.
--- 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
@@ -850,8 +850,29 @@ struct ext4_inode {__le32 i_crtime_extra;/* extra FileCreationtime (nsec << 2 | epoch) */ __le32 i_version_hi;/* high 32 bits for 64-bit version */ __le32 i_projid;/* Project ID */ +/* uid_r feature: a UUID or GUID owner and group, see EXT4_ID_R_* */ +__u8 i_uid_r_type;/* kind of i_uid_r, EXT4_ID_R_LEGACY: i_uid */ +__u8 i_gid_r_type;/* kind of i_gid_r, EXT4_ID_R_LEGACY: i_gid */ +__le16 i_id_r_reserved; +__u8 i_uid_r[16 ];/* UUID (RFC 9562 order) or GUID owner */ +__u8 i_gid_r[16 ];/* UUID (RFC 9562 order) or GUID group */ }; +/* +* Kinds of i_uid_r/i_gid_r. For a UUID or GUID the classic i_uid/i_gid +* fields hold 0xffffffff, which kernels without uid_r -- they may only +* mount read-only -- see as an id nobody has. +*/ +#define EXT4_ID_R_LEGACY 0 +#define EXT4_ID_R_UUID 1 +#define EXT4_ID_R_GUID 2 + +/* i_extra_isize of inodes without and with the uid_r fields */ +#define EXT4_EXTRA_ISIZE_BASE (offsetofend(struct ext4_inode, i_projid) - \ + EXT4_GOOD_OLD_INODE_SIZE) +#define EXT4_EXTRA_ISIZE_UID_R (sizeof(struct ext4_inode) - \ + EXT4_GOOD_OLD_INODE_SIZE) +#define EXT4_EPOCH_BITS 2#define EXT4_EPOCH_MASK ((1 << EXT4_EPOCH_BITS) - 1)#define EXT4_NSEC_MASK (~0UL << EXT4_EPOCH_BITS)
@@ -2214,6 +2235,7 @@ static inline struct mapping_metadata_bhs *ext4_i_metadata_bhs(#define EXT4_FEATURE_RO_COMPAT_VERITY 0x8000#define EXT4_FEATURE_RO_COMPAT_ORPHAN_PRESENT 0x10000/* Orphan file may be non-empty */ +#define EXT4_FEATURE_RO_COMPAT_UID_R 0x20000/* UUID and GUID owners */ #define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001#define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002
@@ -2313,6 +2335,7 @@ EXT4_FEATURE_RO_COMPAT_FUNCS(readonly, READONLY) EXT4_FEATURE_RO_COMPAT_FUNCS(project, PROJECT) EXT4_FEATURE_RO_COMPAT_FUNCS(verity, VERITY) EXT4_FEATURE_RO_COMPAT_FUNCS(orphan_present, ORPHAN_PRESENT) +EXT4_FEATURE_RO_COMPAT_FUNCS(uid_r, UID_R) EXT4_FEATURE_INCOMPAT_FUNCS(compression, COMPRESSION)EXT4_FEATURE_INCOMPAT_FUNCS (filetype,FILETYPE )
@@ -2373,7 +2396,8 @@ EXT4_FEATURE_INCOMPAT_FUNCS(casefold, CASEFOLD) EXT4_FEATURE_RO_COMPAT_QUOTA |\ EXT4_FEATURE_RO_COMPAT_PROJECT |\ EXT4_FEATURE_RO_COMPAT_VERITY |\ - EXT4_FEATURE_RO_COMPAT_ORPHAN_PRESENT) + EXT4_FEATURE_RO_COMPAT_ORPHAN_PRESENT |\ + EXT4_FEATURE_RO_COMPAT_UID_R)#define EXTN_FEATURE_FUNCS (ver) \ static inline bool ext4_has_unknown_ext##ver##_compat_features(struct super_block *sb) \
fs/ext4/inode.c +113 -2
153 lines not on this page · raw message
fs/ext4/super.c +14 -2
@@ -4613,9 +4613,17 @@ static int ext4_inode_info_init(struct super_block *sb, sb->s_time_min =EXT4_TIMESTAMP_MIN ; } +if (ext4_has_feature_uid_r (sb) && + sbi->s_inode_size <EXT4_GOOD_OLD_INODE_SIZE +EXT4_EXTRA_ISIZE_UID_R ) { +ext4_msg (sb,KERN_ERR ,"uid_r needs inodes of at least %zu bytes" , +EXT4_GOOD_OLD_INODE_SIZE +EXT4_EXTRA_ISIZE_UID_R ); +return -EINVAL ; + } +if (sbi->s_inode_size >EXT4_GOOD_OLD_INODE_SIZE ) { - sbi->s_want_extra_isize =sizeof (struct ext4_inode ) - -EXT4_GOOD_OLD_INODE_SIZE ; +/* room for the uid_r fields in new inodes only if needed */ + sbi->s_want_extra_isize =ext4_has_feature_uid_r (sb) ? +EXT4_EXTRA_ISIZE_UID_R :EXT4_EXTRA_ISIZE_BASE ;if (ext4_has_feature_extra_isize (sb)) {unsigned v, max = (sbi->s_inode_size -EXT4_GOOD_OLD_INODE_SIZE );
@@ -5437,6 +5445,10 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)/* HSM events are allowed by default. */ sb->s_iflags |=SB_I_ALLOW_HSM ; +/* uid_r: inodes can have UUID and GUID owners */ +if (ext4_has_feature_uid_r (sb) && !test_opt (sb,NO_UID32 )) + sb->s_iflags |=SB_I_UID_R ; + err =ext4_check_feature_compatibility (sb, es, silent);if (err) goto failed_mount;
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 31/41] ext4: add the uid_r feature for UUID and GUID owners
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider: - [High] ext4: unverified extra_isize expansion in ext4_make_room_for_id_r() - [Medium] ext4: UUID/GUID…
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] ext4: unverified extra_isize expansion in ext4_make_room_for_id_r()
- [Medium] ext4: UUID/GUID owners lost in ext4_xattr_inode_create() and ext4_ext_migrate()
- [Medium] ext4: debug_want_extra_isize can set s_want_extra_isize too small for uid_r
- [Medium] ext4: NO_UID32 clobbers 0xffffffff sentinel in ext4_fill_raw_inode()
- [Medium] ext4: race in ext4_make_room_for_id_r() with concurrent inode expansion
- [Medium] ext4: unsynchronized 20-byte i_uid and i_gid accesses in ext4_fill_raw_inode() --
commit f1bc4b92fd7bffda167e28ce9ca4459d00337211
Author: Jan Koester <[email protected]>
ext4: add the uid_r feature for UUID and GUID owners
This commit adds the read-only compatible uid_r feature to ext4, extending struct ext4_inode with i_uid_r_type, i_gid_r_type, i_uid_r, and i_gid_r to store 16-byte UUID and GUID owners and groups while storing 0xffffffff in the classic i_uid and i_gid fields. It also sets SB_I_UID_R on the superblock and expands existing inodes in ext4_setattr() when assigning a UUID or GUID owner or group.
Quoted 35 lines
fs/ext4/inode.c +27
-0@@ -4780,6 +4780,75 @@ static int ext4_inode_blocks_set(struct ext4_inode *raw_inode,return 0 ; } +/* +* uid_r: a UUID or GUID owner and group live in i_uid_r and i_gid_r of +* inodes with room for them; i_uid and i_gid then hold 0xffffffff. +*/ +static int ext4_inode_set_id_r (struct inode *inode,struct ext4_inode *raw_inode) +{ +struct ext4_inode_info *ei =EXT4_I (inode); +bool fits =EXT4_INODE_SIZE (inode->i_sb) >EXT4_GOOD_OLD_INODE_SIZE && +EXT4_FITS_IN_INODE (raw_inode, ei, i_gid_r); +bool legacy =uid_is_legacy (inode->i_uid) &&gid_is_legacy (inode->i_gid); + +if (!legacy && (!ext4_has_feature_uid_r (inode->i_sb) || !fits)) +return -EOVERFLOW ; +if (!fits || !ext4_has_feature_uid_r (inode->i_sb)) +return 0 ; + + raw_inode->i_id_r_reserved =0 ; +if (uid_is_legacy (inode->i_uid)) { + raw_inode->i_uid_r_type =EXT4_ID_R_LEGACY ; +memset (raw_inode->i_uid_r,0 ,sizeof (raw_inode->i_uid_r)); + }else { +BUILD_BUG_ON (KID_UUID !=EXT4_ID_R_UUID || +KID_GUID !=EXT4_ID_R_GUID ); + raw_inode->i_uid_r_type = inode->i_uid.type; +memcpy (raw_inode->i_uid_r, inode->i_uid.uuid.b, +sizeof (raw_inode->i_uid_r)); + }
fs/ext4/inode.c static int ext4_inode_blocks_set(struct ext4_inode *raw_inode, · line 4819
Quoted 10 lines
fs/ext4/inode.c +10
-0+if (gid_is_legacy (inode->i_gid)) { + raw_inode->i_gid_r_type =EXT4_ID_R_LEGACY ; +memset (raw_inode->i_gid_r,0 ,sizeof (raw_inode->i_gid_r)); + }else { + raw_inode->i_gid_r_type = inode->i_gid.type; +memcpy (raw_inode->i_gid_r, inode->i_gid.uuid.b, +sizeof (raw_inode->i_gid_r)); + } +return 0 ; +}
[Severity: Medium]
With UUID and GUID support, kuid_t and kgid_t are 20-byte structures, so reads and writes of inode->i_uid and inode->i_gid are multi-word and not atomic.
In fs/ext4/inode.c, ext4_setattr() updates inode->i_uid and inode->i_gid under inode->i_rwsem without holding EXT4_I(inode)->i_raw_lock:
fs/ext4/inode.c:ext4_setattr() {
...
i_uid_update(idmap, attr, inode);
i_gid_update(idmap, attr, inode);
error = ext4_mark_inode_dirty(handle, inode);
}Concurrently, paths that dirty the inode without holding inode->i_rwsem (such as touch_atime() -> ext4_dirty_inode(), or unwritten extent conversion in ext4_end_io_rsv_work() -> ext4_mark_inode_dirty()) call ext4_do_update_inode() -> ext4_fill_raw_inode() -> ext4_inode_set_id_r() under ei->i_raw_lock, and __ext4_get_inode_loc() also calls ext4_fill_raw_inode() under lock_buffer(bh).
Because ext4_fill_raw_inode() first reads inode->i_uid and inode->i_gid via i_uid_read() and i_gid_read(), and ext4_inode_set_id_r() then re-reads inode->i_uid and inode->i_gid multiple times, can a concurrent chown race with ext4_fill_raw_inode() and write a torn 16-byte UUID/GUID or mismatched classic i_uid/i_gid and i_uid_r/i_gid_r fields (with a valid metadata checksum computed over that inconsistent state) into raw_inode?
[ ... ]
fs/ext4/inode.c static int ext4_fill_raw_inode(struct inode *inode, struct ext4_inode *raw_inode · line 4867
Quoted 8 lines
fs/ext4/inode.c +2
-0@@ -4792,8 +4861,10 @@ static int ext4_fill_raw_inode(struct inode *inode, struct ext4_inode *raw_inode err =ext4_inode_blocks_set (raw_inode, ei); raw_inode->i_mode =cpu_to_le16 (inode->i_mode); +/* a UUID or GUID owner: 0xffffffff here, the id in i_uid_r */ i_uid =i_uid_read (inode); i_gid =i_gid_read (inode); + err = err ?:ext4_inode_set_id_r (inode, raw_inode);
[Severity: Medium]
When an inode has a UUID or GUID owner or group, i_uid_read(inode) and i_gid_read(inode) return (uid_t)-1 (0xffffffff).
Both ext4_xattr_inode_create() in fs/ext4/xattr.c and ext4_ext_migrate() in fs/ext4/migrate.c copy the parent inode's owner into a uid_t owner[2] array using i_uid_read() and i_gid_read() and pass that array to ext4_new_inode():
fs/ext4/xattr.c:ext4_xattr_inode_create() {
struct inode *ea_inode = NULL;
uid_t owner[2] = { i_uid_read(inode), i_gid_read(inode) };
...
ea_inode = ext4_new_inode(handle, inode->i_sb->s_root->d_inode,
S_IFREG | 0600, NULL, inode->i_ino + 1, owner,
EXT4_EA_INODE_FL);
}fs/ext4/migrate.c:ext4_ext_migrate() {
...
owner[0] = i_uid_read(inode);
owner[1] = i_gid_read(inode);
tmp_inode = ext4_new_inode(handle, d_inode(inode->i_sb->s_root),
S_IFREG, NULL, goal, owner, 0);
}In fs/ext4/ialloc.c, __ext4_new_inode() then passes those 32-bit values to i_uid_write() and i_gid_write() before calling dquot_initialize():
fs/ext4/ialloc.c:__ext4_new_inode() {
if (owner) {
inode->i_mode = mode;
i_uid_write(inode, owner[0]);
i_gid_write(inode, owner[1]);
}
...
err = dquot_initialize(inode);
}Because make_kuid(&init_user_ns, (uid_t)-1) produces INVALID_UID (with KID_LEGACY and value -1) rather than preserving the UUID or GUID, qid_has_mapping() in dqget() returns false and causes dquot_initialize() to fail with -EINVAL when quotas are enabled, or writes out the helper inode with EXT4_ID_R_LEGACY and i_uid 0xffffffff when quotas are disabled.
Should ext4_xattr_inode_create() and ext4_ext_migrate() preserve the full kuid_t and kgid_t owner and group when creating helper inodes for a UUID or GUID owned file?
[ ... ]
Quoted 24 lines
fs/ext4/inode.c +20
-0@@ -6006,6 +6079,40 @@ static void ext4_wait_for_tail_page_commit(struct inode *inode)* * Called with inode->i_rwsem down. */ +/* +* An inode from before uid_r, or with in-inode xattrs in the way, may +* lack room for i_uid_r and i_gid_r: make it, before it gets a UUID or +* GUID owner or group. +*/ +static int ext4_make_room_for_id_r (struct mnt_idmap *idmap, +struct inode *inode,struct iattr *attr) +{ +struct ext4_iloc iloc; +bool legacy = true; +int err; + +if (attr->ia_valid &ATTR_UID ) + legacy =uid_is_legacy (from_vfsuid (idmap,i_user_ns (inode), + attr->ia_vfsuid)); +if (attr->ia_valid &ATTR_GID ) + legacy &=gid_is_legacy (from_vfsgid (idmap,i_user_ns (inode), + attr->ia_vfsgid)); +if (legacy) +return 0 ;
fs/ext4/inode.c static void ext4_wait_for_tail_page_commit(struct inode *inode) · line 6111
Quoted 10 lines
fs/ext4/inode.c +10
-0+if (!ext4_has_feature_uid_r (inode->i_sb)) +return -EOVERFLOW ; + + err =ext4_get_inode_loc (inode, &iloc); +if (err) +return err; +if (EXT4_FITS_IN_INODE (ext4_raw_inode (&iloc),EXT4_I (inode), i_gid_r)) { +brelse (iloc.bh); +return 0 ; + }
[Severity: Medium]
In ext4_make_room_for_id_r(), EXT4_FITS_IN_INODE() is checked without holding EXT4_I(inode)->xattr_sem before calling ext4_expand_extra_isize() with EXT4_EXTRA_ISIZE_UID_R.
Concurrently, paths that dirty the inode without holding inode->i_rwsem (such as ext4_dirty_inode(), ext4_page_mkwrite(), or ext4_end_io_rsv_work()) can call __ext4_mark_inode_dirty() -> ext4_try_to_expand_extra_isize(), which acquires xattr_sem via ext4_write_trylock_xattr() and sets EXT4_STATE_NO_EXPAND while xattr_sem is held.
If ext4_expand_extra_isize() runs during that window, it checks EXT4_STATE_NO_EXPAND before taking xattr_sem:
fs/ext4/inode.c:ext4_expand_extra_isize() {
if (ext4_test_inode_state(inode, EXT4_STATE_NO_EXPAND)) {
brelse(iloc->bh);
return -EOVERFLOW;
}
...
}Furthermore, if ext4_expand_extra_isize() passes that check and blocks on ext4_write_lock_xattr() while ext4_try_to_expand_extra_isize() expands ei->i_extra_isize to sbi->s_want_extra_isize (when sbi->s_want_extra_isize exceeds EXT4_EXTRA_ISIZE_UID_R), __ext4_expand_extra_isize() will then see new_extra_isize < ei->i_extra_isize and return -EINVAL:
fs/ext4/inode.c:__ext4_expand_extra_isize() {
if ((new_extra_isize < ei->i_extra_isize) ||
(new_extra_isize < 4) ||
(new_extra_isize > inode_size - EXT4_GOOD_OLD_INODE_SIZE))
return -EINVAL; /* Should never happen */
}
Could this race cause ext4_make_room_for_id_r() to spuriously fail a chown operation with -EOVERFLOW even when sufficient extra inode space is available?
fs/ext4/inode.c static void ext4_wait_for_tail_page_commit(struct inode *inode) · line 6114
Quoted 3 lines
fs/ext4/inode.c +3
-0+ err =ext4_expand_extra_isize (inode,EXT4_EXTRA_ISIZE_UID_R , &iloc); +return err ? -EOVERFLOW :0 ; +}
[Severity: High]
What happens here if ext4_expand_extra_isize() returns 0 without expanding i_extra_isize all the way to EXT4_EXTRA_ISIZE_UID_R?
When an inode has in-inode extended attributes (EXT4_STATE_XATTR) that cannot be moved out to free 36 bytes (for example, inline data or an external xattr block without enough free space), ext4_expand_extra_isize() -> __ext4_expand_extra_isize() -> ext4_expand_extra_isize_ea() falls back to s_min_extra_isize (typically 32 bytes) on -ENOSPC and jumps to retry:
fs/ext4/xattr.c:ext4_expand_extra_isize_ea() {
retry:
isize_diff = new_extra_isize - EXT4_I(inode)->i_extra_isize;
if (EXT4_I(inode)->i_extra_isize >= new_extra_isize)
return 0;
...
if (error) {
if (error == -ENOSPC && !tried_min_extra_isize &&
s_min_extra_isize) {
tried_min_extra_isize++;
new_extra_isize = s_min_extra_isize;
error = 0;
goto retry;
}
goto cleanup;
}
}When i_extra_isize is already at least s_min_extra_isize (such as 32 bytes on an inode created before uid_r), ext4_expand_extra_isize_ea() returns 0 at the retry label while i_extra_isize is still smaller than EXT4_EXTRA_ISIZE_UID_R.
ext4_make_room_for_id_r() then returns 0, so ext4_setattr() updates inode->i_uid and inode->i_gid in memory to the UUID/GUID and calls ext4_mark_inode_dirty() -> ext4_do_update_inode() -> ext4_fill_raw_inode() -> ext4_inode_set_id_r(), which sees !legacy && !fits, returns -EOVERFLOW, and triggers a false-positive filesystem corruption error:
fs/ext4/inode.c:ext4_do_update_inode() {
err = ext4_fill_raw_inode(inode, raw_inode);
spin_unlock(&ei->i_raw_lock);
if (err) {
EXT4_ERROR_INODE(inode, "corrupted inode contents");
goto out_brelse;
}
}Should ext4_make_room_for_id_r() verify that i_gid_r actually fits in the inode after ext4_expand_extra_isize() returns?
[ ... ]
Quoted 11 lines
fs/ext4/super.c +3
-0@@ -4613,9 +4613,17 @@ static int ext4_inode_info_init(struct super_block *sb, sb->s_time_min =EXT4_TIMESTAMP_MIN ; } +if (ext4_has_feature_uid_r (sb) && + sbi->s_inode_size <EXT4_GOOD_OLD_INODE_SIZE +EXT4_EXTRA_ISIZE_UID_R ) { + ext4_msg(sb, KERN_ERR, "uid_r needs inodes of at least %zu bytes",
fs/ext4/super.c static int ext4_inode_info_init(struct super_block *sb, · line 4626
Quoted 10 lines
fs/ext4/super.c +7
-2+ EXT4_GOOD_OLD_INODE_SIZE + EXT4_EXTRA_ISIZE_UID_R); +return -EINVAL ; + } +if (sbi->s_inode_size >EXT4_GOOD_OLD_INODE_SIZE ) { - sbi->s_want_extra_isize =sizeof (struct ext4_inode ) - -EXT4_GOOD_OLD_INODE_SIZE ; +/* room for the uid_r fields in new inodes only if needed */ + sbi->s_want_extra_isize =ext4_has_feature_uid_r (sb) ? +EXT4_EXTRA_ISIZE_UID_R :EXT4_EXTRA_ISIZE_BASE ;
[Severity: Medium]
In __ext4_fill_super(), ext4_inode_info_init() initializes sbi->s_want_extra_isize to EXT4_EXTRA_ISIZE_UID_R, but parse_apply_sb_mount_options(), ext4_check_opt_consistency(), and ext4_apply_options() run right afterwards (and on remount in __ext4_remount()) and overwrite sbi->s_want_extra_isize when the debug_want_extra_isize mount option is specified.
Because ext4_check_opt_consistency() only checks the upper bound of ctx->s_want_extra_isize:
fs/ext4/super.c:ext4_check_opt_consistency() {
if (ctx->s_want_extra_isize >
(sbi->s_inode_size - EXT4_GOOD_OLD_INODE_SIZE)) {
ext4_msg(NULL, KERN_ERR,
"Invalid want_extra_isize %d",
ctx->s_want_extra_isize);
return -EINVAL;
}
}mounting or remounting a uid_r filesystem with debug_want_extra_isize smaller than EXT4_EXTRA_ISIZE_UID_R causes __ext4_new_inode() to initialize ei->i_extra_isize to that smaller value.
If a new inode is then created with a UUID or GUID owner or group, won't ext4_mark_inode_dirty() -> ext4_do_update_inode() -> ext4_fill_raw_inode() -> ext4_inode_set_id_r() return -EOVERFLOW and trigger EXT4_ERROR_INODE(inode, "corrupted inode contents")?
fs/ext4/super.c static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) · line 5450
Quoted 10 lines
fs/ext4/super.c +3
-0if (ext4_has_feature_extra_isize (sb)) {unsigned v, max = (sbi->s_inode_size -EXT4_GOOD_OLD_INODE_SIZE );@@ -5437,6 +5445,10 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)/* HSM events are allowed by default. */ sb->s_iflags |=SB_I_ALLOW_HSM ; +/* uid_r: inodes can have UUID and GUID owners */ +if (ext4_has_feature_uid_r (sb) && !test_opt (sb,NO_UID32 )) + sb->s_iflags |=SB_I_UID_R ;
[Severity: Medium]
While __ext4_fill_super() avoids setting SB_I_UID_R when NO_UID32 is enabled at mount time, __ext4_remount() allows enabling NO_UID32 on remount without clearing SB_I_UID_R, and ext4_inode_get_id_r() loads UUID and GUID owners into inode->i_uid and inode->i_gid regardless of NO_UID32.
When an inode with a UUID or GUID owner or group is dirtied and written out in ext4_fill_raw_inode() while NO_UID32 is set, i_uid_read(inode) and i_gid_read(inode) return 0xffffffff, and the NO_UID32 branch converts them with fs_high2lowuid() and fs_high2lowgid():
fs/ext4/inode.c:ext4_fill_raw_inode() {
if (!(test_opt(inode->i_sb, NO_UID32))) {
...
} else {
raw_inode->i_uid_low = cpu_to_le16(fs_high2lowuid(i_uid));
raw_inode->i_gid_low = cpu_to_le16(fs_high2lowgid(i_gid));
raw_inode->i_uid_high = 0;
raw_inode->i_gid_high = 0;
}
}Doesn't this overwrite the on-disk 0xffffffff sentinel in i_uid and i_gid with 0x0000fffe (65534) while leaving i_uid_r_type and i_gid_r_type set to EXT4_ID_R_UUID or EXT4_ID_R_GUID?
Quoted 4 lines
fs/ext4/super.c +1
-0+ err =ext4_check_feature_compatibility (sb, es, silent);if (err) goto failed_mount;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=31
RFC PATCH v2 32/41 ext4: let uid_r be turned on while the filesystem is mounted
In reply to Jan KoesterSB_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.
--- 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
@@ -3322,6 +3322,7 @@ extern struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb, sector_t block);extern struct buffer_head *ext4_sb_bread_nofail (struct super_block *sb,sector_t block); +void ext4_enable_uid_r (struct super_block *sb);void ext4_read_bh_nowait (struct buffer_head *bh,blk_opf_t op_flags,bio_end_io_t end_io,bool simu_fail); int ext4_read_bh(struct buffer_head *bh, blk_opf_t op_flags,
fs/ext4/ioctl.c +29 -1
@@ -1269,7 +1269,8 @@ static int ext4_ioctl_setuuid(struct file *filp, EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \ EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | \ EXT4_FEATURE_RO_COMPAT_PROJECT | \ - EXT4_FEATURE_RO_COMPAT_VERITY) + EXT4_FEATURE_RO_COMPAT_VERITY | \ + EXT4_FEATURE_RO_COMPAT_UID_R)#define EXT4_TUNE_CLEAR_COMPAT_SUPP (0)#define EXT4_TUNE_CLEAR_INCOMPAT_SUPP (0)
@@ -1382,6 +1383,13 @@ static void ext4_sb_setparams(struct ext4_sb_info *sbi,if (params->set_feature_incompat_mask &EXT4_FEATURE_INCOMPAT_CSUM_SEED ) es->s_checksum_seed =cpu_to_le32 (sbi->s_csum_seed); +/* as tune2fs does: room for the uid_r fields in new inodes */ +if ((params->set_feature_ro_compat_mask & +EXT4_FEATURE_RO_COMPAT_UID_R ) && +ext4_has_feature_extra_isize (sbi->s_sb) && +le16_to_cpu (es->s_want_extra_isize) <EXT4_EXTRA_ISIZE_UID_R ) + es->s_want_extra_isize = +cpu_to_le16 (EXT4_EXTRA_ISIZE_UID_R ); }if (params->set_flags &EXT4_TUNE_FL_FORCE_FSCK ) es->s_state |=cpu_to_le16 (EXT4_ERROR_FS );
@@ -1395,6 +1403,7 @@ static int ext4_ioctl_set_tune_sb(struct file *filp,struct ext4_sb_info *sbi =EXT4_SB (sb);struct ext4_super_block *es = sbi->s_es;int enabling_casefold =0 ; +bool enabling_uid_r = false;int ret;if (!capable (CAP_SYS_ADMIN ))
@@ -1461,6 +1470,18 @@ static int ext4_ioctl_set_tune_sb(struct file *filp, ~EXT4_TUNE_CLEAR_RO_COMPAT_SUPP))return -EOPNOTSUPP ; +/* +* uid_r may already be on disk but not in use yet, when it +* was set while the filesystem was mounted: take that up too. +*/ +if (params.set_feature_ro_compat_mask & +EXT4_FEATURE_RO_COMPAT_UID_R ) { +if (sbi->s_inode_size <EXT4_GOOD_OLD_INODE_SIZE + +EXT4_EXTRA_ISIZE_UID_R ) +return -EINVAL ; + enabling_uid_r = true; + } +/* * Filter out the features that are already set from * the set_mask.
@@ -1532,6 +1553,13 @@ static int ext4_ioctl_set_tune_sb(struct file *filp,if (params.set_flags &EXT4_TUNE_FL_DEF_HASH_ALG ) sbi->s_def_hash_version = params.def_hash_alg; +/* not under mnt_want_write_file(), freeze_super() would wait for us */ +if (!ret && enabling_uid_r) { +down_write (&sb->s_umount); +ext4_enable_uid_r (sb); +up_write (&sb->s_umount); + } +return ret; }
fs/ext4/super.c +29 -0
@@ -6580,6 +6580,32 @@ static int ext4_unfreeze(struct super_block *sb)return 0 ; } +/* +* Let the filesystem take UUID and GUID owners when the uid_r feature was +* turned on after the mount, by a remount or EXT4_IOC_SET_TUNE_SB_PARAM. +* It is never turned off again, as cached inodes may have such owners by +* now. Called with s_umount held for writing. +*/ +void ext4_enable_uid_r (struct super_block *sb) +{ +struct ext4_sb_info *sbi =EXT4_SB (sb); + +if (!ext4_has_feature_uid_r (sb) ||test_opt (sb,NO_UID32 ) || + (sb->s_iflags &SB_I_UID_R )) +return ; +if (sbi->s_inode_size < +EXT4_GOOD_OLD_INODE_SIZE +EXT4_EXTRA_ISIZE_UID_R ) { +ext4_msg (sb,KERN_WARNING , +"uid_r needs inodes of at least %zu bytes, not enabled" , +EXT4_GOOD_OLD_INODE_SIZE +EXT4_EXTRA_ISIZE_UID_R ); +return ; + } +if (sbi->s_want_extra_isize <EXT4_EXTRA_ISIZE_UID_R ) +WRITE_ONCE (sbi->s_want_extra_isize,EXT4_EXTRA_ISIZE_UID_R ); + sb->s_iflags |=SB_I_UID_R ; +ext4_msg (sb,KERN_INFO ,"uid_r enabled" ); +} +/* * Structure to save mount options for ext4_remount's benefit */
@@ -6861,6 +6887,9 @@ static int __ext4_remount(struct fs_context *fc, struct super_block *sb)if (!test_opt (sb,BLOCK_VALIDITY ) && sbi->s_system_blks)ext4_release_system_zone (sb); +/* tune2fs may have turned on uid_r since the mount */ +ext4_enable_uid_r (sb); +/* * Reinitialize lazy itable initialization thread based on * current settings
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 32/41] ext4: let uid_r be turned on while the filesystem is mounted
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] ext4: ext4_ioctl_set_tune_sb() mishandles uid_r when already set on disk --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] ext4: ext4_ioctl_set_tune_sb() mishandles uid_r when already set on disk --
commit 18ffac15f27841cea0033ca0f9c30bacf945f9ce
Author: Jan Koester <[email protected]>
ext4: let uid_r be turned on while the filesystem is mounted
This commit allows the uid_r feature (SB_I_UID_R) to be enabled on a mounted ext4 filesystem during remount or via the EXT4_IOC_SET_TUNE_SB_PARAM ioctl. When enabled via the ioctl, it also raises s_want_extra_isize to reserve space for the uid_r fields in new inodes.
Quoted 4 lines
fs/ext4/ioctl.c +0
-0
[ ... ]
Quoted 14 lines
fs/ext4/ioctl.c +7
-0@@ -1382,6 +1383,13 @@ static void ext4_sb_setparams(struct ext4_sb_info *sbi,if (params->set_feature_incompat_mask &EXT4_FEATURE_INCOMPAT_CSUM_SEED ) es->s_checksum_seed =cpu_to_le32 (sbi->s_csum_seed); +/* as tune2fs does: room for the uid_r fields in new inodes */ +if ((params->set_feature_ro_compat_mask & +EXT4_FEATURE_RO_COMPAT_UID_R ) && +ext4_has_feature_extra_isize (sbi->s_sb) && +le16_to_cpu (es->s_want_extra_isize) <EXT4_EXTRA_ISIZE_UID_R ) + es->s_want_extra_isize = +cpu_to_le16 (EXT4_EXTRA_ISIZE_UID_R ); }if (params->set_flags &EXT4_TUNE_FL_FORCE_FSCK ) es->s_state |=cpu_to_le16 (EXT4_ERROR_FS );
[ ... ]
Quoted 9 lines
fs/ext4/ioctl.c +5
-0@@ -1461,6 +1470,18 @@ static int ext4_ioctl_set_tune_sb(struct file *filp, ~EXT4_TUNE_CLEAR_RO_COMPAT_SUPP))return -EOPNOTSUPP ; +/* +* uid_r may already be on disk but not in use yet, when it +* was set while the filesystem was mounted: take that up too. +*/ + if (params.set_feature_ro_compat_mask &
fs/ext4/ioctl.c static int ext4_ioctl_set_tune_sb(struct file *filp, · line 1487
Quoted 10 lines
fs/ext4/ioctl.c +7
-0+ EXT4_FEATURE_RO_COMPAT_UID_R) { +if (sbi->s_inode_size <EXT4_GOOD_OLD_INODE_SIZE + +EXT4_EXTRA_ISIZE_UID_R ) +return -EINVAL ; + enabling_uid_r = true; + } +/* * Filter out the features that are already set from * the set_mask.
[Severity: Medium]
In fs/ext4/ioctl.c, ext4_ioctl_set_tune_sb() intends to activate uid_r even when EXT4_FEATURE_RO_COMPAT_UID_R is already set in es->s_feature_ro_compat on disk.
However, when the caller passes EXT4_TUNE_FL_FEATURES rather than EXT4_TUNE_FL_EDIT_FEATURES, ext4_ioctl_set_tune_sb() derives params.set_feature_ro_compat_mask earlier by masking out features already present in es->s_feature_ro_compat:
if (params.set_flags & EXT4_TUNE_FL_FEATURES) {
...
params.set_feature_ro_compat_mask =
params.feature_ro_compat &
~le32_to_cpu(es->s_feature_ro_compat);If EXT4_FEATURE_RO_COMPAT_UID_R is already set in es->s_feature_ro_compat, that bit is cleared from params.set_feature_ro_compat_mask before reaching the check above, so enabling_uid_r remains false, the sbi->s_inode_size check is skipped, and ext4_enable_uid_r(sb) is never called.
Additionally, even when EXT4_TUNE_FL_EDIT_FEATURES is used directly, ext4_ioctl_set_tune_sb() clears already-set features from params.set_feature_ro_compat_mask immediately after setting enabling_uid_r:
params.set_feature_ro_compat_mask &= ~le32_to_cpu(es->s_feature_ro_compat);
When ext4_update_superblocks_fn() then invokes ext4_sb_setparams(), params->set_feature_ro_compat_mask no longer has EXT4_FEATURE_RO_COMPAT_UID_R set, so es->s_want_extra_isize is not raised to EXT4_EXTRA_ISIZE_UID_R on disk in the superblocks.
Does this prevent EXT4_IOC_SET_TUNE_SB_PARAM from enabling uid_r via EXT4_TUNE_FL_FEATURES and from updating es->s_want_extra_isize on disk when EXT4_FEATURE_RO_COMPAT_UID_R is already set in es->s_feature_ro_compat?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=32
RFC PATCH v2 33/41 posix_acl: support UUID and GUID entries
In reply to Jan KoesterThe 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.
--- 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
@@ -19,6 +19,8 @@#include <linux/cred.h> #include <linux/posix_acl.h> #include <linux/posix_acl_xattr.h> +#include <linux/uidgid_r.h> +#include <linux/unaligned.h> #include <linux/xattr.h> #include <linux/export.h> #include <linux/user_namespace.h>
@@ -741,16 +743,62 @@ static int posix_acl_fix_xattr_common(const void *value, size_t size)return -EINVAL ;if (size <sizeof (struct posix_acl_xattr_header ))return -EINVAL ; -if (header->a_version !=cpu_to_le32 (POSIX_ACL_XATTR_VERSION )) +if (header->a_version ==cpu_to_le32 (POSIX_ACL_XATTR_VERSION_R )) + count =posix_acl_xattr_count_r (size); +else if (header->a_version ==cpu_to_le32 (POSIX_ACL_XATTR_VERSION )) + count =posix_acl_xattr_count (size); +else return -EOPNOTSUPP ; - count =posix_acl_xattr_count (size);if (count <0 )return -EINVAL ;return count; } +/* The entries of a version 3 ACL xattr into @acl; -EINVAL if malformed */ +static int posix_acl_from_xattr_r (struct user_namespace *userns, +const struct posix_acl_xattr_entry_r *entry, +struct posix_acl *acl) +{ +struct __kernel_uid_r id; + +for (int n =0 ; n < acl->a_count; n++, entry++) { +struct posix_acl_entry *acl_e = &acl->a_entries[n]; + + acl_e->e_tag =le16_to_cpu (entry->e_tag); + acl_e->e_perm =le16_to_cpu (entry->e_perm); + +memset (&id,0 ,sizeof (id)); + id.type =le32_to_cpu (entry->e_type); +if (id.type ==UID_R_LEGACY ) + id.legacy =get_unaligned_le32 (entry->e_id); +else +memcpy (id.uuid, entry->e_id,sizeof (id.uuid)); + +switch (acl_e->e_tag) { +case ACL_USER_OBJ : +case ACL_GROUP_OBJ : +case ACL_MASK : +case ACL_OTHER : +break ; +case ACL_USER : + acl_e->e_uid =make_kuid_r (userns, &id); +if (!uid_valid (acl_e->e_uid)) +return -EINVAL ; +break ; +case ACL_GROUP : + acl_e->e_gid =make_kgid_r (userns, &id); +if (!gid_valid (acl_e->e_gid)) +return -EINVAL ; +break ; +default : +return -EINVAL ; + } + } +return 0 ; +} +/** * posix_acl_from_xattr - convert POSIX ACLs from backing store to VFS format * @userns: the filesystem's idmapping
@@ -795,6 +843,13 @@ struct posix_acl *posix_acl_from_xattr(struct user_namespace *userns,return ERR_PTR (-ENOMEM ); acl_e = acl->a_entries; +if (header->a_version ==cpu_to_le32 (POSIX_ACL_XATTR_VERSION_R )) { +if (posix_acl_from_xattr_r (userns, (const void *)(header +1 ), + acl)) + goto fail; +return acl; + } +for (end = entry + count; entry != end; acl_e++, entry++) { acl_e->e_tag =le16_to_cpu (entry->e_tag); acl_e->e_perm =le16_to_cpu (entry->e_perm);
@@ -874,6 +929,61 @@ posix_acl_to_xattr(struct user_namespace *user_ns, const struct posix_acl *acl, }EXPORT_SYMBOL (posix_acl_to_xattr); +/* Like vfs_posix_acl_to_xattr(), in version 3 */ +static ssize_t vfs_posix_acl_to_xattr_r (struct mnt_idmap *idmap, +struct inode *inode, +const struct posix_acl *acl, +void *buffer,size_t size) +{ +struct posix_acl_xattr_header *ext_acl = buffer; +struct posix_acl_xattr_entry_r *ext_entry; +struct user_namespace *fs_userns =i_user_ns (inode); +struct user_namespace *caller_userns =current_user_ns (); +struct __kernel_uid_r id; +ssize_t real_size; +bool mapped; + + real_size =posix_acl_xattr_size_r (acl->a_count); +if (!buffer) +return real_size; +if (real_size > size) +return -ERANGE ; + + ext_entry = (void *)(ext_acl +1 ); + ext_acl->a_version =cpu_to_le32 (POSIX_ACL_XATTR_VERSION_R ); + +for (int n =0 ; n < acl->a_count; n++, ext_entry++) { +const struct posix_acl_entry *acl_e = &acl->a_entries[n]; + + ext_entry->e_tag =cpu_to_le16 (acl_e->e_tag); + ext_entry->e_perm =cpu_to_le16 (acl_e->e_perm); +memset (&id,0 ,sizeof (id)); + mapped = true; +switch (acl_e->e_tag) { +case ACL_USER : + mapped =from_kuid_r (caller_userns,vfsuid_into_kuid ( +make_vfsuid (idmap, fs_userns, acl_e->e_uid)), &id); +break ; +case ACL_GROUP : + mapped =from_kgid_r (caller_userns,vfsgid_into_kgid ( +make_vfsgid (idmap, fs_userns, acl_e->e_gid)), &id); +break ; + } +/* no mapping: the classic -1, as in version 2 */ +if (!mapped) { + id.type =UID_R_LEGACY ; + id.legacy =ACL_UNDEFINED_ID ; + } + ext_entry->e_type =cpu_to_le32 (id.type); +memset (ext_entry->e_id,0 ,sizeof (ext_entry->e_id)); +if (id.type ==UID_R_LEGACY ) +put_unaligned_le32 (id.legacy, ext_entry->e_id); +else if (id.type !=UID_R_NONE ) +memcpy (ext_entry->e_id, id.uuid,sizeof (ext_entry->e_id)); + } +return real_size; +} +/** * vfs_posix_acl_to_xattr - convert from kernel to userspace representation * @idmap: idmap of the mount
@@ -902,6 +1012,11 @@ static ssize_t vfs_posix_acl_to_xattr(struct mnt_idmap *idmap,vfsuid_t vfsuid;vfsgid_t vfsgid; +/* UUIDs and GUIDs the caller can see need version 3 */ +if (posix_acl_has_id_r (acl) &¤t_user_ns () == &init_user_ns) +return vfs_posix_acl_to_xattr_r (idmap, inode, acl, buffer, + size); + real_size =posix_acl_xattr_size (acl->a_count);if (!buffer)return real_size;
@@ -956,6 +1071,10 @@ set_posix_acl(struct mnt_idmap *idmap, struct dentry *dentry,int ret =posix_acl_valid (inode->i_sb->s_user_ns, acl);if (ret)return ret; +/* UUID and GUID entries only where the filesystem stores them */ +if (posix_acl_has_id_r (acl) && + !(inode->i_sb->s_iflags &SB_I_UID_R )) +return -EOVERFLOW ; }return inode->i_op->set_acl (idmap, dentry, acl, type); }
include/linux/posix_acl_xattr.h +31 -0
@@ -32,6 +32,37 @@ posix_acl_xattr_count(size_t size)return size /sizeof (struct posix_acl_xattr_entry ); } +static inline size_t +posix_acl_xattr_size_r (int count) +{ +return (sizeof (struct posix_acl_xattr_header ) + + (count *sizeof (struct posix_acl_xattr_entry_r ))); +} + +static inline int +posix_acl_xattr_count_r (size_t size) +{ +if (size <sizeof (struct posix_acl_xattr_header )) +return -1 ; + size -=sizeof (struct posix_acl_xattr_header ); +if (size %sizeof (struct posix_acl_xattr_entry_r )) +return -1 ; +return size /sizeof (struct posix_acl_xattr_entry_r ); +} + +/* Whether an ACL_USER or ACL_GROUP entry of @acl is a UUID or GUID */ +static inline bool posix_acl_has_id_r (const struct posix_acl *acl) +{ +for (int n =0 ; n < acl->a_count; n++) { +const struct posix_acl_entry *e = &acl->a_entries[n]; + +if ((e->e_tag ==ACL_USER && !uid_is_legacy (e->e_uid)) || + (e->e_tag ==ACL_GROUP && !gid_is_legacy (e->e_gid))) +return true; + } +return false; +} +#ifdef CONFIG_FS_POSIX_ACL struct posix_acl *posix_acl_from_xattr (struct user_namespace *user_ns,const void *value,size_t size);
include/uapi/linux/posix_acl_xattr.h +19 -0
@@ -36,4 +36,23 @@ struct posix_acl_xattr_header { __le32 a_version; }; +/* +* Version 3: the ids of ACL_USER and ACL_GROUP entries can also be UUIDs +* and GUIDs. e_type is a UID_R_* kind (<linux/uidgid_r.h>); a classic id +* is in the first four bytes of e_id, little endian, a UUID or GUID takes +* all of it in the byte order of __kernel_uid_r_t. Other entries have +* e_type UID_R_NONE. +* +* getxattr() returns version 2 unless an entry has a UUID or GUID; +* setxattr() takes both. +*/ +#define POSIX_ACL_XATTR_VERSION_R 0x0003 + +struct posix_acl_xattr_entry_r { +__le16 e_tag; +__le16 e_perm; +__le32 e_type; +__u8 e_id[16 ]; +}; +#endif /* __UAPI_POSIX_ACL_XATTR_H */
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 33/41] posix_acl: support UUID and GUID entries
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] posix_acl: version 3 ACLs accepted by posix_acl_from_xattr() corrupt on writeback --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] posix_acl: version 3 ACLs accepted by posix_acl_from_xattr() corrupt on writeback --
commit 2e207d2596cd01ebad6cf100258b3d1483a2d6a6
Author: Jan Koester <[email protected]>
posix_acl: support UUID and GUID entries
This commit adds version 3 of the POSIX ACL xattr format to support 16-byte UUID and GUID entries in ACL_USER and ACL_GROUP tags. It updates setxattr() to accept both version 2 and version 3, getxattr() to emit version 3 when needed, and set_posix_acl() to reject UUID and GUID entries with -EOVERFLOW on filesystems without SB_I_UID_R.
Quoted 4 lines
fs/posix_acl.c +0
-0
[ ... ]
fs/posix_acl.c struct posix_acl *posix_acl_from_xattr(struct user_namespace *userns, · line 851
Quoted 10 lines
fs/posix_acl.c +6
-0@@ -795,6 +843,13 @@ struct posix_acl *posix_acl_from_xattr(struct user_namespace *userns,return ERR_PTR (-ENOMEM ); acl_e = acl->a_entries; +if (header->a_version ==cpu_to_le32 (POSIX_ACL_XATTR_VERSION_R )) { +if (posix_acl_from_xattr_r (userns, (const void *)(header +1 ), + acl)) + goto fail; +return acl; + }
[Severity: Medium]
Can accepting POSIX_ACL_XATTR_VERSION_R unconditionally in posix_acl_from_xattr() corrupt ACLs on writeback for filesystems that do not set SB_I_UID_R?
posix_acl_from_xattr() is used both by the VFS setxattr() path in do_set_acl() and by filesystems that store POSIX ACLs in the uapi xattr format (such as btrfs, fuse, 9p, ceph, erofs, gfs2, jfs, ntfs, ntfs3, and orangefs) in their ->get_acl() and ->get_inode_acl() callbacks.
If a backing store returns a version 3 xattr containing UUID or GUID entries (for example, a fuse/virtiofs or 9p server exporting a host directory where getxattr() returns version 3, or a filesystem image with a version 3 xattr), posix_acl_from_xattr() will load and cache a struct posix_acl with non-legacy kuid_t or kgid_t entries on a filesystem without SB_I_UID_R.
When chmod() (via posix_acl_chmod()) or file creation under a directory with a default ACL (via posix_acl_create()) later writes the ACL back, it invokes ->set_acl() or filesystem init_acl directly without going through the SB_I_UID_R check in set_posix_acl(). Those filesystems serialize the ACL with posix_acl_to_xattr(), which only emits version 2:
fs/posix_acl.c:posix_acl_to_xattr() {
...
ext_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION);
for (n=0; n < acl->a_count; n++, ext_entry++) {
const struct posix_acl_entry *acl_e = &acl->a_entries[n];
ext_entry->e_tag = cpu_to_le16(acl_e->e_tag);
ext_entry->e_perm = cpu_to_le16(acl_e->e_perm);
switch(acl_e->e_tag) {
case ACL_USER:
ext_entry->e_id =
cpu_to_le32(from_kuid(user_ns, acl_e->e_uid));
break;
case ACL_GROUP:
ext_entry->e_id =
cpu_to_le32(from_kgid(user_ns, acl_e->e_gid));
break;
...
}Because from_kuid() and from_kgid() return (uid_t)-1 and (gid_t)-1 for non-legacy IDs, posix_acl_to_xattr() writes a version 2 xattr with e_id set to ACL_UNDEFINED_ID (-1). When that xattr is subsequently read back by posix_acl_from_xattr(), make_kuid() and make_kgid() produce INVALID_UID and INVALID_GID, causing subsequent get_inode_acl(), getxattr(), and generic_permission() calls on the inode to fail with -EINVAL.
Should version 3 xattr decoding be restricted to the VFS userspace xattr path (or gated on filesystems that support version 3 / SB_I_UID_R), rather than enabled for all posix_acl_from_xattr() callers whose writeback path uses posix_acl_to_xattr()?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=33
RFC PATCH v2 34/41 ext4: store ACLs with UUID and GUID entries on uid_r filesystems
In reply to Jan KoesterACLs 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.
--- fs/ext4/acl.c | 109 +++++++++++++++++++++++++++++++++++++++----------- fs/ext4/acl.h | 34 +++++++++++++--- 2 files changed, 115 insertions(+), 28 deletions(-)
fs/ext4/acl.c +86 -23
@@ -6,6 +6,7 @@*/ #include <linux/quotaops.h> +#include <linux/unaligned.h> #include "ext4_jbd2.h" #include "ext4.h" #include "xattr.h"
@@ -14,22 +15,41 @@/* * Convert from filesystem to in-memory representation. */ +/* The id of an ACL_USER or ACL_GROUP entry of EXT4_ACL_VERSION_R */ +static int ext4_acl_id_from_disk (const ext4_acl_entry_r *entry,u32 *type, +u32 *legacy,uuid_t *id) +{ + *type =le32_to_cpu (entry->e_type); +if (*type >EXT4_ID_R_GUID ) +return -EINVAL ; + *legacy =get_unaligned_le32 (entry->e_id); +memcpy (id->b, entry->e_id,sizeof (id->b)); +return 0 ; +} +static struct posix_acl *ext4_acl_from_disk (const void *value,size_t size) {const char *end = (char *)value + size;int n, count;struct posix_acl *acl; +size_t entry_size =sizeof (ext4_acl_entry); +bool r = false;if (!value)return NULL ;if (size <sizeof (ext4_acl_header))return ERR_PTR (-EINVAL ); -if (((ext4_acl_header *)value)->a_version != -cpu_to_le32 (EXT4_ACL_VERSION )) +if (((ext4_acl_header *)value)->a_version == +cpu_to_le32 (EXT4_ACL_VERSION_R )) { + r = true; + entry_size =sizeof (ext4_acl_entry_r); + }else if (((ext4_acl_header *)value)->a_version != +cpu_to_le32 (EXT4_ACL_VERSION )) {return ERR_PTR (-EINVAL ); + } value = (char *)value +sizeof (ext4_acl_header); - count =ext4_acl_count (size); + count =ext4_acl_count_e (size, entry_size);if (count <0 )return ERR_PTR (-EINVAL );if (count ==0 )
@@ -55,21 +75,33 @@ ext4_acl_from_disk(const void *value, size_t size)break ;case ACL_USER : - value = (char *)value +sizeof (ext4_acl_entry); +case ACL_GROUP : { +u32 type =EXT4_ID_R_LEGACY , legacy; +uuid_t id; + + value = (char *)value + entry_size;if ((char *)value > end) goto fail; - acl->a_entries[n].e_uid = -make_kuid (&init_user_ns, -le32_to_cpu (entry->e_id)); -break ; -case ACL_GROUP : - value = (char *)value +sizeof (ext4_acl_entry); -if ((char *)value > end) + legacy =le32_to_cpu (entry->e_id); +if (r &&ext4_acl_id_from_disk ((void *)entry, &type, + &legacy, &id)) goto fail; - acl->a_entries[n].e_gid = -make_kgid (&init_user_ns, -le32_to_cpu (entry->e_id)); +if (acl->a_entries[n].e_tag ==ACL_USER ) + acl->a_entries[n].e_uid = + type ==EXT4_ID_R_LEGACY ? +make_kuid (&init_user_ns, legacy) : + type ==EXT4_ID_R_UUID ? +KUIDT_INIT_UUID (id) : +KUIDT_INIT_GUID (*(guid_t *)&id); +else + acl->a_entries[n].e_gid = + type ==EXT4_ID_R_LEGACY ? +make_kgid (&init_user_ns, legacy) : + type ==EXT4_ID_R_UUID ? +KGIDT_INIT_UUID (id) : +KGIDT_INIT_GUID (*(guid_t *)&id);break ; + }default : goto fail;
@@ -87,19 +119,38 @@ ext4_acl_from_disk(const void *value, size_t size)/* * Convert from in-memory to filesystem representation. */ +/* An ACL_USER or ACL_GROUP id into an entry of EXT4_ACL_VERSION_R */ +static void ext4_acl_id_to_disk (ext4_acl_entry_r *entry,u32 type,u32 legacy, +const uuid_t *id) +{ + entry->e_type =cpu_to_le32 (type); +memset (entry->e_id,0 ,sizeof (entry->e_id)); +if (type ==EXT4_ID_R_LEGACY ) +put_unaligned_le32 (legacy, entry->e_id); +else +memcpy (entry->e_id, id->b,sizeof (entry->e_id)); +} + +/* +* ACLs with UUID or GUID entries (only on uid_r filesystems, see +* set_posix_acl()) are written as EXT4_ACL_VERSION_R, others as before. +*/ static void *ext4_acl_to_disk (const struct posix_acl *acl,size_t *size) {ext4_acl_header *ext_acl;char *e;size_t n; +bool r =posix_acl_has_id_r (acl); +size_t entry_size = r ?sizeof (ext4_acl_entry_r) :sizeof (ext4_acl_entry); - *size =ext4_acl_size (acl->a_count); + *size =ext4_acl_size_e (acl->a_count, entry_size); ext_acl =kmalloc (sizeof (ext4_acl_header) + acl->a_count * -sizeof (ext4_acl_entry),GFP_NOFS ); + entry_size,GFP_NOFS );if (!ext_acl)return ERR_PTR (-ENOMEM ); - ext_acl->a_version =cpu_to_le32 (EXT4_ACL_VERSION ); + ext_acl->a_version =cpu_to_le32 (r ?EXT4_ACL_VERSION_R : +EXT4_ACL_VERSION ); e = (char *)ext_acl +sizeof (ext4_acl_header);for (n =0 ; n < acl->a_count; n++) {const struct posix_acl_entry *acl_e = &acl->a_entries[n];
@@ -108,14 +159,26 @@ ext4_acl_to_disk(const struct posix_acl *acl, size_t *size) entry->e_perm =cpu_to_le16 (acl_e->e_perm);switch (acl_e->e_tag) {case ACL_USER : - entry->e_id =cpu_to_le32 ( -from_kuid (&init_user_ns, acl_e->e_uid)); - e +=sizeof (ext4_acl_entry); +if (r) +ext4_acl_id_to_disk ((void *)entry, + acl_e->e_uid.type, +from_kuid (&init_user_ns, acl_e->e_uid), + &acl_e->e_uid.uuid); +else + entry->e_id =cpu_to_le32 ( +from_kuid (&init_user_ns, acl_e->e_uid)); + e += entry_size;break ;case ACL_GROUP : - entry->e_id =cpu_to_le32 ( -from_kgid (&init_user_ns, acl_e->e_gid)); - e +=sizeof (ext4_acl_entry); +if (r) +ext4_acl_id_to_disk ((void *)entry, + acl_e->e_gid.type, +from_kgid (&init_user_ns, acl_e->e_gid), + &acl_e->e_gid.uuid); +else + entry->e_id =cpu_to_le32 ( +from_kgid (&init_user_ns, acl_e->e_gid)); + e += entry_size;break ;case ACL_USER_OBJ :
fs/ext4/acl.h +29 -5
@@ -8,6 +8,8 @@#include <linux/posix_acl_xattr.h> #define EXT4_ACL_VERSION 0x0001 +/* uid_r: ACL_USER and ACL_GROUP entries are ext4_acl_entry_r */ +#define EXT4_ACL_VERSION_R 0x0002 typedef struct { __le16 e_tag;
@@ -20,11 +22,23 @@ typedef struct {__le16 e_perm; } ext4_acl_entry_short; +/* +* EXT4_ACL_VERSION_R: e_type an EXT4_ID_R_* kind, a classic id in the +* first four bytes of e_id (little endian), a UUID or GUID all of it +*/ +typedef struct { +__le16 e_tag; +__le16 e_perm; +__le32 e_type; +__u8 e_id[16 ]; +}ext4_acl_entry_r ; +typedef struct {__le32 a_version; }ext4_acl_header ; -static inline size_t ext4_acl_size (int count) +/* @entry: sizeof(ext4_acl_entry) or, for EXT4_ACL_VERSION_R, of _r */ +static inline size_t ext4_acl_size_e (int count,size_t entry) {if (count <=4 ) { return sizeof(ext4_acl_header) +
@@ -32,11 +46,11 @@ static inline size_t ext4_acl_size(int count) }else {return sizeof (ext4_acl_header) +4 *sizeof (ext4_acl_entry_short) + - (count -4 ) *sizeof (ext4_acl_entry); + (count -4 ) * entry; } } -static inline int ext4_acl_count (size_t size) +static inline int ext4_acl_count_e (size_t size,size_t entry) {ssize_t s; size -=sizeof (ext4_acl_header);
@@ -46,12 +60,22 @@ static inline int ext4_acl_count(size_t size)return -1 ;return size /sizeof (ext4_acl_entry_short); }else { -if (s %sizeof (ext4_acl_entry)) +if (s % entry)return -1 ; -return s /sizeof (ext4_acl_entry) +4 ; +return s / entry +4 ; } } +static inline size_t ext4_acl_size (int count) +{ +return ext4_acl_size_e (count,sizeof (ext4_acl_entry)); +} + +static inline int ext4_acl_count (size_t size) +{ +return ext4_acl_count_e (size,sizeof (ext4_acl_entry)); +} +#ifdef CONFIG_EXT4_FS_POSIX_ACL /* acl.c */
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 34/41] ext4: store ACLs with UUID and GUID entries on uid_r filesystems
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] ext4: under-reserved journal credits in ext4_set_acl() and new inode ACLs - [Medium] ext4: missing…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] ext4: under-reserved journal credits in ext4_set_acl() and new inode ACLs
- [Medium] ext4: missing uid_r check in ext4_get_acl() and ext4_acl_to_disk() --
commit 9cf145428ff7d92b62a997fd08d61060d4a516a9
Author: Jan Koester <[email protected]>
ext4: store ACLs with UUID and GUID entries on uid_r filesystems
This commit adds the EXT4_ACL_VERSION_R on-disk format so ext4 can store POSIX ACLs containing 16-byte UUID or GUID user and group entries on uid_r filesystems. ACLs without UUID or GUID entries continue to use the legacy EXT4_ACL_VERSION format.
Quoted 4 lines
fs/ext4/acl.c +0
-0
[ ... ]
Quoted 29 lines
fs/ext4/acl.c +14
-0@@ -14,22 +15,41 @@/* * Convert from filesystem to in-memory representation. */ +/* The id of an ACL_USER or ACL_GROUP entry of EXT4_ACL_VERSION_R */ +static int ext4_acl_id_from_disk (const ext4_acl_entry_r *entry,u32 *type, +u32 *legacy,uuid_t *id) +{ + *type =le32_to_cpu (entry->e_type); +if (*type >EXT4_ID_R_GUID ) +return -EINVAL ; + *legacy =get_unaligned_le32 (entry->e_id); +memcpy (id->b, entry->e_id,sizeof (id->b)); +return 0 ; +} +static struct posix_acl *ext4_acl_from_disk (const void *value,size_t size) {const char *end = (char *)value + size;int n, count;struct posix_acl *acl; +size_t entry_size =sizeof (ext4_acl_entry); +bool r = false;if (!value)return NULL ;if (size <sizeof (ext4_acl_header))return ERR_PTR (-EINVAL );
fs/ext4/acl.c line 50
Quoted 10 lines
fs/ext4/acl.c +7
-2-if (((ext4_acl_header *)value)->a_version != -cpu_to_le32 (EXT4_ACL_VERSION )) +if (((ext4_acl_header *)value)->a_version == +cpu_to_le32 (EXT4_ACL_VERSION_R )) { + r = true; + entry_size =sizeof (ext4_acl_entry_r); + }else if (((ext4_acl_header *)value)->a_version != +cpu_to_le32 (EXT4_ACL_VERSION )) {return ERR_PTR (-EINVAL ); + }
[Severity: Medium]
Should ext4_get_acl() -> ext4_acl_from_disk() and ext4_acl_to_disk() verify that uid_r is enabled on the filesystem before accepting or writing EXT4_ACL_VERSION_R entries?
In fs/ext4/inode.c, both ext4_inode_get_id_r() and ext4_inode_set_id_r() check ext4_has_feature_uid_r(inode->i_sb), whereas ext4_get_acl() in fs/ext4/acl.c calls ext4_acl_from_disk() without checking ext4_has_feature_uid_r(inode->i_sb) or SB_I_UID_R:
fs/ext4/acl.c:ext4_get_acl() {
...
if (retval > 0)
acl = ext4_acl_from_disk(value, retval);
...
}In addition, the comment above ext4_acl_to_disk() notes that set_posix_acl() rejects non-legacy IDs when SB_I_UID_R is not set, but two write paths in fs/ext4/acl.c bypass set_posix_acl():
1. chmod() calls posix_acl_chmod() -> ext4_set_acl() -> __ext4_set_acl() -> ext4_acl_to_disk().
2. New inode creation calls __ext4_new_inode() -> ext4_init_acl() -> posix_acl_create() -> __ext4_set_acl() -> ext4_acl_to_disk():
fs/ext4/acl.c:ext4_init_acl() {
...
if (default_acl) {
error = __ext4_set_acl(handle, inode, ACL_TYPE_DEFAULT,
default_acl, XATTR_CREATE);
posix_acl_release(default_acl);
}
...
}If a filesystem without EXT4_FEATURE_RO_COMPAT_UID_R (or a uid_r filesystem mounted with -o nouid32, where __ext4_fill_super() leaves SB_I_UID_R unset) has an existing EXT4_ACL_VERSION_R xattr on disk, wouldn't ext4_get_acl() load those non-legacy entries and allow chmod() or file creation to write new EXT4_ACL_VERSION_R xattrs onto the filesystem?
[ ... ]
Quoted 31 lines
fs/ext4/acl.c +19
-1@@ -87,19 +119,38 @@ ext4_acl_from_disk(const void *value, size_t size)/* * Convert from in-memory to filesystem representation. */ +/* An ACL_USER or ACL_GROUP id into an entry of EXT4_ACL_VERSION_R */ +static void ext4_acl_id_to_disk (ext4_acl_entry_r *entry,u32 type,u32 legacy, +const uuid_t *id) +{ + entry->e_type =cpu_to_le32 (type); +memset (entry->e_id,0 ,sizeof (entry->e_id)); +if (type ==EXT4_ID_R_LEGACY ) +put_unaligned_le32 (legacy, entry->e_id); +else +memcpy (entry->e_id, id->b,sizeof (entry->e_id)); +} + +/* +* ACLs with UUID or GUID entries (only on uid_r filesystems, see +* set_posix_acl()) are written as EXT4_ACL_VERSION_R, others as before. +*/ static void *ext4_acl_to_disk (const struct posix_acl *acl,size_t *size) {ext4_acl_header *ext_acl;char *e;size_t n; +bool r =posix_acl_has_id_r (acl); +size_t entry_size = r ?sizeof (ext4_acl_entry_r) :sizeof (ext4_acl_entry); - *size =ext4_acl_size (acl->a_count); + *size =ext4_acl_size_e (acl->a_count, entry_size);
[ ... ]
Quoted 4 lines
fs/ext4/acl.h +0
-0
[ ... ]
Quoted 6 lines
fs/ext4/acl.h +1
-1@@ -46,12 +60,22 @@ static inline int ext4_acl_count(size_t size)return -1 ;return size /sizeof (ext4_acl_entry_short); }else { -if (s %sizeof (ext4_acl_entry)) +if (s % entry)
fs/ext4/acl.h static inline int ext4_acl_count(size_t size) · line 72
Quoted 10 lines
fs/ext4/acl.h +5
-1return -1 ; -return s /sizeof (ext4_acl_entry) +4 ; +return s / entry +4 ; } } +static inline size_t ext4_acl_size (int count) +{ +return ext4_acl_size_e (count,sizeof (ext4_acl_entry)); +}
[Severity: High]
Can leaving ext4_acl_size() hardcoded to sizeof(ext4_acl_entry) cause journal credit under-reservation in ext4_set_acl() and ext4_xattr_credits_for_new_inode()?
When posix_acl_has_id_r(acl) is true, ext4_acl_to_disk() in fs/ext4/acl.c serializes ACL_USER and ACL_GROUP entries using sizeof(ext4_acl_entry_r) (24 bytes) and sets *size to ext4_acl_size_e(acl->a_count, sizeof(ext4_acl_entry_r)).
However, ext4_set_acl() in fs/ext4/acl.c still computes acl_size using ext4_acl_size(acl->a_count), which assumes 8-byte ext4_acl_entry elements:
fs/ext4/acl.c:ext4_set_acl() {
...
size_t acl_size = acl ? ext4_acl_size(acl->a_count) : 0;
...
retry:
error = ext4_xattr_set_credits(inode, acl_size, false /* is_create */,
&credits);
}Similarly, when a new inode inherits a default ACL in __ext4_new_inode() -> ext4_init_acl(), ext4_xattr_credits_for_new_inode() in fs/ext4/ialloc.c computes acl_size using sizeof(ext4_acl_entry):
fs/ext4/ialloc.c:ext4_xattr_credits_for_new_inode() {
...
if (p) {
int acl_size = p->a_count * sizeof(ext4_acl_entry);
nblocks += (S_ISDIR(mode) ? 2 : 1) *
__ext4_xattr_set_credits(sb, NULL /* inode */,
NULL /* block_bh */, acl_size,
true /* is_create */);
posix_acl_release(p);
}
}When the ea_inode feature is enabled on the filesystem, __ext4_xattr_set_credits() in fs/ext4/xattr.c scales the credit count with the number of blocks spanned by value_len:
fs/ext4/xattr.c:__ext4_xattr_set_credits() {
...
blocks = (value_len + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
blocks += 1;
credits += blocks * 2;
credits += blocks;
...
}Later, __ext4_set_acl() -> ext4_xattr_set_handle() recomputes the required credits from the actual serialized value_len and checks that the running handle has enough buffer credits:
fs/ext4/xattr.c:ext4_xattr_set_handle() {
...
credits = __ext4_xattr_set_credits(inode->i_sb, inode, bh,
value_len,
flags & XATTR_CREATE);
brelse(bh);
if (jbd2_handle_buffer_credits(handle) < credits) {
error = -ENOSPC;
goto cleanup;
}
}If an EXT4_ACL_VERSION_R ACL is large enough that its 24-byte entries cross a block boundary not crossed by the 8-byte estimate, won't ext4_xattr_set_handle() fail this check and return a spurious -ENOSPC (or leave __ext4_new_inode() short of journal credits for subsequent operations on the same handle)?
[ ... ]
Quoted 1 line
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=34
RFC PATCH v2 35/41 Documentation: describe UUID and GUID user and group ids
In reply to Jan KoesterDescribe __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.
--- 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
@@ -22,6 +22,7 @@ System calls ioctl/index mseal rseq + uid_r Security-related interfaces ===========================
Documentation/userspace-api/uid_r.rst new file +169 -0
169 lines not on this page · raw message
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 35/41] Documentation: describe UUID and GUID user and group ids
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
Describe
__kernel_uid_r_t, the rules for UUID and GUID ids (overflow ids in classic interfaces, the initial user namespace only, filesystems withSB_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-5Signed-off-by Jan Koester <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=35
RFC PATCH v2 36/41 selftests: add tests for UUID and GUID ids
In reply to Jan KoesterTest 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.
--- 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
@@ -140,6 +140,7 @@ TARGETS += tpm2 TARGETS += tty TARGETS += ublk TARGETS += uevent +TARGETS += uid_r TARGETS += user_events TARGETS += vDSO TARGETS += mm
tools/testing/selftests/uid_r/.gitignore new file +1 -0
@@ -0,0 +1 @@ +uid_r_test
tools/testing/selftests/uid_r/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +CFLAGS += -g -Wall $(KHDR_INCLUDES) $(TOOLS_INCLUDES) + +TEST_GEN_PROGS := uid_r_test + +include ../lib.mk
tools/testing/selftests/uid_r/config new file +4 -0
@@ -0,0 +1,4 @@ +CONFIG_TMPFS=y +CONFIG_TMPFS_POSIX_ACL=y +CONFIG_SYSVIPC=y +CONFIG_SIGNALFD=y
tools/testing/selftests/uid_r/uid_r_test.c new file +535 -0
535 lines not on this page · raw message
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 36/41] selftests: add tests for UUID and GUID ids
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] selftests: uid_r: acl_v3() writes POSIX ACL xattr fields in host byte order - [Medium]…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] selftests: uid_r: acl_v3() writes POSIX ACL xattr fields in host byte order
- [Medium] selftests/uid_r: fail instead of skip on ENOSYS in signalfd and ipc tests
- [Low] selftests: uid_r: FIXTURE_TEARDOWN() leaves mkdtemp() directories in /tmp --
commit b236f646b555e600321fde8fdcedd3ac92eccb4e
Author: Jan Koester <[email protected]>
selftests: add tests for UUID and GUID ids
This commit adds a kselftest suite for the *_r system calls and extended kernel interfaces supporting UUID and GUID user and group identifiers. It covers ID validation, credential switching, supplementary groups, filesystem ownership on tmpfs, socket credentials, signalfd, SysV IPC, POSIX ACL v3 xattrs, /proc/self/status, and user namespace restrictions.
Quoted 6 lines
tools/testing/selftests/uid_r/uid_r_test.c new file +0
-0@@ -0,0 +1,535 @@
[ ... ]
Quoted 9 lines
tools/testing/selftests/uid_r/uid_r_test.c new file +9
-0+/* a private tmpfs at a fresh directory, for file tests */ +static void private_tmpfs (struct __test_metadata *_metadata,char *dir) +{ +strcpy (dir,"/tmp/uid_r.XXXXXX" ); +ASSERT_EQ (0 ,unshare (CLONE_NEWNS )); +ASSERT_EQ (0 ,mount (NULL ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL )); +ASSERT_NE (NULL ,mkdtemp (dir)); +ASSERT_EQ (0 ,mount ("tmpfs" , dir,"tmpfs" ,0 ,"mode=1777" )); +}
[ ... ]
Quoted 8 lines
tools/testing/selftests/uid_r/uid_r_test.c new file +8
-0+FIXTURE (uid_r) { +char dir[64 ]; +}; + +FIXTURE_SETUP (uid_r) +{ +id_r id; +
tools/testing/selftests/uid_r/uid_r_test.c line 179
Quoted 10 lines
tools/testing/selftests/uid_r/uid_r_test.c new file +10
-0+if (geteuid () !=0 ) +SKIP (return,"needs root" ); +if (sys (__NR_getuid_r, (long )&id,0 ,0 ,0 ,0 ) == -ENOSYS ) +SKIP (return,"no *_r system calls" ); + self->dir[0 ] =0 ; +} + +FIXTURE_TEARDOWN (uid_r) +{ +}
[Severity: Low]
Does FIXTURE_TEARDOWN(uid_r) leak the temporary /tmp/uid_r.XXXXXX mountpoint directories created by private_tmpfs()?
In tools/testing/selftests/uid_r/uid_r_test.c, private_tmpfs() calls unshare(CLONE_NEWNS) and makes mount propagation private, then calls mkdtemp(dir) on the underlying /tmp filesystem before mounting tmpfs onto dir.
When chown_r_statx, create_as_uuid_fsuid, posix_acl_v3, and user_namespace call private_tmpfs(_metadata, self->dir), the private tmpfs mount is cleaned up when the test child process exits, but because FIXTURE_TEARDOWN(uid_r) is empty, the underlying self->dir directory in /tmp is never unmounted and removed with rmdir(self->dir) when self->dir[0] is non-empty.
[ ... ]
Quoted 12 lines
tools/testing/selftests/uid_r/uid_r_test.c new file +12
-0+TEST_F(uid_r, signalfd_uid_r) +{ +id_r u =uuid (11 ), s0 =legacy (0 ), got; +struct signalfd_siginfo ssi; +sigset_t mask; +int sfd; + +sigemptyset (&mask); +sigaddset (&mask,SIGUSR1 ); +ASSERT_EQ (0 ,sigprocmask (SIG_BLOCK , &mask,NULL )); + sfd =signalfd (-1 , &mask,0 ); +ASSERT_LE (0 , sfd);
[ ... ]
Quoted 4 lines
tools/testing/selftests/uid_r/uid_r_test.c new file +4
-0+TEST_F(uid_r, ipc_stat_r) +{ +id_r u =uuid (12 ), g =guid (13 ); +struct ipc_perm_r_t pr;
tools/testing/selftests/uid_r/uid_r_test.c line 411
Quoted 10 lines
tools/testing/selftests/uid_r/uid_r_test.c new file +10
-0+struct shmid_ds ds; +int id; + +memset (&pr,0 ,sizeof (pr)); + pr.mode =0640 ; + pr.uid = u; + pr.gid = g; + + id =shmget (IPC_PRIVATE ,4096 ,IPC_CREAT |0600 ); +ASSERT_LE (0 , id);
[Severity: Medium]
Should signalfd_uid_r and ipc_stat_r skip instead of failing when the kernel is built without CONFIG_SIGNALFD or CONFIG_SYSVIPC?
In tools/testing/selftests/uid_r/uid_r_test.c, if CONFIG_SIGNALFD=n or CONFIG_SYSVIPC=n, signalfd() in signalfd_uid_r and shmget() in ipc_stat_r return -1 with errno set to ENOSYS, and ASSERT_LE() fails the tests outright rather than calling SKIP().
Also, tools/testing/selftests/uid_r/config lists:
CONFIG_TMPFS=y
CONFIG_TMPFS_POSIX_ACL=y
CONFIG_SYSVIPC=y
CONFIG_SIGNALFD=y
Should tools/testing/selftests/uid_r/config also include CONFIG_USER_NS=y so that the user_namespace test is not skipped on kernels built using the selftest config fragment?
[ ... ]
Quoted 33 lines
tools/testing/selftests/uid_r/uid_r_test.c new file +33
-0+/* user::rw- user:<u>:r-- group::--- mask::r-- other::--- in version 3 */ +static size_t acl_v3 (unsigned char *buf,const id_r *u) +{ +static const unsigned short ent[5 ][2 ] = { + {0x01 ,6 }, {0x02 ,4 }, {0x04 ,0 }, {0x10 ,4 }, {0x20 ,0 } }; +unsigned char *e = buf +4 ; +unsigned int ver =3 ; + +memcpy (buf, &ver,4 ); +for (int i =0 ; i <5 ; i++, e +=24 ) { +unsigned int type =0 ; + +memset (e,0 ,24 ); +memcpy (e, &ent[i][0 ],2 ); +memcpy (e +2 , &ent[i][1 ],2 ); +if (ent[i][0 ] ==0x02 ) { + type = u->type; +memcpy (e +8 , u->uuid,16 ); + } +memcpy (e +4 , &type,4 ); + } +return 4 +5 *24 ; +} + +TEST_F(uid_r, posix_acl_v3) +{ +unsigned char buf[256 ], got[256 ]; +id_r u =uuid (20 ), s0 =legacy (0 ); +char path[96 ]; +size_t len; +int fd; + +private_tmpfs (_metadata, self->dir);
tools/testing/selftests/uid_r/uid_r_test.c line 465
Quoted 10 lines
tools/testing/selftests/uid_r/uid_r_test.c new file +10
-0+snprintf (path,sizeof (path),"%s/acl" , self->dir); + fd =open (path,O_CREAT |O_WRONLY ,0600 ); +ASSERT_LE (0 , fd); +close (fd); + len =acl_v3 (buf, &u); +if (setxattr (path,"system.posix_acl_access" , buf, len,0 ) && + errno ==EOPNOTSUPP ) +SKIP (return,"tmpfs without POSIX ACLs" ); +ASSERT_EQ (len,getxattr (path,"system.posix_acl_access" , got,sizeof (got))); +EXPECT_EQ (3 , got[0 ]);
[Severity: Medium]
Won't acl_v3() and posix_acl_v3 fail or falsely skip on big-endian architectures because the POSIX ACL xattr fields are serialized in host byte order instead of little-endian?
In include/uapi/linux/posix_acl_xattr.h, struct posix_acl_xattr_header defines a_version as __le32, and struct posix_acl_xattr_entry_r defines e_tag and e_perm as __le16 and e_type as __le32. In fs/posix_acl.c, posix_acl_fix_xattr_common() checks header->a_version against cpu_to_le32(POSIX_ACL_XATTR_VERSION_R) and returns -EOPNOTSUPP on a mismatch, while posix_acl_from_xattr_r() converts e_tag, e_perm, and e_type using le16_to_cpu() and le32_to_cpu().
In tools/testing/selftests/uid_r/uid_r_test.c, acl_v3() copies host-endian unsigned int ver, unsigned short ent[i][0] and ent[i][1], and unsigned int type directly into buf with memcpy(). On big-endian systems, setxattr() in posix_acl_v3 sees a byte-swapped a_version and fails with EOPNOTSUPP, which posix_acl_v3 then treats as "tmpfs without POSIX ACLs" and skips even when CONFIG_TMPFS_POSIX_ACL=y is enabled.
In addition, if setxattr() fails with an errno other than EOPNOTSUPP, posix_acl_v3 does not assert that setxattr() succeeded before calling getxattr().
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=36
RFC PATCH v2 37/41 ovl: allow UUID and GUID owners when the upper layer does
In reply to Jan KoesterChanges 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.
--- fs/overlayfs/super.c | 3 +++ 1 file changed, 3 insertions(+)
fs/overlayfs/super.c +3 -0
@@ -1455,6 +1455,9 @@ static int ovl_fill_super_creds(struct fs_context *fc, struct super_block *sb) sb->s_stack_depth = upper_sb->s_stack_depth; sb->s_time_gran = upper_sb->s_time_gran; +/* changes land in the upper layer: its kinds of owner */ +if (upper_sb->s_iflags &SB_I_UID_R ) + sb->s_iflags |=SB_I_UID_R ; } oe =ovl_get_lowerstack (sb, ctx, ofs, layers); err =PTR_ERR (oe);
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 37/41] ovl: allow UUID and GUID owners when the upper layer does
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
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_Rover 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-5Signed-off-by Jan Koester <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=37
RFC PATCH v2 38/41 devpts: allow UUID and GUID owners
In reply to Jan KoesterTerminals 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.
--- fs/devpts/inode.c | 2 ++ 1 file changed, 2 insertions(+)
fs/devpts/inode.c +2 -0
@@ -363,6 +363,8 @@ static int devpts_fill_super(struct super_block *s, struct fs_context *fc)struct inode *inode; s->s_iflags &= ~SB_I_NODEV ; +/* owners live in memory only, a UUID or GUID one as well */ + s->s_iflags |=SB_I_UID_R ; s->s_blocksize =1024 ; s->s_blocksize_bits =10 ; s->s_magic =DEVPTS_SUPER_MAGIC ;
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 38/41] devpts: allow UUID and GUID owners
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
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-EOVERFLOWand the session is closed.Assisted-by Claude:claude-opus-5-5Signed-off-by Jan Koester <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=38
RFC PATCH v2 39/41 ksmbd: log in UUID and GUID users and map them to SIDs
In reply to Jan KoesterA 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.
--- 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 +- 10 files changed, 229 insertions(+), 67 deletions(-)
fs/smb/server/ksmbd_netlink.h +14 -1
@@ -9,6 +9,7 @@#define _LINUX_KSMBD_SERVER_H#include <linux/types.h> +#include <linux/uidgid_r.h> /* * This is a userspace ABI to communicate data between ksmbd and user IPC
@@ -153,14 +154,26 @@ struct ksmbd_login_response {/* * IPC user login response extension. +* +* With KSMBD_LOGIN_EXT_ID_R, uid_r and gid_r are the user's ids and may be +* UUIDs or GUIDs (see Documentation/userspace-api/uid_r.rst); the response's +* uid and gid are then ignored. With KSMBD_LOGIN_EXT_GROUPS_R the payload +* holds ngroups __kernel_gid_r_t instead of ngroups gid_t. A user space +* that knows neither leaves flags (formerly reserved) zero. */ struct ksmbd_login_response_ext {__u32 handle;__s32 ngroups;/* supplementary group count */ -__s8 reserved[128 ];/* Reserved room */ +__u32 flags;/* KSMBD_LOGIN_EXT_* */ +__kernel_uid_r_t uid_r;/* with KSMBD_LOGIN_EXT_ID_R */ +__kernel_gid_r_t gid_r; +__s8 reserved[84 ];/* Reserved room */ __s8 ____payload[]; }; +#define KSMBD_LOGIN_EXT_ID_R 0x1 +#define KSMBD_LOGIN_EXT_GROUPS_R 0x2 +/* * IPC request to fetch net share config. */
fs/smb/server/mgmt/user_config.c +32 -3
@@ -56,6 +56,8 @@ struct ksmbd_user *ksmbd_alloc_user(struct ksmbd_login_response *resp, user->flags = resp->status; user->gid = resp->gid; user->uid = resp->uid; + user->kuid =make_kuid (&init_user_ns, resp->uid); + user->kgid =make_kgid (&init_user_ns, resp->gid); user->passkey_sz = resp->hash_sz; user->passkey =kmalloc (resp->hash_sz,KSMBD_DEFAULT_GFP );if (user->passkey)
@@ -68,12 +70,38 @@ struct ksmbd_user *ksmbd_alloc_user(struct ksmbd_login_response *resp, goto err_free;if (resp_ext) { - user->sgid =kmemdup (resp_ext->____payload, - resp_ext->ngroups *sizeof (gid_t), +int i; + +if (resp_ext->flags &KSMBD_LOGIN_EXT_ID_R ) { +/* the user's ids may be UUIDs or GUIDs */ + user->kuid =make_kuid_r (&init_user_ns, &resp_ext->uid_r); + user->kgid =make_kgid_r (&init_user_ns, &resp_ext->gid_r); +if (!uid_valid (user->kuid) || !gid_valid (user->kgid)) + goto err_free; + user->uid =from_kuid_munged (&init_user_ns, user->kuid); + user->gid =from_kgid_munged (&init_user_ns, user->kgid); + } + + user->sgid =kcalloc (resp_ext->ngroups,sizeof (kgid_t),KSMBD_DEFAULT_GFP ); -if (!user->sgid) +if (!user->sgid && resp_ext->ngroups) goto err_free; +for (i =0 ; i < resp_ext->ngroups; i++) { +if (resp_ext->flags &KSMBD_LOGIN_EXT_GROUPS_R ) { +const __kernel_gid_r_t *g = (const __kernel_gid_r_t *) + resp_ext->____payload + i; + + user->sgid[i] =make_kgid_r (&init_user_ns, g); + }else { +const gid_t *g = (const gid_t *)resp_ext->____payload + i; + + user->sgid[i] =make_kgid (&init_user_ns, *g); + } +if (!gid_valid (user->sgid[i])) + goto err_free; + } + user->ngroups = resp_ext->ngroups;ksmbd_debug (SMB ,"supplementary groups : %d\n" , user->ngroups); }
@@ -81,6 +109,7 @@ struct ksmbd_user *ksmbd_alloc_user(struct ksmbd_login_response *resp,return user; err_free: +kfree (user->sgid);kfree (user->name);kfree_sensitive (user->passkey);kfree (user);
fs/smb/server/mgmt/user_config.h +3 -1
@@ -13,13 +13,15 @@ struct ksmbd_user {unsigned int uid;unsigned int gid; +kuid_t kuid;/* the user: uid, or a UUID or GUID */ +kgid_t kgid;char *name;size_t passkey_sz;char *passkey;int ngroups; -gid_t *sgid; +kgid_t *sgid; };static inline bool user_guest (struct ksmbd_user *user)
fs/smb/server/smb2pdu.c +5 -5
@@ -4577,14 +4577,14 @@ int smb2_open(struct ksmbd_work *work)if (file_present && !(req->CreateOptions &FILE_DELETE_ON_CLOSE_LE )) { rc =smb_check_perm_dacl (conn, &path, &daccess, req->DesiredAccess, - sess->user->uid, false); + sess->user->kuid, false);if (rc) goto err_out;if (maximal_access_ctxt) { maximal_access =FILE_MAXIMAL_ACCESS_LE ; rc =smb_check_perm_dacl (conn, &path, &maximal_access, -0 , sess->user->uid, false); +0 , sess->user->kuid, false);if (rc) goto err_out;
@@ -4776,8 +4776,8 @@ int smb2_open(struct ksmbd_work *work)if (rc == -ENOENT ) {if (test_share_config_flag (work->tcon->share_conf,KSMBD_SHARE_FLAG_ACL_XATTR )) { - rc =smb_inherit_dacl (conn, &path, sess->user->uid, - sess->user->gid); + rc =smb_inherit_dacl (conn, &path, sess->user->kuid, + sess->user->kgid); }if (rc) {if (posix_acl_rc)
@@ -5837,7 +5837,7 @@ static int process_query_dir_entries(struct smb2_query_dir_private *priv) path.dentry = dent; rc =smb_check_perm_dacl (priv->work->conn, &path, &daccess, daccess, - priv->work->sess->user->uid, + priv->work->sess->user->kuid, true);if (rc) {dput (dent);
fs/smb/server/smb_common.c +9 -9
@@ -797,23 +797,23 @@ int __ksmbd_override_fsids(struct ksmbd_work *work,struct ksmbd_user *user = sess->user;struct cred *cred;struct group_info *gi; -unsigned int uid; -unsigned int gid; +kuid_t uid; +kgid_t gid;int i; - uid =user_uid (user); - gid =user_gid (user); + uid = user->kuid; + gid = user->kgid;if (share->force_uid !=KSMBD_SHARE_INVALID_UID ) - uid = share->force_uid; + uid =make_kuid (&init_user_ns, share->force_uid);if (share->force_gid !=KSMBD_SHARE_INVALID_GID ) - gid = share->force_gid; + gid =make_kgid (&init_user_ns, share->force_gid); cred =prepare_kernel_cred (&init_task);if (!cred)return -ENOMEM ; - cred->fsuid =make_kuid (&init_user_ns, uid); - cred->fsgid =make_kgid (&init_user_ns, gid); + cred->fsuid = uid; + cred->fsgid = gid; gi =groups_alloc (user->ngroups);if (!gi) {
@@ -822,7 +822,7 @@ int __ksmbd_override_fsids(struct ksmbd_work *work, }for (i =0 ; i < user->ngroups; i++) - gi->gid[i] =make_kgid (&init_user_ns, user->sgid[i]); + gi->gid[i] = user->sgid[i];if (user->ngroups)groups_sort (gi);
fs/smb/server/smbacl.c +139 -39
283 lines not on this page · raw message
fs/smb/server/smbacl.h +17 -2
@@ -93,18 +93,33 @@ void posix_state_to_acl(struct posix_acl_state *state,int compare_sids (const struct smb_sid *ctsid,const struct smb_sid *cwsid);bool smb_inherit_flags (int flags,bool is_dir);int smb_inherit_dacl (struct ksmbd_conn *conn,const struct path *path, -unsigned int uid,unsigned int gid); +kuid_t uid,kgid_t gid);int smb_check_perm_dacl (struct ksmbd_conn *conn,const struct path *path, -__le32 *pdaccess,__le32 raw_daccess,int uid, +__le32 *pdaccess,__le32 raw_daccess,kuid_t uid,bool strict);int set_info_sec (struct ksmbd_conn *conn,struct ksmbd_tree_connect *tcon,const struct path *path,struct smb_ntsd *pntsd,int ntsd_len,bool type_check,bool get_write);void id_to_sid (unsigned int cid,uint sidtype,struct smb_sid *ssid); +void ksmbd_uid_to_sid (kuid_t uid,uint sidtype,struct smb_sid *ssid); +void ksmbd_gid_to_sid (kgid_t gid,uint sidtype,struct smb_sid *ssid);void ksmbd_init_domain (u32 *sub_auth);size_t smb_acl_sec_desc_scratch_len (struct smb_fattr *fattr,struct smb_ntsd *ppntsd,int ppntsd_size,int addition_info); +/* the owner of an ACL entry as a kuid (also a UUID or GUID) */ +static inline kuid_t posix_acl_kuid_translate (struct mnt_idmap *idmap, +struct posix_acl_entry *pace) +{ +return vfsuid_into_kuid (make_vfsuid (idmap, &init_user_ns, pace->e_uid)); +} + +static inline kgid_t posix_acl_kgid_translate (struct mnt_idmap *idmap, +struct posix_acl_entry *pace) +{ +return vfsgid_into_kgid (make_vfsgid (idmap, &init_user_ns, pace->e_gid)); +} +static inline uid_t posix_acl_uid_translate (struct mnt_idmap *idmap,struct posix_acl_entry *pace) {
fs/smb/server/transport_ipc.c +3 -1
@@ -564,7 +564,9 @@ static int ipc_validate_msg(struct ipc_msg_table_entry *entry)return -EINVAL ; } msg_sz =sizeof (struct ksmbd_login_response_ext ) + - resp->ngroups *sizeof (gid_t); + resp->ngroups * + (resp->flags &KSMBD_LOGIN_EXT_GROUPS_R ? +sizeof (__kernel_gid_r_t) :sizeof (gid_t)); } } }
fs/smb/server/vfs_cache.c +5 -4
@@ -1715,8 +1715,8 @@ int ksmbd_vfs_set_durable_owner(struct ksmbd_file *fp,spin_lock (&fp->f_lock); old_name = fp->owner.name; - fp->owner.uid = user->uid; - fp->owner.gid = user->gid; + fp->owner.uid = user->kuid; + fp->owner.gid = user->kgid; fp->owner.name = name;spin_unlock (&fp->f_lock);kfree (old_name);
@@ -1747,7 +1747,7 @@ bool ksmbd_vfs_compare_durable_owner(struct ksmbd_file *fp, goto out;/* Check if the UID and GID match first (fast path) */ -if (fp->owner.uid != user->uid || fp->owner.gid != user->gid) +if (!uid_eq (fp->owner.uid, user->kuid) || !gid_eq (fp->owner.gid, user->kgid)) goto out;/* Validate the account name to ensure the same SecurityContext */
@@ -1953,7 +1953,8 @@ int ksmbd_reopen_durable_fd(struct ksmbd_work *work, struct ksmbd_file *fp)up_write (&ci->m_lock);spin_lock (&fp->f_lock); - fp->owner.uid = fp->owner.gid =0 ; + fp->owner.uid =GLOBAL_ROOT_UID ; + fp->owner.gid =GLOBAL_ROOT_GID ;kfree (fp->owner.name); fp->owner.name =NULL ;spin_unlock (&fp->f_lock);
fs/smb/server/vfs_cache.h +2 -2
@@ -77,8 +77,8 @@ enum {/* Owner information for durable handle reconnect */ struct durable_owner { -unsigned int uid; -unsigned int gid; +kuid_t uid; +kgid_t gid;char *name; };
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 39/41] ksmbd: log in UUID and GUID users and map them to SIDs
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] ksmbd: sid_to_id() bypasses make_kuid_r() validation for UUID/GUID SIDs - [High] ksmbd…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] ksmbd: sid_to_id() bypasses make_kuid_r() validation for UUID/GUID SIDs
- [High] ksmbd: ksmbd_alloc_user() falls back to resp uid/gid when resp_ext is NULL
- [Low] ksmbd: unused uid and gid fields and helpers in struct ksmbd_user --
commit a1ea85f35f595431966b4e9bd815708cd849c5bc
Author: Jan Koester <[email protected]>
ksmbd: log in UUID and GUID users and map them to SIDs
This commit adds support for logging in UUID and GUID users and groups via ksmbd_login_response_ext and mapping their kuid_t and kgid_t values to and from S-1-22-<kind>-w0-w1-w2-w3 SIDs in security descriptors, POSIX ACLs, and durable handle owners.
[ ... ]
Quoted 20 lines
fs/smb/server/mgmt/user_config.c +3
-2@@ -56,6 +56,8 @@ struct ksmbd_user *ksmbd_alloc_user(struct ksmbd_login_response *resp, user->flags = resp->status; user->gid = resp->gid; user->uid = resp->uid; + user->kuid =make_kuid (&init_user_ns, resp->uid); + user->kgid =make_kgid (&init_user_ns, resp->gid); user->passkey_sz = resp->hash_sz; user->passkey =kmalloc (resp->hash_sz,KSMBD_DEFAULT_GFP );if (user->passkey)@@ -68,12 +70,38 @@ struct ksmbd_user *ksmbd_alloc_user(struct ksmbd_login_response *resp, goto err_free;if (resp_ext) { - user->sgid = kmemdup(resp_ext->____payload, - resp_ext->ngroups * sizeof(gid_t), +int i;
fs/smb/server/mgmt/user_config.c struct ksmbd_user *ksmbd_alloc_user(struct ksmbd_login_response *resp, · line 83
Quoted 10 lines
fs/smb/server/mgmt/user_config.c +10
-0+ +if (resp_ext->flags &KSMBD_LOGIN_EXT_ID_R ) { +/* the user's ids may be UUIDs or GUIDs */ + user->kuid =make_kuid_r (&init_user_ns, &resp_ext->uid_r); + user->kgid =make_kgid_r (&init_user_ns, &resp_ext->gid_r); +if (!uid_valid (user->kuid) || !gid_valid (user->kgid)) + goto err_free; + user->uid =from_kuid_munged (&init_user_ns, user->kuid); + user->gid =from_kgid_munged (&init_user_ns, user->kgid); + }
[Severity: High]
What happens in ksmbd_alloc_user() in fs/smb/server/mgmt/user_config.c if resp->status has KSMBD_USER_FLAG_EXTENSION set, but fetching the login extension via ksmbd_ipc_login_request_ext() fails and returns NULL?
Both callers pass resp_ext directly to ksmbd_alloc_user() without checking whether the second IPC request succeeded:
fs/smb/server/mgmt/user_config.c:ksmbd_login_user() {
if (resp->status & KSMBD_USER_FLAG_EXTENSION)
resp_ext = ksmbd_ipc_login_request_ext(account);
user = ksmbd_alloc_user(resp, resp_ext);
}fs/smb/server/auth.c:ksmbd_krb5_authenticate() {
if (resp->login_response.status & KSMBD_USER_FLAG_EXTENSION)
resp_ext = ksmbd_ipc_login_request_ext(resp->login_response.account);
user = ksmbd_alloc_user(&resp->login_response, resp_ext);
}Per the comment on struct ksmbd_login_response_ext in fs/smb/server/ksmbd_netlink.h, resp->uid and resp->gid in the base login response are ignored when KSMBD_LOGIN_EXT_ID_R is used. However, if ksmbd_ipc_login_request_ext() returns NULL (for example on an IPC error, allocation failure, or validation failure in ipc_validate_msg()), the if (resp_ext) block is skipped and ksmbd_alloc_user() still succeeds using user->kuid and user->kgid initialized from resp->uid and resp->gid.
If userspace left resp->uid and resp->gid zeroed in the base response, the session will log in as GLOBAL_ROOT_UID and GLOBAL_ROOT_GID (keeping filesystem capabilities in __ksmbd_override_fsids()). If resp->uid or resp->gid is -1 (or when KSMBD_LOGIN_EXT_ID_R is not set), user->kuid or user->kgid becomes INVALID_UID or INVALID_GID because uid_valid() and gid_valid() are only checked inside the KSMBD_LOGIN_EXT_ID_R branch.
Should ksmbd_alloc_user() reject the login whenresp->status & KSMBD_USER_FLAG_EXTENSION is set but resp_ext is NULL, and also check uid_valid(user->kuid) and gid_valid(user->kgid) when KSMBD_LOGIN_EXT_ID_R is not set?
[ ... ]
Quoted 11 lines
fs/smb/server/mgmt/user_config.h +2
-0@@ -13,13 +13,15 @@ struct ksmbd_user {unsigned int uid;unsigned int gid; +kuid_t kuid;/* the user: uid, or a UUID or GUID */ +kgid_t kgid;
fs/smb/server/mgmt/user_config.h struct ksmbd_user { · line 27
Quoted 10 lines
fs/smb/server/mgmt/user_config.h +1
-1char *name;size_t passkey_sz;char *passkey;int ngroups; -gid_t *sgid; +kgid_t *sgid; };static inline bool user_guest (struct ksmbd_user *user)
[Severity: Low]
This isn't a bug, but now that smb2_open(), process_query_dir_entries(), __ksmbd_override_fsids(), ksmbd_vfs_set_durable_owner(), and ksmbd_vfs_compare_durable_owner() all use user->kuid and user->kgid, are the 32-bit uid and gid fields in struct ksmbd_user (and the user_uid() and user_gid() helpers in fs/smb/server/mgmt/user_config.h) still needed, or could they be dropped now that they have no remaining readers?
[ ... ]
Quoted 4 lines
fs/smb/server/smbacl.c +0
-0
[ ... ]
Quoted 29 lines
fs/smb/server/smbacl.c +25
-0@@ -279,6 +341,42 @@ static int sid_to_id(struct mnt_idmap *idmap,return -EIO ; } + { +u8 id[16 ]; +u32 kind =sid_to_id_r (psid, id); + +if (kind && sidtype ==SIDOWNER && + (kind ==SID_UNIX_UUID_USER || kind ==SID_UNIX_GUID_USER )) { +kuid_t uid; + +if (kind ==SID_UNIX_UUID_USER ) + uid =KUIDT_INIT_UUID (*(uuid_t *)id); +else + uid =KUIDT_INIT_GUID (*(guid_t *)id); + uid =from_vfsuid (idmap, &init_user_ns,VFSUIDT_INIT (uid)); +if (!uid_valid (uid)) +return -EINVAL ; + fattr->cf_uid = uid; +return 0 ; + } +if (kind && sidtype !=SIDOWNER && + (kind ==SID_UNIX_UUID_GROUP || kind ==SID_UNIX_GUID_GROUP )) { +kgid_t gid; + +if (kind ==SID_UNIX_UUID_GROUP ) + gid =KGIDT_INIT_UUID (*(uuid_t *)id); +else
fs/smb/server/smbacl.c static int sid_to_id(struct mnt_idmap *idmap, · line 378
Quoted 10 lines
fs/smb/server/smbacl.c +10
-0+ gid =KGIDT_INIT_GUID (*(guid_t *)id); + gid =from_vfsgid (idmap, &init_user_ns,VFSGIDT_INIT (gid)); +if (!gid_valid (gid)) +return -EINVAL ; + fattr->cf_gid = gid; +return 0 ; + } +if (kind) +return -EINVAL ; + }
[Severity: High]
Can sid_to_id() in fs/smb/server/smbacl.c allow an SMB client to persist malformed UUIDs or nil GUIDs into inode ownership and POSIX ACLs?
When a client sends an SMB2_SET_INFO or SMB2_CREATE security descriptor containing an S-1-22-<kind>-w0-w1-w2-w3 SID (via set_info_sec() -> parse_sec_desc() / parse_dacl() -> sid_to_id()), sid_to_id() builds the kuid_t or kgid_t directly with KUIDT_INIT_UUID(), KUIDT_INIT_GUID(), KGIDT_INIT_UUID(), and KGIDT_INIT_GUID() instead of calling make_kuid_r() and make_kgid_r().
Unlike make_kuid_r() and make_kgid_r(), which validate the 16-byte payload via kid_r_valid() in kernel/uidgid_r.c:
kernel/uidgid_r.c:kid_r_valid() {
switch (id->type) {
...
case UID_R_UUID:
return (id->uuid[6] >> 4) == 4 && (id->uuid[8] & 0xc0) == 0x80;
case UID_R_GUID:
return memchr_inv(id->guid, 0, UID_R_SIZE);
}
return false;
}the uid_valid() and gid_valid() checks in include/linux/uidgid.h unconditionally return true for any KID_UUID or KID_GUID:
include/linux/uidgid.h:uid_valid() {
return !uid_is_legacy(uid) || __kuid_val(uid) != (uid_t) -1;
}As a result, a client can pass a non-v4/non-RFC-9562 UUID (such as S-1-22-3-0-0-0-0) or a nil GUID (S-1-22-5-0-0-0-0) and have it stored on
the inode or in POSIX ACL xattrs, causing subsequent userspace operations
that validate via kid_r_valid() (such as chown_r() or setxattr() on POSIX ACLs) to fail with -EINVAL.
Should sid_to_id() construct these IDs via make_kuid_r() and make_kgid_r() so that invalid UUID and GUID payloads are rejected?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=39
RFC PATCH v2 40/41 nfsd, nfs: carry UUID and GUID owners as their text form
In reply to Jan KoesterNFSv4 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.
--- 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
@@ -729,11 +729,44 @@ idmap_release_pipe(struct inode *inode)nfs_idmap_complete_pipe_upcall (data, -EPIPE ); } +/* +* UUID and GUID owners (Documentation/userspace-api/uid_r.rst) travel as +* the id's text form, which has no '@' and no number for idmapd. +*/ +static bool nfs_id_r_name (const char *name,size_t namelen,char *buf) +{ +if (namelen !=36 && !(namelen ==38 && name[0 ] =='{' )) +return false; +memcpy (buf, name, namelen); + buf[namelen] ='\0' ; +return true; +} + +static int nfs_id_r_to_string (const char *str,char *buf,size_t buflen) +{ +size_t len =strlen (str); + +if (len > buflen) +return -ERANGE ; +memcpy (buf, str, len); +return len; +} +int nfs_map_name_to_uid (const struct nfs_server *server,const char *name,size_t namelen,kuid_t *uid) {struct idmap *idmap = server->nfs_client->cl_idmap;__u32 id =-1 ;int ret =0 ; +char idbuf[KID_STR_LEN ]; + +if (nfs_id_r_name (name, namelen, idbuf)) { +kuid_t k =make_kuid_str (idmap_userns (idmap), idbuf); + +if (uid_valid (k) && !uid_is_legacy (k)) { + *uid = k; +return 0 ; + } + }if (!nfs_map_string_to_numeric (name, namelen, &id)) ret =nfs_idmap_lookup_id (name, namelen,"uid" , &id, idmap);
@@ -751,6 +784,16 @@ int nfs_map_group_to_gid(const struct nfs_server *server, const char *name, sizestruct idmap *idmap = server->nfs_client->cl_idmap;__u32 id =-1 ;int ret =0 ; +char idbuf[KID_STR_LEN ]; + +if (nfs_id_r_name (name, namelen, idbuf)) { +kgid_t k =make_kgid_str (idmap_userns (idmap), idbuf); + +if (gid_valid (k) && !gid_is_legacy (k)) { + *gid = k; +return 0 ; + } + }if (!nfs_map_string_to_numeric (name, namelen, &id)) ret =nfs_idmap_lookup_id (name, namelen,"gid" , &id, idmap);
@@ -769,6 +812,11 @@ int nfs_map_uid_to_name(const struct nfs_server *server, kuid_t uid, char *buf,int ret = -EINVAL ;__u32 id; +if (!uid_is_legacy (uid) &&kuid_has_mapping (idmap_userns (idmap), uid)) { +char str[KID_STR_LEN ]; + +return nfs_id_r_to_string (kuid_str (uid, str), buf, buflen); + } id =from_kuid_munged (idmap_userns (idmap), uid);if (!(server->caps &NFS_CAP_UIDGID_NOMAP )) ret =nfs_idmap_lookup_name (id,"user" , buf, buflen, idmap);
@@ -783,6 +831,11 @@ int nfs_map_gid_to_group(const struct nfs_server *server, kgid_t gid, char *buf,int ret = -EINVAL ;__u32 id; +if (!gid_is_legacy (gid) &&kgid_has_mapping (idmap_userns (idmap), gid)) { +char str[KID_STR_LEN ]; + +return nfs_id_r_to_string (kgid_str (gid, str), buf, buflen); + } id =from_kgid_munged (idmap_userns (idmap), gid);if (!(server->caps &NFS_CAP_UIDGID_NOMAP )) ret =nfs_idmap_lookup_name (id,"group" , buf, buflen, idmap);
fs/nfs/super.c +2 -0
@@ -1100,6 +1100,8 @@ static void nfs_fill_super(struct super_block *sb, struct nfs_fs_context *ctx)break ;case 4 : sb->s_iflags |=SB_I_NOUMASK ; +/* owners are strings: UUIDs and GUIDs in their text form */ + sb->s_iflags |=SB_I_UID_R ; sb->s_time_gran =1 ; sb->s_time_min =S64_MIN ; sb->s_time_max =S64_MAX ;
fs/nfsd/nfs4idmap.c +66 -2
97 lines not on this page · raw message
Signature · 1 line
2.56.0
Chuck Lever
maintainerRe: [RFC PATCH v2 40/41] nfsd, nfs: carry UUID and GUID owners as their text form
Quoted 4 lines · Jan Koester
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.
A bare UUID in an owner, owner_group, or ACE 'who' string is a new owner-string syntax for NFSv4, one that only Linux would recognize. Thus it isn't interoperable with other NFSv4 stacks as proposed here.
RFC 8881 Section 5.9 says a string without an '@' that is not a decimal number means no translation was available and the receiver "should not use that string as a basis for translation into its own internal format." RFC 8000 Section 6.1 forbids bare numeric ids in multi-domain deployments because they collide; the same applies to bare UUIDs, and more so to GUIDs.
If you are serious about pursuing this, you'll have to start by raising the proposed wire format on [email protected] before the Linux kernel's NFS stack commits to it.
With nfs4_disable_idmapping and AUTH_SYS, numeric_name_to_id() and encode_ascii_id() handle decimal ids in the kernel because there is nothing to look up. Recognizing the text form in that branch only would be the natural analogue once the format is agreed. Everything else should go through the idmapper: extend the nametoid/idtoname channels and the client keyring upcall to carry a 128-bit id, and let rpc.idmapd and nfsidmap decide which strings map to which ids. As written, the UUID check runs before idmapd for every name and auth flavor, bypassing the cache and any site policy.
So my general preference for NFSv4 would be to pass the new format up to the user space idmapper instead of handling these in-kernel with no opportunity to apply local policy.
Signature · 1 line
Chuck Lever (Come to NFS bake-a-thon! https://nfsv4bat.org)
Re: [RFC PATCH v2 40/41] nfsd, nfs: carry UUID and GUID owners as their text form
Quoted 19 lines · Chuck Lever
Quoted 4 lines · Jan Koester
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.
A bare UUID in an owner,
owner_group, or ACE 'who' string is a new owner-string syntax for NFSv4, one that only Linux would recognize. Thus it isn't interoperable with other NFSv4 stacks as proposed here.RFC 8881 Section 5.9 says a string without an '@' that is not a decimal number means no translation was available and the receiver "should not use that string as a basis for translation into its own internal format." RFC 8000 Section 6.1 forbids bare numeric ids in multi-domain deployments because they collide; the same applies to bare UUIDs, and more so to GUIDs.
Quoted 3 lines
If you are serious about pursuing this, you'll have to start by raising the proposed wire format on [email protected] before the Linux kernel's NFS stack commits to it.
I recall rumors of MS wanting to stick Windows SID in text form into the NFSv4 protocol.
THIS proposal is even worse, in every imaginable way:
Stuff an unreadable 128bit blob everywhere. I am sure people having to debug that in the kernel will LOVE the idea (compare blob a with blob b as human,YAY!), and admins facing the 128bit hexdump will send marriage proposals to the author, for making their lives even more heartless and miserable.
NAK, -1, for the whole patch series.
Signature · 2 lines
Internationalization&localization dev / 大阪大学 Takeshi Nishimura <[email protected]>
[email protected]
AI reviewRe: [RFC PATCH v2 40/41] nfsd, nfs: carry UUID and GUID owners as their text form
In reply to Jan KoesterThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] nfsd: unmapped -EOVERFLOW in nfserrno() on UUID/GUID setattr and ACLs - [High] nfs: silent…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] nfsd: unmapped -EOVERFLOW in nfserrno() on UUID/GUID setattr and ACLs
- [High] nfs: silent overflowuid munging on UUID chown when idmap user_ns is non-init
- [Medium] nfs: rejected UUID/GUID chown clears NFS_CAP_UIDGID_NOMAP for entire mount --
commit 651e121e99cc1fc974fd455542b8ff4a2ecaa7ac
Author: Jan Koester <[email protected]>
nfsd, nfs: carry UUID and GUID owners as their text form
This commit encodes and decodes non-legacy UUID and GUID user and group IDs in their text form for NFSv4 owners and ACL principals on both the client and server. It also sets SB_I_UID_R on NFSv4 client superblocks so userspace can set UUID and GUID owners via chown_r().
Quoted 4 lines
fs/nfs/nfs4idmap.c +0
-0
[ ... ]
Quoted 14 lines
fs/nfs/nfs4idmap.c +5
-0@@ -769,6 +812,11 @@ int nfs_map_uid_to_name(const struct nfs_server *server, kuid_t uid, char *buf,int ret = -EINVAL ;__u32 id; +if (!uid_is_legacy (uid) &&kuid_has_mapping (idmap_userns (idmap), uid)) { +char str[KID_STR_LEN ]; + +return nfs_id_r_to_string (kuid_str (uid, str), buf, buflen); + } id =from_kuid_munged (idmap_userns (idmap), uid);if (!(server->caps &NFS_CAP_UIDGID_NOMAP )) ret =nfs_idmap_lookup_name (id,"user" , buf, buflen, idmap);@@ -783,6 +831,11 @@ int nfs_map_gid_to_group(const struct nfs_server *server, kgid_t gid, char *buf,int ret = -EINVAL ;
fs/nfs/nfs4idmap.c int nfs_map_gid_to_group(const struct nfs_server *server, kgid_t gid, char *buf, · line 841
Quoted 10 lines
fs/nfs/nfs4idmap.c +5
-0__u32 id; +if (!gid_is_legacy (gid) &&kgid_has_mapping (idmap_userns (idmap), gid)) { +char str[KID_STR_LEN ]; + +return nfs_id_r_to_string (kgid_str (gid, str), buf, buflen); + } id =from_kgid_munged (idmap_userns (idmap), gid);if (!(server->caps &NFS_CAP_UIDGID_NOMAP )) ret =nfs_idmap_lookup_name (id,"group" , buf, buflen, idmap);
[Severity: High]
What happens here when an NFSv4 superblock has SB_I_UID_R set by nfs_fill_super(), but idmap_userns(idmap) is not init_user_ns?
Because nfs4_fs_type sets FS_USERNS_DELEGATABLE in fs/nfs/fs_context.c, an nfs4 context created via fsopen() in a non-initial user namespace sets idmap->user_ns to that namespace in nfs_idmap_new() (and nfs_match_client() in fs/nfs/client.c can also share that cl_idmap with a subsequent mount in init_user_ns).
When a process in init_user_ns calls chown_r() with a UUID or GUID on that mount, notify_change() in fs/attr.c checks vfsuid_has_fsmapping() (where from_vfsuid() in fs/mnt_idmapping.c returns AS_KUIDT(vfsuid) immediately for nop_mnt_idmap without checking fs_userns) and sb_can_own_kuid(), then calls nfs_setattr() -> nfs4_proc_setattr() -> encode_attrs().
In nfs_map_uid_to_name() and nfs_map_gid_to_group(), kuid_has_mapping() and kgid_has_mapping() return false for non-initial user namespaces, so execution falls through to from_kuid_munged() and from_kgid_munged(), silently sending overflowuid or overflowgid in the SETATTR RPC instead of the requested UUID/GUID.
If overflowuid or overflowgid is not mapped in idmap->user_ns, decode_attr_owner() and decode_attr_group() in fs/nfs/nfs4xdr.c also fail to map the post-op GETATTR owner, so nfs_setattr_update_inode() in fs/nfs/inode.c caches the requested UUID/GUID in inode->i_uid or inode->i_gid while the file on the server is owned by overflowuid or overflowgid:
fs/nfs/inode.c:nfs_setattr_update_inode() {
...
if ((attr->ia_valid & ATTR_UID) != 0)
inode->i_uid = attr->ia_uid;
if ((attr->ia_valid & ATTR_GID) != 0)
inode->i_gid = attr->ia_gid;
...
}Should nfs_fill_super() only set SB_I_UID_R when idmap_userns(idmap) is init_user_ns, or should nfs_setattr() and nfs_map_uid_to_name() reject unmapped non-legacy IDs rather than munging them to overflowuid?
fs/nfs/super.c static void nfs_fill_super(struct super_block *sb, struct nfs_fs_context *ctx) · line 1107
Quoted 13 lines
fs/nfs/super.c +2
-0@@ -1100,6 +1100,8 @@ static void nfs_fill_super(struct super_block *sb, struct nfs_fs_context *ctx)break ;case 4 : sb->s_iflags |=SB_I_NOUMASK ; +/* owners are strings: UUIDs and GUIDs in their text form */ + sb->s_iflags |=SB_I_UID_R ; sb->s_time_gran =1 ; sb->s_time_min =S64_MIN ; sb->s_time_max =S64_MAX ;
[Severity: Medium]
Can setting SB_I_UID_R unconditionally on all NFSv4 mounts cause a rejected UUID or GUID chown_r() to disable numeric UID/GID support for the entire mount?
When a user calls chown_r() with a UUID or GUID on a sec=sys mount where NFS_CAP_UIDGID_NOMAP is set, notify_change() delegates permission checks to the server and calls nfs_setattr() -> nfs4_proc_setattr() -> nfs4_do_setattr().
During XDR encoding, nfs_map_uid_to_name() and nfs_map_gid_to_group() encode the UUID or GUID as its text string even when NFS_CAP_UIDGID_NOMAP is set. If the server does not support UUID/GUID owners and returns NFS4ERR_BADOWNER (which nfsd4_decode_fattr4() in fs/nfsd/nfs4xdr.c returns during XDR decode before nfsd4_setattr() checks file ownership or CAP_CHOWN), nfs4_do_setattr() passes -NFS4ERR_BADOWNER to nfs4_do_handle_exception() in fs/nfs/nfs4proc.c:
case -NFS4ERR_BADOWNER:
/* The following works around a Linux server bug! */
case -NFS4ERR_BADNAME:
if (server->caps & NFS_CAP_UIDGID_NOMAP) {
server->caps &= ~NFS_CAP_UIDGID_NOMAP;
exception->retry = 1;This clears NFS_CAP_UIDGID_NOMAP permanently on server->caps for the mount and retries with the identical UUID/GUID string, forcing all subsequent classic UID/GID setattr calls through idmapd (similar to the regression fixed for ACLs in commit f8849e206ef52b).
Should nfs4_do_setattr() avoid clearing NFS_CAP_UIDGID_NOMAP when the setattr request carried a non-legacy kuid_t or kgid_t?
Quoted 4 lines
fs/nfsd/nfs4idmap.c +0
-0
[ ... ]
Quoted 24 lines
fs/nfsd/nfs4idmap.c +13
-0@@ -672,6 +699,16 @@ __be32 nfsd_map_name_to_uid(struct svc_rqst *rqstp, const char *name,if (name ==NULL || namelen ==0 )return nfserr_inval; + { +char buf[KID_STR_LEN ]; + +if (id_r_name (name, namelen, buf)) { + *uid =make_kuid_str (nfsd_user_namespace (rqstp), buf); +if (uid_valid (*uid) && !uid_is_legacy (*uid)) +return nfs_ok; + } + } + status =do_name_to_id (rqstp,IDMAP_TYPE_USER , name, namelen, &id);if (status)return status;@@ -709,6 +746,16 @@ __be32 nfsd_map_name_to_gid(struct svc_rqst *rqstp, const char *name,if (name ==NULL || namelen ==0 )return nfserr_inval; + { +char buf[KID_STR_LEN ]; +
fs/nfsd/nfs4idmap.c __be32 nfsd_map_name_to_gid(struct svc_rqst *rqstp, const char *name, · line 761
Quoted 10 lines
fs/nfsd/nfs4idmap.c +7
-0+if (id_r_name (name, namelen, buf)) { + *gid =make_kgid_str (nfsd_user_namespace (rqstp), buf); +if (gid_valid (*gid) && !gid_is_legacy (*gid)) +return nfs_ok; + } + } + status =do_name_to_id (rqstp,IDMAP_TYPE_GROUP , name, namelen, &id);if (status)return status;
[Severity: High]
Could accepting UUID and GUID strings here trigger a kernel warning in nfserrno() when the exported filesystem does not support SB_I_UID_R?
nfsd_map_name_to_uid() and nfsd_map_name_to_gid() decode 36-byte UUID and 38-byte GUID strings into non-legacy kuid_t and kgid_t values in nfsd4_decode_fattr4(), nfsd4_decode_nfsace4(), and nfsd4_decode_posixace4() before the target export's superblock is checked.
When nfsd4_setattr(), nfsd4_create(), or do_open_lookup() (via nfsd_create_setattr()) then calls nfsd_setattr() in fs/nfsd/vfs.c on an exported filesystem without SB_I_UID_R (or on ext4 when ext4_make_room_for_id_r() cannot expand an existing inode), notify_change() in fs/attr.c:
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;
and set_posix_acl() in fs/posix_acl.c:
if (posix_acl_has_id_r(acl) && !(inode->i_sb->s_iflags & SB_I_UID_R)) return -EOVERFLOW;
return -EOVERFLOW.
nfsd_setattr() and nfsd4_setattr() pass that error to nfserrno() in fs/nfsd/vfs.c:
for (i = 0; i < ARRAY_SIZE(nfs_errtbl); i++) {
if (nfs_errtbl[i].syserr == errno)
return nfs_errtbl[i].nfserr;
}
WARN_ONCE(1, "nfsd: non-standard errno: %d\n", errno);
return nfserr_io;Because nfs_errtbl[] has no entry for EOVERFLOW, this triggers WARN_ONCE() and returns nfserr_io instead of nfserr_badowner (and for OPEN(CREATE) or CREATE with initial UUID/GUID attributes, leaves the newly created file or directory on disk after nfsd_create_setattr() fails).
Should nfsd check whether the export's superblock supports SB_I_UID_R (and map EOVERFLOW to nfserr_badowner in nfsd_setattr() / nfserrno())?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=40
RFC PATCH v2 41/41 Documentation: uid_r: describe SMB and NFSv4
In reply to Jan Koesterksmbd'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.
--- Documentation/userspace-api/uid_r.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
Documentation/userspace-api/uid_r.rst +17 -0
@@ -159,11 +159,28 @@ RPCSEC_GSS upcalls user as ``__kernel_uid_r_t``, then the usual fields. The binary (v0) upcall can't carry such users and fails with ``EACCES``. +SMB (ksmbd) + The login response extension (``struct ksmbd_login_response_ext``) + carries the user's ids as ``__kernel_uid_r_t`` with + ``KSMBD_LOGIN_EXT_ID_R`` and the supplementary groups as + ``__kernel_gid_r_t`` with ``KSMBD_LOGIN_EXT_GROUPS_R``. Such users and + groups appear in security descriptors as + ``S-1-22-<kind>-w0-w1-w2-w3``: kind 3 and 4 for a UUID user and group, + 5 and 6 for a GUID user and group, w0 to w3 the 16 bytes of the id as + big endian words. + +NFSv4 + Owners and ACL principals that are UUIDs or GUIDs travel as their text + form, on the server and the client, with or without idmapd. + Limitations =========== - Quotas don't account UUID and GUID owners; quota files hold 32 bit ids. - RPCSEC_GSS needs a gssd that knows ``uid_r=`` for UUID and GUID users. +- NFS with AUTH_SYS sends a 32 bit uid: a UUID or GUID user on a client + reaches the server as the overflow id. +- The SMB3 POSIX extensions' fixed size SID fields show the overflow id. - UUID and GUID users can't create unprivileged ublk devices. - Audit filter rules, SafeSetID policies and IMA policy rules name classic ids only.
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC PATCH v2 41/41] Documentation: uid_r: describe SMB and NFSv4
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
ksmbd's login extension and SIDs for UUID and GUID users, NFSv4 owner strings, and what
AUTH_SYSand the SMB3 POSIX extensions can't carry.Assisted-by Claude:claude-opus-5-5Signed-off-by Jan Koester <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=41
Hi,
i have already submitted but not all patches arrives now i use a other mailbox sorry.
best regards
Jan Koester
Am 21.10.26 um 05:15 schrieb Jan Koester:
Quoted 317 lines
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_tandkgid_tbecome 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 onkuid_tbeing a u32:sk_uidis now read through a seqcount, andaf_unix, netlink and Bluetooth keep only classic ids inskb->cb. Patch 9 changes the type.- UUIDs and GUIDs exist only in the initial user namespace. They are not part of any
uid_maporgid_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_rin 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 theRPCSEC_GSSupcall 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_SYSsends 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 withoutuid_r): 88/88 pass, on a kernel withUSER_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 selftests and the boot test suite ran on the same series on top of v7.2.9 and v7.2.11. On v7.3-rc7, the series is built forx86_64(bzImage and modules, withUSER_NS, audit, ecryptfs, fscrypt, quota, ublk, NFS, Bluetooth and the LSMs enabled) and boots in QEMU, where an integration test with a full user space passes 24/24: ssh sessions with a pty as UUID users, UUID owners on tmpfs and overlayfs, SMB logins of UUID users through ksmbd with S-1-22-3-... owner SIDs, and NFSv4 showing and setting UUID owners. ext4uid_rwas not part of it.
- 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 inkuid_tacceptable, or would you rather see the 128-bit id kept beside a u32kuid_t?
- The new calls copy the classic get/set*id() andchown()families one by one (20 entries). A singlesetid_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?Changes in v2:
- No code changes. v1 reached the lists only up to patch 11, the mail provider throttled the rest; this is the complete series, now sent from [email protected] (author and Signed-off-by changed to it).
- Hunk offsets refreshed against v7.3-rc7, testing section updated.
- v1: https://lore.kernel.org/r/[email protected]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: moveuuid_tandguid_tinto <linux/uuid_types.h>
uapi: add <linux/uidgid_r.h> for 128 bit capable user and group ids
uidgid: adduid_is_legacy()andgid_is_legacy()
net: sock: readsk_uidthrough a seqcount
af_unix: keep sender ids inskb->cbonly when they are classic ids
netlink: keep classic sender ids inskb->cb
Bluetooth: keep classic sender ids inskb->cb
smb: client: use__kuid_val()for the unix SIDs of the caller
uidgid: letkuid_tandkgid_thold 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 bykuid_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: addgetgroups_r()andsetgroups_r()
fs: addchown_r(),lchown_r(),fchown_r()andfchownat_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: addSO_PEERCRED_R,SO_PEERGROUPS_RandSCM_CREDENTIALS_R
signal: report the sender's UUID or GUID uid insi_uid_r
ipc: addIPC_STAT_RandIPC_SET_R
ext4: add theuid_rfeature for UUID and GUID owners
ext4: letuid_rbe turned on while the filesystem is mounted
posix_acl: support UUID and GUID entries
ext4: store ACLs with UUID and GUID entries onuid_rfilesystems
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 NFSv4Documentation/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.cbase-commit:
24a19b953e2a3d0ea5a8c4951a0ab8f32720c907
Adding dreaded Windows SID-style, or. Repeating history, the bad chapters. UUID/GUIDRe: [RFC PATCH v2 00/41] UUID and GUID user and group ids (*_r system calls)
In reply to Jan KoesterQuoted 7 lines · Jan Koester
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.
Are you Linnux guys aware that this is just a variation of the *DREADED* Windows SID that this patch tries to introduce, just with a new name?
Maybe, before doing this, read about Windows SIDs, and why they are so hated.
Secondly, the whole idea of doing 128bit hashes as UUID is not new, IBM DFS had it, and had many iterations of security issues via hash collision exploits. 40 years later all this horror comes back. Does history really have to repeat itself?
Lionel
Quoted 6 lines · Jan Koester
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.
I can't see this being acceptable for a variety of reasons, including but not limited to performance and configuration complexity. It's a general solution for a special case or two, and the impact is significant.
If you're willing to use a UUID and/or GUID in addition to a UID/GID instead of in place of it you could consider implementing this as an LSM. There are a number of issues you'd still run into there (e.g. UDS attributes) and I can't say if the resulting behavior would be what you're looking for. I also can't say that the security community would necessarily be any happier with it than the general population, but if you really want this it might be worth a shot.
Theodore Tso
maintainerQuoted 4 lines · Casey Schaufler
I can't see this being acceptable for a variety of reasons, including but not limited to performance and configuration complexity. It's a general solution for a special case or two, and the impact is significant.
Yeah. I agree it's a non-starter. For one thing, it requires replacing every single system call which uses a 32-bit uid or gid --- either as an input parameter, a return value, or in a structure, such as, "struct stat". It also requires making breaking changes into on-disk file formats that use a uid --- for example, /etc/passwd, /etc/group, utmp/wtmp, etc. If it will also break compatibility with remote file systems that don't use a Windows SID --- e.g., nfsv3, AFS, etc. And that's before we even get to breaking things like tar files, etc.
I'll also note that customers that are most likely to need to use the abominationm of Windows SIDs are also those that are likely to be using proprietary third party binaries --- you know, silly things like SAP R/3, Oracle Enterprise Database, db2, etc. And if you use Windows SIDs as user id's in your /etc/passwd, then binaries that are still using the traditional system calls will get the overflow 32-bit number --- and break.
I suspect it will be much more useful to simply add a supplementary user id and group id which is only used by those file systems that *care* about Windows SID's, and assume that everything else will use true, traditional Unix uids and gids. I also suspect that we should be stashing the supplementary id's as extended attributes for the file systems. That way we can much more quickly and easily add support to ext4, xfs, btrfs, etc., as file systems that can be used as backing stores for NFSv4 and CIFS for those (few) environments that care about Windows SID's.
- Ted
P.S., From my perspective, Windows SID's are actually the legacy ID's. especially as more and more people flee Microslop's Windows 11 and moving to Linux and MacOS. :-)
v2 cover uid_r: convert tun, ivpu and tee
In reply to Jan KoesterHi,
Building the UUID/GUID id RFC (uid_r v2, <[email protected]>) with a distribution config instead of the one I had tested with turned up three users of kuid_t/kgid_t it doesn't build with: kuid_t is a tagged union now and has no .val, and it no longer fits READ_ONCE()/WRITE_ONCE().
1/3 tun: TUNSETOWNER/TUNSETGROUP write the owner and group under RTNL,
tun_fill_info() may read them without it. Mark that read as data_race() instead of READ_ONCE(). Only classic ids from make_kuid()/make_kgid() are ever stored there.
2/3 accel/ivpu: the per-user context limits are keyed by
__kuid_val(). UUID and GUID users share the (uid_t)-1 bucket, which only makes the limit stricter for them.
3/3 tee: the TEE_IOCTL_LOGIN_USER client UUID is derived from the
classic uid. With __kuid_val() alone every UUID or GUID user would get the same one and could act as any other such user towards the TEE, so those logins are refused with -EPERM, like ublk refuses unprivileged devices to them in the series.
These belong into the series before the patch that lets kuid_t and kgid_t hold a UUID or a GUID and will be folded in there in v3; I'm sending them now so that the reviewers of these drivers see what uid_r means for them.
Jan Koester (3):
tun: read the owner and group without READ_ONCE() accel/ivpu: key user limits by __kuid_val()
tee: refuse user logins of UUID and GUID users
drivers/accel/ivpu/ivpu_drv.c | 2 +- drivers/net/tun.c | 8 ++++---- drivers/tee/tee_core.c | 13 +++++++++++-- 3 files changed, 16 insertions(+), 7 deletions(-)
Signature · 1 line
2.53.0
Re: [RFC PATCH v2 0/3] uid_r: convert tun, ivpu and tee
Quoted 33 lines · Jan Koester
Hi,
Building the UUID/GUID id RFC (
uid_rv2, <[email protected]>) with a distribution config instead of the one I had tested with turned up three users of kuid_t/kgid_t it doesn't build with:kuid_tis a tagged union now and has no .val, and it no longer fits READ_ONCE()/WRITE_ONCE().1/3 tun: TUNSETOWNER/TUNSETGROUP write the owner and group under RTNL,
tun_fill_info()may read them without it. Mark that read asdata_race()instead ofREAD_ONCE(). Only classic ids from make_kuid()/make_kgid() are ever stored there.2/3 accel/ivpu: the per-user context limits are keyed by
__kuid_val(). UUID and GUID users share the (uid_t)-1 bucket, which only makes the limit stricter for them.3/3 tee: the
TEE_IOCTL_LOGIN_USERclient UUID is derived from the
classic uid. With__kuid_val()alone every UUID or GUID user would get the same one and could act as any other such user towards the TEE, so those logins are refused with-EPERM, like ublk refuses unprivileged devices to them in the series.These belong into the series before the patch that lets
kuid_tandkgid_thold a UUID or a GUID and will be folded in there in v3; I'm sending them now so that the reviewers of these drivers see whatuid_rmeans for them.Jan Koester (3):
tun: read the owner and group withoutREAD_ONCE()accel/ivpu: key user limits by__kuid_val()
tee: refuse user logins of UUID and GUID users
Quoted 4 lines
drivers/accel/ivpu/ivpu_drv.c | 2 +- drivers/net/tun.c | 8 ++++---- drivers/tee/tee_core.c | 13 +++++++++++-- 3 files changed, 16 insertions(+), 7 deletions(-)
I only received this cover letter. Also do not see the patches on
https://lore.kernel.org/all
Christian Brauner
maintainerQuoted 2 lines · Jan Koester
-
kuid_tandkgid_tbecome a tagged union (legacy number, UUID, GUID) instead of a u32.
Oh boy, I'm not sure this is going to happen.
We are going to extend kuid_t to 64 bit for cells and isolated idmappings. But it stays a plain integer type though. Turning kuid_t and kgid_t into 20-byte tagged unions, adding a parallel *_r syscall family, a new POSIX ACL xattr format and new procfs fields seems very very unlikely.