Skip to content

Commit b91ef7f

Browse files
committed
ptrace: slightly saner 'get_dumpable()' logic
jira VULN-185426 cve CVE-2026-46333 commit-author Linus Torvalds <torvalds@linux-foundation.org> commit 31e62c2 upstream-diff | In order to avoid kabi breakage, user_dumpable is added in rh_reserved area in task_struct. The 'dumpability' of a task is fundamentally about the memory image of the task - the concept comes from whether it can core dump or not - and makes no sense when you don't have an associated mm. And almost all users do in fact use it only for the case where the task has a mm pointer. But we have one odd special case: ptrace_may_access() uses 'dumpable' to check various other things entirely independently of the MM (typically explicitly using flags like PTRACE_MODE_READ_FSCREDS). Including for threads that no longer have a VM (and maybe never did, like most kernel threads). It's not what this flag was designed for, but it is what it is. The ptrace code does check that the uid/gid matches, so you do have to be uid-0 to see kernel thread details, but this means that the traditional "drop capabilities" model doesn't make any difference for this all. Make it all make a *bit* more sense by saying that if you don't have a MM pointer, we'll use a cached "last dumpability" flag if the thread ever had a MM (it will be zero for kernel threads since it is never set), and require a proper CAP_SYS_PTRACE capability to override. Reported-by: Qualys Security Advisory <qsa@qualys.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Kees Cook <kees@kernel.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> (cherry picked from commit 31e62c2) Signed-off-by: Roxana Nicolescu <rnicolescu@ciq.com>
1 parent 70b8745 commit b91ef7f

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

include/linux/sched.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,8 @@ struct task_struct {
15371537
*/
15381538
RH_KABI_REPLACE_SPLIT(long rh_reserved[64],
15391539
int rh_kabi_dummy, /* 0 */ /* Use this one first */
1540+
/* Save user-dumpable when mm goes away */
1541+
unsigned user_dumpable:1,
15401542
)
15411543

15421544
/*

kernel/exit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ static void exit_mm(void)
499499
*/
500500
smp_mb__after_spinlock();
501501
local_irq_disable();
502+
current->user_dumpable = (get_dumpable(mm) == SUID_DUMP_USER);
502503
current->mm = NULL;
503504
membarrier_update_current_mm(NULL);
504505
enter_lazy_tlb(mm, current);

kernel/ptrace.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,24 @@ static bool ptrace_has_cap(struct user_namespace *ns, unsigned int mode)
288288
return ns_capable(ns, CAP_SYS_PTRACE);
289289
}
290290

291+
static bool task_still_dumpable(struct task_struct *task, unsigned int mode)
292+
{
293+
struct mm_struct *mm = task->mm;
294+
if (mm) {
295+
if (get_dumpable(mm) == SUID_DUMP_USER)
296+
return true;
297+
return ptrace_has_cap(mm->user_ns, mode);
298+
}
299+
300+
if (task->user_dumpable)
301+
return true;
302+
return ptrace_has_cap(&init_user_ns, mode);
303+
}
304+
291305
/* Returns 0 on success, -errno on denial. */
292306
static int __ptrace_may_access(struct task_struct *task, unsigned int mode)
293307
{
294308
const struct cred *cred = current_cred(), *tcred;
295-
struct mm_struct *mm;
296309
kuid_t caller_uid;
297310
kgid_t caller_gid;
298311

@@ -353,11 +366,8 @@ static int __ptrace_may_access(struct task_struct *task, unsigned int mode)
353366
* Pairs with a write barrier in commit_creds().
354367
*/
355368
smp_rmb();
356-
mm = task->mm;
357-
if (mm &&
358-
((get_dumpable(mm) != SUID_DUMP_USER) &&
359-
!ptrace_has_cap(mm->user_ns, mode)))
360-
return -EPERM;
369+
if (!task_still_dumpable(task, mode))
370+
return -EPERM;
361371

362372
return security_ptrace_access_check(task, mode);
363373
}

0 commit comments

Comments
 (0)