OSDN Git Service

exec: Always set cap_ambient in cap_bprm_set_creds
authorEric W. Biederman <ebiederm@xmission.com>
Mon, 25 May 2020 17:56:15 +0000 (12:56 -0500)
committerEric W. Biederman <ebiederm@xmission.com>
Tue, 26 May 2020 18:11:00 +0000 (13:11 -0500)
commita4ae32c71fe90794127b32d26d7ad795813b502e
treec4fafbc9f1123b48542ac6c22246928e6a15aed3
parent6a8b55ed4056ea5559ebe4f6a4b247f627870d4c
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: stable@vger.kernel.org
Cc: Andy Lutomirski <luto@kernel.org>
Fixes: 58319057b784 ("capabilities: ambient capabilities")
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
security/commoncap.c