Skip to content

Commit ea0ab64

Browse files
committed
Merge tag 'seccomp-v5.10-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull seccomp fixes from Kees Cook: "This gets the seccomp selftests running again on powerpc and sh, and fixes an audit reporting oversight noticed in both seccomp and ptrace. - Fix typos in seccomp selftests on powerpc and sh (Kees Cook) - Fix PF_SUPERPRIV audit marking in seccomp and ptrace (Mickaël Salaün)" * tag 'seccomp-v5.10-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: selftests/seccomp: sh: Fix register names selftests/seccomp: powerpc: Fix typo in macro variable name seccomp: Set PF_SUPERPRIV when checking capability ptrace: Set PF_SUPERPRIV when checking capability
2 parents 27bba9c + 4c222f3 commit ea0ab64

3 files changed

Lines changed: 11 additions & 18 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);

kernel/seccomp.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include <linux/filter.h>
3939
#include <linux/pid.h>
4040
#include <linux/ptrace.h>
41-
#include <linux/security.h>
41+
#include <linux/capability.h>
4242
#include <linux/tracehook.h>
4343
#include <linux/uaccess.h>
4444
#include <linux/anon_inodes.h>
@@ -558,8 +558,7 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
558558
* behavior of privileged children.
559559
*/
560560
if (!task_no_new_privs(current) &&
561-
security_capable(current_cred(), current_user_ns(),
562-
CAP_SYS_ADMIN, CAP_OPT_NOAUDIT) != 0)
561+
!ns_capable_noaudit(current_user_ns(), CAP_SYS_ADMIN))
563562
return ERR_PTR(-EACCES);
564563

565564
/* Allocate a new seccomp_filter */

tools/testing/selftests/seccomp/seccomp_bpf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,10 +1758,10 @@ TEST_F(TRACE_poke, getpid_runs_normally)
17581758
* and the code is stored as a positive value. \
17591759
*/ \
17601760
if (_result < 0) { \
1761-
SYSCALL_RET(_regs) = -result; \
1761+
SYSCALL_RET(_regs) = -_result; \
17621762
(_regs).ccr |= 0x10000000; \
17631763
} else { \
1764-
SYSCALL_RET(_regs) = result; \
1764+
SYSCALL_RET(_regs) = _result; \
17651765
(_regs).ccr &= ~0x10000000; \
17661766
} \
17671767
} while (0)
@@ -1804,8 +1804,8 @@ TEST_F(TRACE_poke, getpid_runs_normally)
18041804
#define SYSCALL_RET(_regs) (_regs).a[(_regs).windowbase * 4 + 2]
18051805
#elif defined(__sh__)
18061806
# define ARCH_REGS struct pt_regs
1807-
# define SYSCALL_NUM(_regs) (_regs).gpr[3]
1808-
# define SYSCALL_RET(_regs) (_regs).gpr[0]
1807+
# define SYSCALL_NUM(_regs) (_regs).regs[3]
1808+
# define SYSCALL_RET(_regs) (_regs).regs[0]
18091809
#else
18101810
# error "Do not know how to find your architecture's registers and syscalls"
18111811
#endif

0 commit comments

Comments
 (0)