Skip to content

Commit 9ceacb7

Browse files
committed
ptrace: slightly saner 'get_dumpable()' logic
jira VULN-185427 cve CVE-2026-46333 commit-author Linus Torvalds <torvalds@linux-foundation.org> commit 31e62c2 upstream-diff | Used RH_KABI_FILL_HOLE(unsigned user_dumpable:1) in task_struct to fix kabi check. The kabi check failes otherwise, not because the size of the struct changes (there is a payload of 15 unused bits), but because the checksum is different. RH_KABI_FILL_HOLE bypasses that. 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 f6c3842 commit 9ceacb7

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

include/linux/sched.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,10 @@ struct task_struct {
868868
RH_KABI_FILL_HOLE(unsigned sched_psi_wake_requeue:1)
869869
#endif
870870

871+
/* Save user-dumpable when mm goes away */
872+
RH_KABI_FILL_HOLE(unsigned user_dumpable:1)
873+
874+
871875
/* Force alignment to the next boundary: */
872876
unsigned :0;
873877

kernel/exit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ static void exit_mm(void)
494494
*/
495495
smp_mb__after_spinlock();
496496
local_irq_disable();
497+
current->user_dumpable = (get_dumpable(mm) == SUID_DUMP_USER);
497498
current->mm = NULL;
498499
membarrier_update_current_mm(NULL);
499500
enter_lazy_tlb(mm, current);

kernel/ptrace.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,24 @@ static int ptrace_has_cap(struct user_namespace *ns, unsigned int mode)
283283
return has_ns_capability(current, ns, CAP_SYS_PTRACE);
284284
}
285285

286+
static bool task_still_dumpable(struct task_struct *task, unsigned int mode)
287+
{
288+
struct mm_struct *mm = task->mm;
289+
if (mm) {
290+
if (get_dumpable(mm) == SUID_DUMP_USER)
291+
return true;
292+
return ptrace_has_cap(mm->user_ns, mode);
293+
}
294+
295+
if (task->user_dumpable)
296+
return true;
297+
return ptrace_has_cap(&init_user_ns, mode);
298+
}
299+
286300
/* Returns 0 on success, -errno on denial. */
287301
static int __ptrace_may_access(struct task_struct *task, unsigned int mode)
288302
{
289303
const struct cred *cred = current_cred(), *tcred;
290-
struct mm_struct *mm;
291304
kuid_t caller_uid;
292305
kgid_t caller_gid;
293306

@@ -348,11 +361,8 @@ static int __ptrace_may_access(struct task_struct *task, unsigned int mode)
348361
* Pairs with a write barrier in commit_creds().
349362
*/
350363
smp_rmb();
351-
mm = task->mm;
352-
if (mm &&
353-
((get_dumpable(mm) != SUID_DUMP_USER) &&
354-
!ptrace_has_cap(mm->user_ns, mode)))
355-
return -EPERM;
364+
if (!task_still_dumpable(task, mode))
365+
return -EPERM;
356366

357367
return security_ptrace_access_check(task, mode);
358368
}

0 commit comments

Comments
 (0)