diff options
author | Xu Kuohai <xukuohai@huawei.com> | 2024-07-24 10:06:58 +0800 |
---|---|---|
committer | Paul Moore <paul@paul-moore.com> | 2024-07-31 14:46:51 -0400 |
commit | be72a57527fde6c80061c5f9d0e28762eb817b03 (patch) | |
tree | abefde6ce06f167ce75f8f3802fc227934cdb9c8 /security/selinux | |
parent | 61a1dcdceb44d79e5ab511295791b88ea178c045 (diff) | |
download | linux-be72a57527fde6c80061c5f9d0e28762eb817b03.tar.gz linux-be72a57527fde6c80061c5f9d0e28762eb817b03.tar.bz2 linux-be72a57527fde6c80061c5f9d0e28762eb817b03.zip |
lsm: Refactor return value of LSM hook vm_enough_memory
To be consistent with most LSM hooks, convert the return value of
hook vm_enough_memory to 0 or a negative error code.
Before:
- Hook vm_enough_memory returns 1 if permission is granted, 0 if not.
- LSM_RET_DEFAULT(vm_enough_memory_mm) is 1.
After:
- Hook vm_enough_memory reutrns 0 if permission is granted, negative
error code if not.
- LSM_RET_DEFAULT(vm_enough_memory_mm) is 0.
Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
Diffstat (limited to 'security/selinux')
-rw-r--r-- | security/selinux/hooks.c | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 0939816e9671..af7467cdd181 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -2202,23 +2202,16 @@ static int selinux_syslog(int type) } /* - * Check that a process has enough memory to allocate a new virtual - * mapping. 0 means there is enough memory for the allocation to - * succeed and -ENOMEM implies there is not. + * Check permission for allocating a new virtual mapping. Returns + * 0 if permission is granted, negative error code if not. * * Do not audit the selinux permission check, as this is applied to all * processes that allocate mappings. */ static int selinux_vm_enough_memory(struct mm_struct *mm, long pages) { - int rc, cap_sys_admin = 0; - - rc = cred_has_capability(current_cred(), CAP_SYS_ADMIN, - CAP_OPT_NOAUDIT, true); - if (rc == 0) - cap_sys_admin = 1; - - return cap_sys_admin; + return cred_has_capability(current_cred(), CAP_SYS_ADMIN, + CAP_OPT_NOAUDIT, true); } /* binprm security operations */ |