From: Josef Bacik <josef@toxicpanda.com>
To: Christian Brauner <brauner@kernel.org>,
Paul Moore <paul@paul-moore.com>
Cc: Serge Hallyn <sergeh@kernel.org>,
linux-fsdevel@vger.kernel.org,
linux-security-module@vger.kernel.org,
Josef Bacik <josef@toxicpanda.com>
Subject: [PATCH 00/13] cred: gather the "same uid" checks between tasks in one place
Date: Sun, 18 Oct 2026 17:31:42 +0000 [thread overview]
Message-ID: <20261018-b4-cred-ids-v1-0-7bdf2db4ea9f@toxicpanda.com> (raw)
Hello,
We have a dozen places in the kernel that let one task mess with another
because they belong to the same user: kill(), SIGIO, the scheduler
syscalls, setpriority(), ioprio_set(), prlimit(), ptrace, moving a task
around in cgroup v1 and resctrl, and KEYCTL_SESSION_TO_PARENT. Every
one of them open codes a handful of uid_eq() calls on the two creds.
They come in six flavors that differ in which of the real, effective and
saved ids they look at, and in whether euid 0 gets a pass, and there is
nothing that tells you whether two of them differ on purpose or by
accident.
I tripped over this working on something else that needs to change what
"the same user" means. I kept finding another copy I had missed, and
for this kind of check a copy you missed is a hole. So this pulls all
of them into kernel/cred.c, side by side, with a table that says which
rule looks at what, and converts the callers one at a time.
Nothing is supposed to change. What each of these means by "the same
user" is ABI at this point, so every rule is kept exactly as it was,
warts and all, I have not tried to unify them. The capability checks
and the LSM hooks stay with the callers.
The one patch that isn't a straight substitution is the fcntl one.
F_SETOWN copies the uid and euid of the caller into the fown_struct, and
the helpers take creds, so it holds a reference on the cred instead, the
same way struct file does for the opener. That means the cred sticks
around until the owner is set again or the file goes away.
For testing, patch 2 is a KUnit test that holds each helper against the
expression it replaces, verbatim, over every combination of a few ids. I
also ran kill, setpriority, ioprio_set, sched_setaffinity,
sched_setscheduler, prlimit, a cgroup v1 move, SIGIO and PTRACE_SEIZE
for all 64 combinations of real, effective and saved uid of the two
tasks, on a kernel with and without the series under KASAN and lockdep.
All 576 results are the same on both, and they match what the table
says. The resctrl and usbdevfs (kill_pid_usb_asyncio) callers I have no
way to exercise, and the MIPS patch is compile tested only.
This is based on vfs.all only because that's what the other work sits
on. Thanks,
Josef
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
Josef Bacik (13):
cred: gather the rules for acting on a task by uid
cred: add KUnit tests for the id rules
signal: use cred_ids_allow_signal()
fcntl: use cred_ids_allow_sigio()
sched: use cred_ids_allow_sched()
MIPS: use cred_ids_allow_sched()
sys: use cred_ids_allow_sched() for setpriority()
sys: use cred_ids_allow_control() for prlimit()
block: use cred_ids_allow_ioprio()
cgroup/v1: use cred_ids_allow_move()
fs/resctrl: use cred_ids_allow_move()
ptrace: use cred_ids_allow_control()
keys: use cred_ids_allow_control()
Documentation/security/credentials.rst | 19 +++
MAINTAINERS | 1 +
arch/mips/kernel/mips-mt-fpaff.c | 3 +-
block/blk-ioc.c | 3 +-
fs/fcntl.c | 19 +--
fs/resctrl/rdtgroup.c | 4 +-
include/linux/cred.h | 20 +++
include/linux/fs.h | 4 +-
kernel/Makefile | 1 +
kernel/cgroup/cgroup-v1.c | 4 +-
kernel/cred.c | 160 ++++++++++++++++++++++++
kernel/cred_kunit.c | 218 +++++++++++++++++++++++++++++++++
kernel/ptrace.c | 16 +--
kernel/sched/syscalls.c | 3 +-
kernel/signal.c | 10 +-
kernel/sys.c | 10 +-
lib/Kconfig.debug | 13 ++
security/keys/keyctl.c | 7 +-
security/landlock/fs.h | 3 +-
19 files changed, 459 insertions(+), 59 deletions(-)
---
base-commit: ac311bf4f20e614d8e94cae4c62f075f2e5ef16c
change-id: 20261018-b4-cred-ids-eb01b2b38524
next reply other threads:[~2026-10-18 17:31 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-18 17:31 Josef Bacik [this message]
2026-10-18 17:31 ` [PATCH 01/13] cred: gather the rules for acting on a task by uid Josef Bacik
2026-10-18 17:35 ` sashiko-bot
2026-10-18 17:31 ` [PATCH 02/13] cred: add KUnit tests for the id rules Josef Bacik
2026-10-18 17:34 ` sashiko-bot
2026-10-18 17:31 ` [PATCH 03/13] signal: use cred_ids_allow_signal() Josef Bacik
2026-10-18 17:34 ` sashiko-bot
2026-10-18 17:31 ` [PATCH 04/13] fcntl: use cred_ids_allow_sigio() Josef Bacik
2026-10-18 17:37 ` sashiko-bot
2026-10-18 17:31 ` [PATCH 05/13] sched: use cred_ids_allow_sched() Josef Bacik
2026-10-18 17:34 ` sashiko-bot
2026-10-18 17:31 ` [PATCH 06/13] MIPS: " Josef Bacik
2026-10-18 17:34 ` sashiko-bot
2026-10-18 17:31 ` [PATCH 07/13] sys: use cred_ids_allow_sched() for setpriority() Josef Bacik
2026-10-18 17:34 ` sashiko-bot
2026-10-18 17:31 ` [PATCH 08/13] sys: use cred_ids_allow_control() for prlimit() Josef Bacik
2026-10-18 17:34 ` sashiko-bot
2026-10-18 17:31 ` [PATCH 09/13] block: use cred_ids_allow_ioprio() Josef Bacik
2026-10-18 17:34 ` sashiko-bot
2026-10-18 17:31 ` [PATCH 10/13] cgroup/v1: use cred_ids_allow_move() Josef Bacik
2026-10-18 17:34 ` sashiko-bot
2026-10-18 17:31 ` [PATCH 11/13] fs/resctrl: " Josef Bacik
2026-10-18 17:34 ` sashiko-bot
2026-10-18 17:31 ` [PATCH 12/13] ptrace: use cred_ids_allow_control() Josef Bacik
2026-10-18 17:34 ` sashiko-bot
2026-10-18 17:31 ` [PATCH 13/13] keys: " Josef Bacik
2026-10-18 17:34 ` sashiko-bot
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=20261018-b4-cred-ids-v1-0-7bdf2db4ea9f@toxicpanda.com \
--to=josef@toxicpanda.com \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=sergeh@kernel.org \
/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