Skip to content

Commit b465bc7

Browse files
committed
ptrace: slightly saner 'get_dumpable()' logic
jira VULN-185424 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 21735e7 commit b465bc7

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
@@ -1563,6 +1563,8 @@ struct task_struct {
15631563
*/
15641564
RH_KABI_REPLACE_SPLIT(long rh_reserved[64],
15651565
int rh_kabi_dummy, /* 0 */ /* Use this one first */
1566+
/* Save user-dumpable when mm goes away */
1567+
unsigned user_dumpable:1,
15661568
)
15671569

15681570
/*

kernel/exit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ static void exit_mm(void)
534534
*/
535535
smp_mb__after_spinlock();
536536
local_irq_disable();
537+
current->user_dumpable = (get_dumpable(mm) == SUID_DUMP_USER);
537538
current->mm = NULL;
538539
membarrier_update_current_mm(NULL);
539540
enter_lazy_tlb(mm, current);

kernel/ptrace.c

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

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

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

356366
return security_ptrace_access_check(task, mode);
357367
}

0 commit comments

Comments
 (0)