security: Add LSM hook to setgroups() syscall
PATCH 1/3 security: Add LSM hook to setgroups() syscall
Give the LSM framework the ability to filter setgroups() syscalls. There are already analagous hooks for the set*uid() and set*gid() syscalls. The SafeSetID LSM will use this new hook to ensure setgroups() calls are allowed by the installed security policy. Tested by putting print statement in security_task_fix_setgroups() hook and confirming that it gets hit when userspace does a setgroups() syscall.
--- include/linux/lsm_hook_defs.h | 1 + include/linux/lsm_hooks.h | 7 +++++++ include/linux/security.h | 7 +++++++ kernel/groups.c | 13 +++++++++++++ security/security.c | 5 +++++ 5 files changed, 33 insertions(+)
include/linux/lsm_hook_defs.h +1 -0
@@ -201,6 +201,7 @@ LSM_HOOK(int, 0, task_fix_setuid, struct cred *new, const struct cred *old, int flags) LSM_HOOK(int, 0, task_fix_setgid, struct cred *new, const struct cred * old, int flags) +LSM_HOOK(int, 0, task_fix_setgroups, struct cred *new, const struct cred * old) LSM_HOOK(int, 0, task_setpgid, struct task_struct *p, pid_t pgid) LSM_HOOK(int, 0, task_getpgid, struct task_struct *p) LSM_HOOK(int, 0, task_getsid, struct task_struct *p)
include/linux/lsm_hooks.h +7 -0
@@ -702,6 +702,13 @@* @old is the set of credentials that are being replaced. * @flags contains one of the LSM_SETID_* values. * Return 0 on success. +* @task_fix_setgroups: +* Update the module's state after setting the supplementary group +* identity attributes of the current process. +* @new is the set of credentials that will be installed. Modifications +* should be made to this rather than to @current->cred. +* @old is the set of credentials that are being replaced. +* Return 0 on success. * @task_setpgid: * Check permission before setting the process group identifier of the * process @p to @pgid.
include/linux/security.h +7 -0
@@ -415,6 +415,7 @@ int security_task_fix_setuid(struct cred *new, const struct cred *old, int flags);int security_task_fix_setgid (struct cred *new,const struct cred *old,int flags); +int security_task_fix_setgroups (struct cred *new,const struct cred *old);int security_task_setpgid (struct task_struct *p,pid_t pgid);int security_task_getpgid (struct task_struct *p);int security_task_getsid (struct task_struct *p);
@@ -1098,6 +1099,12 @@ static inline int security_task_fix_setgid(struct cred *new,return 0 ; } +static inline int security_task_fix_setgroups (struct cred *new, +const struct cred *old) +{ +return 0 ; +} +static inline int security_task_setpgid (struct task_struct *p,pid_t pgid) {return 0 ;
kernel/groups.c +13 -0
@@ -134,13 +134,26 @@ EXPORT_SYMBOL(set_groups);int set_current_groups (struct group_info *group_info) {struct cred *new; +const struct cred *old; +int retval; new =prepare_creds ();if (!new)return -ENOMEM ; + old =current_cred (); +set_groups (new, group_info); + + retval =security_task_fix_setgroups (new, old); +if (retval <0 ) + goto error; +return commit_creds (new); + +error: +abort_creds (new); +return retval; }EXPORT_SYMBOL (set_current_groups);
security/security.c +5 -0
@@ -1803,6 +1803,11 @@ int security_task_fix_setgid(struct cred *new, const struct cred *old,return call_int_hook (task_fix_setgid,0 , new, old, flags); } +int security_task_fix_setgroups (struct cred *new,const struct cred *old) +{ +return call_int_hook (task_fix_setgroups,0 , new, old); +} +int security_task_setpgid (struct task_struct *p,pid_t pgid) {return call_int_hook (task_setpgid,0 , p, pgid);
Signature · 1 line
2.36.1.476.g0c4daa206d-goog
Quoted 8 lines · Micah Morton
Give the LSM framework the ability to filter
setgroups()syscalls. There are already analagous hooks for the set*uid() and set*gid() syscalls. The SafeSetID LSM will use this new hook to ensuresetgroups()calls are allowed by the installed security policy. Tested by putting print statement insecurity_task_fix_setgroups()hook and confirming that it gets hit when userspace does asetgroups()syscall.Signed-off-by Micah Morton <[email protected]>
I don't see any problems with this.
Quoted 110 lines
--- include/linux/lsm_hook_defs.h | 1 + include/linux/lsm_hooks.h | 7 +++++++ include/linux/security.h | 7 +++++++ kernel/groups.c | 13 +++++++++++++ security/security.c | 5 +++++ 5 files changed, 33 insertions(+)include/linux/lsm_hook_defs.h +1
-0@@ -201,6 +201,7 @@ LSM_HOOK(int, 0, task_fix_setuid, struct cred *new, const struct cred *old, int flags) LSM_HOOK(int, 0, task_fix_setgid, struct cred *new, const struct cred * old, int flags) +LSM_HOOK(int, 0, task_fix_setgroups, struct cred *new, const struct cred * old) LSM_HOOK(int, 0, task_setpgid, struct task_struct *p, pid_t pgid) LSM_HOOK(int, 0, task_getpgid, struct task_struct *p) LSM_HOOK(int, 0, task_getsid, struct task_struct *p)include/linux/lsm_hooks.h +7
-0@@ -702,6 +702,13 @@* @old is the set of credentials that are being replaced. * @flags contains one of the LSM_SETID_* values. * Return 0 on success. +* @task_fix_setgroups: +* Update the module's state after setting the supplementary group +* identity attributes of the current process. +* @new is the set of credentials that will be installed. Modifications +* should be made to this rather than to @current->cred. +* @old is the set of credentials that are being replaced. +* Return 0 on success. * @task_setpgid: * Check permission before setting the process group identifier of the * process @p to @pgid. include/linux/security.h +7
-0@@ -415,6 +415,7 @@ int security_task_fix_setuid(struct cred *new, const struct cred *old, int flags);int security_task_fix_setgid (struct cred *new,const struct cred *old,int flags); +int security_task_fix_setgroups (struct cred *new,const struct cred *old);int security_task_setpgid (struct task_struct *p,pid_t pgid);int security_task_getpgid (struct task_struct *p);int security_task_getsid (struct task_struct *p);@@ -1098,6 +1099,12 @@ static inline int security_task_fix_setgid(struct cred *new,return 0 ; } +static inline int security_task_fix_setgroups (struct cred *new, +const struct cred *old) +{ +return 0 ; +} +static inline int security_task_setpgid (struct task_struct *p,pid_t pgid) {return 0 ;kernel/groups.c +13
-0@@ -134,13 +134,26 @@ EXPORT_SYMBOL(set_groups);int set_current_groups (struct group_info *group_info) {struct cred *new; +const struct cred *old; +int retval; new =prepare_creds ();if (!new)return -ENOMEM ; + old =current_cred (); +set_groups (new, group_info); + + retval =security_task_fix_setgroups (new, old); +if (retval <0 ) + goto error; +return commit_creds (new); + +error: +abort_creds (new); +return retval; }EXPORT_SYMBOL (set_current_groups);security/security.c +5
-0@@ -1803,6 +1803,11 @@ int security_task_fix_setgid(struct cred *new, const struct cred *old,return call_int_hook (task_fix_setgid,0 , new, old, flags); } +int security_task_fix_setgroups (struct cred *new,const struct cred *old) +{ +return call_int_hook (task_fix_setgroups,0 , new, old); +} +int security_task_setpgid (struct task_struct *p,pid_t pgid) {return call_int_hook (task_setpgid,0 , p, pgid);
Quoted 8 lines · Casey Schaufler
Quoted 7 lines · Micah Morton
Give the LSM framework the ability to filter
setgroups()syscalls. There are already analagous hooks for the set*uid() and set*gid() syscalls. The SafeSetID LSM will use this new hook to ensuresetgroups()calls are allowed by the installed security policy. Tested by putting print statement insecurity_task_fix_setgroups()hook and confirming that it gets hit when userspace does asetgroups()syscall.
Quoted 5 lines
Quoted 1 line
Signed-off-by Micah Morton <[email protected]>I don't see any problems with this.
Acked-by Casey Schaufler <[email protected]>
Ditto. Thanks.
Quoted 105 lines
Quoted 105 lines
--- include/linux/lsm_hook_defs.h | 1 + include/linux/lsm_hooks.h | 7 +++++++ include/linux/security.h | 7 +++++++ kernel/groups.c | 13 +++++++++++++ security/security.c | 5 +++++ 5 files changed, 33 insertions(+)include/linux/lsm_hook_defs.h +1
-0@@ -201,6 +201,7 @@ LSM_HOOK(int, 0, task_fix_setuid, struct cred *new, const struct cred *old, int flags) LSM_HOOK(int, 0, task_fix_setgid, struct cred *new, const struct cred * old, int flags) +LSM_HOOK(int, 0, task_fix_setgroups, struct cred *new, const struct cred * old) LSM_HOOK(int, 0, task_setpgid, struct task_struct *p, pid_t pgid) LSM_HOOK(int, 0, task_getpgid, struct task_struct *p) LSM_HOOK(int, 0, task_getsid, struct task_struct *p)include/linux/lsm_hooks.h +7
-0@@ -702,6 +702,13 @@* @old is the set of credentials that are being replaced. * @flags contains one of the LSM_SETID_* values. * Return 0 on success. +* @task_fix_setgroups: +* Update the module's state after setting the supplementary group +* identity attributes of the current process. +* @new is the set of credentials that will be installed. Modifications +* should be made to this rather than to @current->cred. +* @old is the set of credentials that are being replaced. +* Return 0 on success. * @task_setpgid: * Check permission before setting the process group identifier of the * process @p to @pgid. include/linux/security.h +7
-0@@ -415,6 +415,7 @@ int security_task_fix_setuid(struct cred *new, const struct cred *old, int flags);int security_task_fix_setgid (struct cred *new,const struct cred *old,int flags); +int security_task_fix_setgroups (struct cred *new,const struct cred *old);int security_task_setpgid (struct task_struct *p,pid_t pgid);int security_task_getpgid (struct task_struct *p);int security_task_getsid (struct task_struct *p);@@ -1098,6 +1099,12 @@ static inline int security_task_fix_setgid(struct cred *new,return 0 ; } +static inline int security_task_fix_setgroups (struct cred *new, +const struct cred *old) +{ +return 0 ; +} +static inline int security_task_setpgid (struct task_struct *p,pid_t pgid) {return 0 ;kernel/groups.c +13
-0@@ -134,13 +134,26 @@ EXPORT_SYMBOL(set_groups);int set_current_groups (struct group_info *group_info) {struct cred *new; +const struct cred *old; +int retval; new =prepare_creds ();if (!new)return -ENOMEM ; + old =current_cred (); +set_groups (new, group_info); + + retval =security_task_fix_setgroups (new, old); +if (retval <0 ) + goto error; +return commit_creds (new); + +error: +abort_creds (new); +return retval; }EXPORT_SYMBOL (set_current_groups);security/security.c +5
-0@@ -1803,6 +1803,11 @@ int security_task_fix_setgid(struct cred *new, const struct cred *old,return call_int_hook (task_fix_setgid,0 , new, old, flags); } +int security_task_fix_setgroups (struct cred *new,const struct cred *old) +{ +return call_int_hook (task_fix_setgroups,0 , new, old); +} +int security_task_setpgid (struct task_struct *p,pid_t pgid) {return call_int_hook (task_setpgid,0 , p, pgid);