Skip to content

Commit cf23705

Browse files
l0kodkees
authored andcommitted
ptrace: Set PF_SUPERPRIV when checking capability
Commit 69f594a ("ptrace: do not audit capability check when outputing /proc/pid/stat") replaced the use of ns_capable() with has_ns_capability{,_noaudit}() which doesn't set PF_SUPERPRIV. Commit 6b3ad66 ("ptrace: reintroduce usage of subjective credentials in ptrace_has_cap()") replaced has_ns_capability{,_noaudit}() with security_capable(), which doesn't set PF_SUPERPRIV neither. Since commit 98f368e ("kernel: Add noaudit variant of ns_capable()"), a new ns_capable_noaudit() helper is available. Let's use it! As a result, the signature of ptrace_has_cap() is restored to its original one. Cc: Christian Brauner <christian.brauner@ubuntu.com> Cc: Eric Paris <eparis@redhat.com> Cc: Jann Horn <jannh@google.com> Cc: Kees Cook <keescook@chromium.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Serge E. Hallyn <serge@hallyn.com> Cc: Tyler Hicks <tyhicks@linux.microsoft.com> Cc: stable@vger.kernel.org Fixes: 6b3ad66 ("ptrace: reintroduce usage of subjective credentials in ptrace_has_cap()") Fixes: 69f594a ("ptrace: do not audit capability check when outputing /proc/pid/stat") Signed-off-by: Mickaël Salaün <mic@linux.microsoft.com> Reviewed-by: Jann Horn <jannh@google.com> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20201030123849.770769-2-mic@digikod.net
1 parent 09162bc commit cf23705

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

kernel/ptrace.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,11 @@ static int ptrace_check_attach(struct task_struct *child, bool ignore_state)
264264
return ret;
265265
}
266266

267-
static bool ptrace_has_cap(const struct cred *cred, struct user_namespace *ns,
268-
unsigned int mode)
267+
static bool ptrace_has_cap(struct user_namespace *ns, unsigned int mode)
269268
{
270-
int ret;
271-
272269
if (mode & PTRACE_MODE_NOAUDIT)
273-
ret = security_capable(cred, ns, CAP_SYS_PTRACE, CAP_OPT_NOAUDIT);
274-
else
275-
ret = security_capable(cred, ns, CAP_SYS_PTRACE, CAP_OPT_NONE);
276-
277-
return ret == 0;
270+
return ns_capable_noaudit(ns, CAP_SYS_PTRACE);
271+
return ns_capable(ns, CAP_SYS_PTRACE);
278272
}
279273

280274
/* Returns 0 on success, -errno on denial. */
@@ -326,7 +320,7 @@ static int __ptrace_may_access(struct task_struct *task, unsigned int mode)
326320
gid_eq(caller_gid, tcred->sgid) &&
327321
gid_eq(caller_gid, tcred->gid))
328322
goto ok;
329-
if (ptrace_has_cap(cred, tcred->user_ns, mode))
323+
if (ptrace_has_cap(tcred->user_ns, mode))
330324
goto ok;
331325
rcu_read_unlock();
332326
return -EPERM;
@@ -345,7 +339,7 @@ static int __ptrace_may_access(struct task_struct *task, unsigned int mode)
345339
mm = task->mm;
346340
if (mm &&
347341
((get_dumpable(mm) != SUID_DUMP_USER) &&
348-
!ptrace_has_cap(cred, mm->user_ns, mode)))
342+
!ptrace_has_cap(mm->user_ns, mode)))
349343
return -EPERM;
350344

351345
return security_ptrace_access_check(task, mode);

0 commit comments

Comments
 (0)