[PATCH] security: Add LSM hooks to set*gid syscalls

Kees Cook keescook at chromium.org
Fri Jun 5 21:25:51 UTC 2020


On Fri, Jun 05, 2020 at 12:38:05PM -0700, Micah Morton wrote:
> The SafeSetID LSM uses the security_task_fix_setuid hook to filter
> set*uid() syscalls according to its configured security policy. In
> preparation for adding analagous support in the LSM for set*gid()
> syscalls, we add the requisite hook here. Tested by putting print
> statements in the security_task_fix_setgid hook and seeing them get hit
> during kernel boot.
> 
> From: Thomas Cedeno <thomascedeno at google.com>

^^^ this line should be before the commit log body (many tools won't
find it here).

> Signed-off-by: Thomas Cedeno <thomascedeno at google.com>
> Reviewed-by: Micah Morton <mortonm at chromium.org>
> ---
> NOTE: I (Micah) will send this patch as a pull request to Linus through
> my SafeSetID tree if there are no objections.
>  include/linux/lsm_hook_defs.h |  2 ++
>  include/linux/lsm_hooks.h     |  9 +++++++++
>  include/linux/security.h      |  9 +++++++++
>  kernel/sys.c                  | 15 ++++++++++++++-
>  security/security.c           |  6 ++++++
>  5 files changed, 40 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
> index fb3ce6cec997..d5401c09f2d3 100644
> --- a/include/linux/lsm_hook_defs.h
> +++ b/include/linux/lsm_hook_defs.h
> @@ -191,6 +191,8 @@ LSM_HOOK(int, 0, kernel_post_read_file, struct file *file, char *buf,
>  	 loff_t size, enum kernel_read_file_id id)
>  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_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)
> diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h
> index 3e62dab77699..8012b610fe53 100644
> --- a/include/linux/lsm_hooks.h
> +++ b/include/linux/lsm_hooks.h
> @@ -659,6 +659,15 @@
>   *	@old is the set of credentials that are being replaces
>   *	@flags contains one of the LSM_SETID_* values.
>   *	Return 0 on success.
> + * @task_fix_setgid:
> + *     Update the module's state after setting one or more of the group
> + *     identity attributes of the current process.  The @flags parameter
> + *     indicates which of the set*gid system calls invoked this hook.
> + *     @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.
> + *     @flags contains one of the LSM_SETID_* values.
> + *     Return 0 on success.

The indenting here appears to be using spaces instead of a tab.

Everything else looks okay. (There are a surprising number of gid
changing places...)

-- 
Kees Cook



More information about the Linux-security-module-archive mailing list