From: sashiko-bot@kernel.org
To: "Jan Koester" <jan.koester@tuxist.de>,
"Christian Brauner" <brauner@kernel.org>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Serge E. Hallyn" <serge@hallyn.com>
Cc: "Jan Kara" <jack@suse.cz>, "Theodore Y. Ts'o" <tytso@mit.edu>,
"Paul Moore" <paul@paul-moore.com>,
"Arnd Bergmann" <arnd@arndb.de>,
linux-security-module@vger.kernel.org,
linux-ext4@vger.kernel.org, audit@vger.kernel.org,
keyrings@vger.kernel.org, "Chuck Lever" <cel@kernel.org>,
"Jeff Layton" <jlayton@kernel.org>,
"Anna Schumaker" <anna@kernel.org>
Subject: Re: [RFC PATCH v2 19/41] cred: add the *_r variants of the get/set*id() system calls
Date: Thu, 22 Oct 2026 03:17:43 +0000 [thread overview]
Message-ID: <sashiko-outbox-180920@kernel.org> (raw)
In-Reply-To: <86c66380f2654c560e747b9075edbddd610975ca.1792552161.git.jan.koester@tuxist.de>
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 <jan.koester@tuxist.de>
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.
> diff --git a/kernel/sys.c b/kernel/sys.c
> index 35b538ba843c7..fad55732345de 100644
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
[ ... ]
> @@ -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;
> +}
[ ... ]
> @@ -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;
> +}
[ ... ]
> +/*
> + * 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;
> + 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?
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1792552161.git.jan.koester@tuxist.de?part=19
next prev parent reply other threads:[~2026-10-22 3:17 UTC|newest]
Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 3:15 [RFC PATCH v2 00/41] UUID and GUID user and group ids (*_r system calls) Jan Koester
2026-10-21 3:15 ` [RFC PATCH v2 01/41] uuid: move uuid_t and guid_t into <linux/uuid_types.h> Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 02/41] uapi: add <linux/uidgid_r.h> for 128 bit capable user and group ids Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 03/41] uidgid: add uid_is_legacy() and gid_is_legacy() Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 04/41] net: sock: read sk_uid through a seqcount Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 05/41] af_unix: keep sender ids in skb->cb only when they are classic ids Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 06/41] netlink: keep classic sender ids in skb->cb Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 07/41] Bluetooth: " Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 08/41] smb: client: use __kuid_val() for the unix SIDs of the caller Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 09/41] uidgid: let kuid_t and kgid_t hold a UUID or a GUID Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 10/41] uidgid: convert between kernel ids and the ids of the *_r system calls Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 11/41] fscrypt: show the whole uid in the description of user key claims Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 12/41] keys: name per-user keyrings of UUID and GUID users by the whole uid Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 13/41] ublk: refuse unprivileged devices to UUID and GUID users Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 14/41] nfsd: don't hand out uid 0 for read layouts of UUID-owned files Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 15/41] SUNRPC: name UUID and GUID users to gssd as uid_r= Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 16/41] ecryptfs: hash daemons by kuid_hash() Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 17/41] quota: don't account UUID and GUID owners Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 18/41] fs: keep UUID and GUID owners off filesystems that can't store them Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 19/41] cred: add the *_r variants of the get/set*id() system calls Jan Koester
2026-10-22 3:17 ` sashiko-bot [this message]
2026-10-21 3:15 ` [RFC PATCH v2 20/41] groups: add getgroups_r() and setgroups_r() Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 21/41] fs: add chown_r(), lchown_r(), fchown_r() and fchownat_r() Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 22/41] arch: wire up the *_r uid and gid system calls Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 23/41] statx: report UUID and GUID owners Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 24/41] shmem, ramfs: allow " Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 25/41] uidgid: parse and print ids in their text form Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 26/41] proc: show UUID and GUID ids in status, accept them for loginuid Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 27/41] audit: log UUID and GUID ids in full Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 28/41] net: add SO_PEERCRED_R, SO_PEERGROUPS_R and SCM_CREDENTIALS_R Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 29/41] signal: report the sender's UUID or GUID uid in si_uid_r Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 30/41] ipc: add IPC_STAT_R and IPC_SET_R Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 31/41] ext4: add the uid_r feature for UUID and GUID owners Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 32/41] ext4: let uid_r be turned on while the filesystem is mounted Jan Koester
2026-10-22 3:17 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 33/41] posix_acl: support UUID and GUID entries Jan Koester
2026-10-22 3:18 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 34/41] ext4: store ACLs with UUID and GUID entries on uid_r filesystems Jan Koester
2026-10-22 3:18 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 35/41] Documentation: describe UUID and GUID user and group ids Jan Koester
2026-10-22 3:18 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 36/41] selftests: add tests for UUID and GUID ids Jan Koester
2026-10-22 3:18 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 37/41] ovl: allow UUID and GUID owners when the upper layer does Jan Koester
2026-10-22 3:18 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 38/41] devpts: allow UUID and GUID owners Jan Koester
2026-10-22 3:18 ` sashiko-bot
2026-10-21 3:15 ` [RFC PATCH v2 39/41] ksmbd: log in UUID and GUID users and map them to SIDs Jan Koester
2026-10-22 3:18 ` sashiko-bot
2026-10-21 3:16 ` [RFC PATCH v2 40/41] nfsd, nfs: carry UUID and GUID owners as their text form Jan Koester
2026-10-21 17:35 ` Chuck Lever
2026-10-22 2:52 ` Takeshi Nishimura
2026-10-22 3:18 ` sashiko-bot
2026-10-21 3:16 ` [RFC PATCH v2 41/41] Documentation: uid_r: describe SMB and NFSv4 Jan Koester
2026-10-22 3:18 ` sashiko-bot
2026-10-21 3:20 ` [RFC PATCH v2 00/41] UUID and GUID user and group ids (*_r system calls) jan Koester
2026-10-21 14:26 ` Adding dreaded Windows SID-style, or. Repeating history, the bad chapters. UUID/GUIDRe: " Lionel Cons
2026-10-22 17:00 ` Casey Schaufler
2026-10-22 18:26 ` Theodore Tso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-180920@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=anna@kernel.org \
--cc=arnd@arndb.de \
--cc=audit@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=cel@kernel.org \
--cc=jack@suse.cz \
--cc=jan.koester@tuxist.de \
--cc=jlayton@kernel.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=serge@hallyn.com \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox