security/safesetid: fix comment and error handling
Subsystems (2)
PATCH 1/1 security/safesetid: fix comment and error handling
- Fix comment in lsm.c: use CAP_SETGID instead of CAP_SETUID in the GID capability check comment to match the actual logic.
- In handle_policy_update(), set err = -EINVAL and goto out_free_buf when policy type is neither UID nor GID, so the error is returned to the caller instead of only logging.
- In safesetid_init_securityfs(), return ret directly when policy_dir creation fails instead of goto error (no cleanup needed at that point).
--- security/safesetid/lsm.c | 2 +- security/safesetid/securityfs.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-)
security/safesetid/lsm.c +1 -1
@@ -128,7 +128,7 @@ static int safesetid_security_capable(const struct cred *cred,if (setid_policy_lookup ((kid_t ){.gid = cred->gid},INVALID_ID ,GID ) ==SIDPOL_DEFAULT )return 0 ;/* -* Reject use of CAP_SETUID for functionality other than calling +* Reject use of CAP_SETGID for functionality other than calling * set*gid() (e.g. setting up userns gid mappings). */ pr_warn("Operation requires CAP_SETGID, which is not available to GID %u for operations besides approved set*gid transitions\n",
security/safesetid/securityfs.c +3 -1
@@ -224,6 +224,8 @@ static ssize_t handle_policy_update(struct file *file, }else {/* Error, policy type is neither UID or GID */ pr_warn ("error: bad policy type" ); + err = -EINVAL ; + goto out_free_buf; } err = len;
@@ -321,7 +323,7 @@ int __init safesetid_init_securityfs(void) policy_dir =securityfs_create_dir ("safesetid" ,NULL );if (IS_ERR (policy_dir)) { ret =PTR_ERR (policy_dir); - goto error; +return ret; } uid_policy_file = securityfs_create_file("uid_allowlist_policy", 0600,
Signature · 1 line
2.43.5
Micah Morton
maintainerQuoted 21 lines · yanwei.gao
- Fix comment in
lsm.c: useCAP_SETGIDinstead ofCAP_SETUIDin the GID capability check comment to match the actual logic.
- Inhandle_policy_update(), set err =-EINVALand gotoout_free_bufwhen policy type is neither UID nor GID, so the error is returned to the caller instead of only logging.
- Insafesetid_init_securityfs(), return ret directly whenpolicy_dircreation fails instead of goto error (no cleanup needed at that point).Signed-off-by yanwei.gao <[email protected]>--- security/safesetid/lsm.c | 2 +- security/safesetid/securityfs.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-)security/safesetid/lsm.c +0
-0
security/safesetid/lsm.c static int safesetid_security_capable(const struct cred *cred, · line 131
Quoted 5 lines
security/safesetid/lsm.c +1
-1@@ -128,7 +128,7 @@ static int safesetid_security_capable(const struct cred *cred,if (setid_policy_lookup ((kid_t ){.gid = cred->gid},INVALID_ID ,GID ) ==SIDPOL_DEFAULT )return 0 ;/* -* Reject use of CAP_SETUID for functionality other than calling +* Reject use of CAP_SETGID for functionality other than calling
Looks good.
security/safesetid/securityfs.c static ssize_t handle_policy_update(struct file *file, · line 228
Quoted 13 lines
security/safesetid/lsm.c +0
-0* set*gid() (e.g. setting up userns gid mappings). */ pr_warn("Operation requires CAP_SETGID, which is not available to GID %u for operations besides approved set*gid transitions\n",security/safesetid/securityfs.c +2
-0@@ -224,6 +224,8 @@ static ssize_t handle_policy_update(struct file *file, }else {/* Error, policy type is neither UID or GID */ pr_warn ("error: bad policy type" ); + err = -EINVAL ; + goto out_free_buf;
This makes sense to me and matches how things are done in the functions above in verify_ruleset() and parse_policy_line().
Is this code actually reachable? I guess if verify_ruleset returns -EINVAL due to a bad policy type value the code still hits this spot?
security/safesetid/securityfs.c int __init safesetid_init_securityfs(void) · line 326
Quoted 9 lines
security/safesetid/securityfs.c +1
-1} err = len;@@ -321,7 +323,7 @@ int __init safesetid_init_securityfs(void) policy_dir =securityfs_create_dir ("safesetid" ,NULL );if (IS_ERR (policy_dir)) { ret =PTR_ERR (policy_dir); - goto error; +return ret;
We still need the securityfs_remove(policy_dir) call to clean up the dir created with policy_dir = securityfs_create_dir("safesetid", NULL) don't we?
Quoted 6 lines
security/safesetid/securityfs.c +0
-1} uid_policy_file = securityfs_create_file("uid_allowlist_policy", 0600, --2.43.5
Micah Morton
maintainerQuoted 52 lines · Micah Morton
Quoted 21 lines · yanwei.gao
- Fix comment in
lsm.c: useCAP_SETGIDinstead ofCAP_SETUIDin the GID capability check comment to match the actual logic.
- Inhandle_policy_update(), set err =-EINVALand gotoout_free_bufwhen policy type is neither UID nor GID, so the error is returned to the caller instead of only logging.
- Insafesetid_init_securityfs(), return ret directly whenpolicy_dircreation fails instead of goto error (no cleanup needed at that point).Signed-off-by yanwei.gao <[email protected]>--- security/safesetid/lsm.c | 2 +- security/safesetid/securityfs.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-)security/safesetid/lsm.c +0
-0security/safesetid/lsm.c static int safesetid_security_capable(const struct cred *cred, · line 131
Quoted 5 lines
security/safesetid/lsm.c +1
-1@@ -128,7 +128,7 @@ static int safesetid_security_capable(const struct cred *cred,if (setid_policy_lookup ((kid_t ){.gid = cred->gid},INVALID_ID ,GID ) ==SIDPOL_DEFAULT )return 0 ;/* -* Reject use of CAP_SETUID for functionality other than calling +* Reject use of CAP_SETGID for functionality other than calling Looks good.
security/safesetid/securityfs.c static ssize_t handle_policy_update(struct file *file, · line 228
Quoted 13 lines
security/safesetid/lsm.c +0
-0* set*gid() (e.g. setting up userns gid mappings). */ pr_warn("Operation requires CAP_SETGID, which is not available to GID %u for operations besides approved set*gid transitions\n",security/safesetid/securityfs.c +2
-0@@ -224,6 +224,8 @@ static ssize_t handle_policy_update(struct file *file, }else {/* Error, policy type is neither UID or GID */ pr_warn ("error: bad policy type" ); + err = -EINVAL ; + goto out_free_buf;This makes sense to me and matches how things are done in the functions above in
verify_ruleset()andparse_policy_line().Is this code actually reachable? I guess if
verify_rulesetreturns-EINVALdue to a bad policy type value the code still hits this spot?Quoted 3 lines
security/safesetid/securityfs.c +0
-0} err = len;
Quoted 10 lines
security/safesetid/securityfs.c int __init safesetid_init_securityfs(void) · line 326
Quoted 6 lines
security/safesetid/securityfs.c +1
-1@@ -321,7 +323,7 @@ int __init safesetid_init_securityfs(void) policy_dir =securityfs_create_dir ("safesetid" ,NULL );if (IS_ERR (policy_dir)) { ret =PTR_ERR (policy_dir); - goto error; +return ret;We still need the
securityfs_remove(policy_dir)call to clean up the dir created withpolicy_dir = securityfs_create_dir("safesetid", NULL)don't we?
I guess securityfs_remove() just returns right away if the 'policy_dir' pointer IS_ERR, so either way is fine. I don't really see a reason to change this though.. seems better to err on the side of calling the securityfs_remove() function even if its currently a no-op.
Quoted 7 lines
Quoted 7 lines
security/safesetid/securityfs.c +0
-1} uid_policy_file = securityfs_create_file("uid_allowlist_policy", 0600, --2.43.5