Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,8 @@ struct task_struct {
*/
RH_KABI_REPLACE_SPLIT(long rh_reserved[64],
int rh_kabi_dummy, /* 0 */ /* Use this one first */
/* Save user-dumpable when mm goes away */
unsigned user_dumpable:1,
)

/*
Expand Down
1 change: 1 addition & 0 deletions kernel/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ static void exit_mm(void)
*/
smp_mb__after_spinlock();
local_irq_disable();
current->user_dumpable = (get_dumpable(mm) == SUID_DUMP_USER);
current->mm = NULL;
membarrier_update_current_mm(NULL);
enter_lazy_tlb(mm, current);
Expand Down
22 changes: 16 additions & 6 deletions kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,24 @@ static bool ptrace_has_cap(struct user_namespace *ns, unsigned int mode)
return ns_capable(ns, CAP_SYS_PTRACE);
}

static bool task_still_dumpable(struct task_struct *task, unsigned int mode)
{
struct mm_struct *mm = task->mm;
if (mm) {
if (get_dumpable(mm) == SUID_DUMP_USER)
return true;
return ptrace_has_cap(mm->user_ns, mode);
}

if (task->user_dumpable)
return true;
return ptrace_has_cap(&init_user_ns, mode);
}

/* Returns 0 on success, -errno on denial. */
static int __ptrace_may_access(struct task_struct *task, unsigned int mode)
{
const struct cred *cred = current_cred(), *tcred;
struct mm_struct *mm;
kuid_t caller_uid;
kgid_t caller_gid;

Expand Down Expand Up @@ -353,11 +366,8 @@ static int __ptrace_may_access(struct task_struct *task, unsigned int mode)
* Pairs with a write barrier in commit_creds().
*/
smp_rmb();
mm = task->mm;
if (mm &&
((get_dumpable(mm) != SUID_DUMP_USER) &&
!ptrace_has_cap(mm->user_ns, mode)))
return -EPERM;
if (!task_still_dumpable(task, mode))
return -EPERM;

return security_ptrace_access_check(task, mode);
}
Expand Down
Loading