Commit 8068866c authored by Jann Horn's avatar Jann Horn Committed by Micah Morton

LSM: SafeSetID: refactor safesetid_security_capable()

At the moment, safesetid_security_capable() has two nested conditional
blocks, and one big comment for all the logic. Chop it up and reduce the
amount of indentation.
Signed-off-by: default avatarJann Horn <jannh@google.com>
Signed-off-by: default avatarMicah Morton <mortonm@chromium.org>
parent 1cd02a27
...@@ -55,21 +55,32 @@ static int safesetid_security_capable(const struct cred *cred, ...@@ -55,21 +55,32 @@ static int safesetid_security_capable(const struct cred *cred,
int cap, int cap,
unsigned int opts) unsigned int opts)
{ {
if (cap == CAP_SETUID && /* We're only interested in CAP_SETUID. */
setuid_policy_lookup(cred->uid, INVALID_UID) != SIDPOL_DEFAULT) { if (cap != CAP_SETUID)
if (!(opts & CAP_OPT_INSETID)) { return 0;
/*
* Deny if we're not in a set*uid() syscall to avoid /*
* giving powers gated by CAP_SETUID that are related * If CAP_SETUID is currently used for a set*uid() syscall, we want to
* to functionality other than calling set*uid() (e.g. * let it go through here; the real security check happens later, in the
* allowing user to set up userns uid mappings). * task_fix_setuid hook.
*/ */
pr_warn("Operation requires CAP_SETUID, which is not available to UID %u for operations besides approved set*uid transitions\n", if ((opts & CAP_OPT_INSETID) != 0)
__kuid_val(cred->uid)); return 0;
return -1;
} /*
} * If no policy applies to this task, allow the use of CAP_SETUID for
return 0; * other purposes.
*/
if (setuid_policy_lookup(cred->uid, INVALID_UID) == SIDPOL_DEFAULT)
return 0;
/*
* Reject use of CAP_SETUID for functionality other than calling
* set*uid() (e.g. setting up userns uid mappings).
*/
pr_warn("Operation requires CAP_SETUID, which is not available to UID %u for operations besides approved set*uid transitions\n",
__kuid_val(cred->uid));
return -1;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment