Skip to content

Commit 2052313

Browse files
committed
exec: Test the ptracer's saved cred to see if the tracee can gain caps
Now that we have user namespaces and non-global capabilities verify the tracer has capabilities in the relevant user namespace instead of in the current_user_ns(). As the test for setting LSM_UNSAFE_PTRACE_CAP is currently ptracer_capable(p, current_user_ns()) and the new task credentials are in current_user_ns() this change does not have any user visible change and simply moves the test to where it is used, making the code easier to read. Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent 7016942 commit 2052313

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

security/commoncap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,8 @@ int cap_bprm_set_creds(struct linux_binprm *bprm)
548548

549549
if ((is_setid ||
550550
!cap_issubset(new->cap_permitted, old->cap_permitted)) &&
551-
bprm->unsafe & ~LSM_UNSAFE_PTRACE_CAP) {
551+
((bprm->unsafe & ~(LSM_UNSAFE_PTRACE | LSM_UNSAFE_PTRACE_CAP)) ||
552+
!ptracer_capable(current, new->user_ns))) {
552553
/* downgrade; they get no more than they had, and maybe less */
553554
if (!ns_capable(new->user_ns, CAP_SETUID) ||
554555
(bprm->unsafe & LSM_UNSAFE_NO_NEW_PRIVS)) {

0 commit comments

Comments
 (0)