Skip to content

Commit a4ae32c

Browse files
committed
exec: Always set cap_ambient in cap_bprm_set_creds
An invariant of cap_bprm_set_creds is that every field in the new cred structure that cap_bprm_set_creds might set, needs to be set every time to ensure the fields does not get a stale value. The field cap_ambient is not set every time cap_bprm_set_creds is called, which means that if there is a suid or sgid script with an interpreter that has neither the suid nor the sgid bits set the interpreter should be able to accept ambient credentials. Unfortuantely because cap_ambient is not reset to it's original value the interpreter can not accept ambient credentials. Given that the ambient capability set is expected to be controlled by the caller, I don't think this is particularly serious. But it is definitely worth fixing so the code works correctly. I have tested to verify my reading of the code is correct and the interpreter of a sgid can receive ambient capabilities with this change and cannot receive ambient capabilities without this change. Cc: [email protected] Cc: Andy Lutomirski <[email protected]> Fixes: 5831905 ("capabilities: ambient capabilities") Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent 6a8b55e commit a4ae32c

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

security/commoncap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ int cap_bprm_set_creds(struct linux_binprm *bprm)
812812
int ret;
813813
kuid_t root_uid;
814814

815+
new->cap_ambient = old->cap_ambient;
815816
if (WARN_ON(!cap_ambient_invariant_ok(old)))
816817
return -EPERM;
817818

0 commit comments

Comments
 (0)