Re: [PATCH v4a 8/8] module: replace the existing LSM hook in init_module
From: Kees Cook
Date: Tue Jun 05 2018 - 15:45:19 EST
On Thu, May 31, 2018 at 8:23 AM, Mimi Zohar <zohar@xxxxxxxxxxxxxxxxxx> wrote:
> diff --git a/security/loadpin/loadpin.c b/security/loadpin/loadpin.c
> index 5fa191252c8f..a9c07bfbc338 100644
> --- a/security/loadpin/loadpin.c
> +++ b/security/loadpin/loadpin.c
> @@ -173,9 +173,24 @@ static int loadpin_read_file(struct file *file, enum kernel_read_file_id id)
> return 0;
> }
>
> +static int loadpin_load_data(enum kernel_load_data_id id)
> +{
> + int rc = 0;
> +
> + switch (id) {
> + case LOADING_MODULE:
> + rc = loadpin_read_file(NULL, READING_MODULE);
> + default:
> + break;
> + }
> +
> + return rc;
> +}
Is it worth keeping the same enum between the two hooks? That would
simplify this a bit since it could just pass the id without remapping.
And if you must have a separate enum, please change this to fail
closed instead of open (and mark the fall-through):
int rc = -EPERM;
switch (id) {
case LOADING_MODULE:
rc = loadpin_read_file(NULL, READING_MODULE);
/* Fall-through */
default:
break;
}
Thanks!
-Kees
> +
> static struct security_hook_list loadpin_hooks[] __lsm_ro_after_init = {
> LSM_HOOK_INIT(sb_free_security, loadpin_sb_free_security),
> LSM_HOOK_INIT(kernel_read_file, loadpin_read_file),
> + LSM_HOOK_INIT(kernel_load_data, loadpin_load_data),
> };
>
> void __init loadpin_add_hooks(void)
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index 02ebd1585eaf..475aed9ee2c7 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -4059,6 +4059,20 @@ static int selinux_kernel_read_file(struct file *file,
> return rc;
> }
>
> +static int selinux_kernel_load_data(enum kernel_load_data_id id)
> +{
> + int rc = 0;
> +
> + switch (id) {
> + case LOADING_MODULE:
> + rc = selinux_kernel_module_from_file(NULL);
> + default:
> + break;
> + }
> +
> + return rc;
> +}
> +
> static int selinux_task_setpgid(struct task_struct *p, pid_t pgid)
> {
> return avc_has_perm(&selinux_state,
> @@ -6950,6 +6964,7 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {
> LSM_HOOK_INIT(kernel_act_as, selinux_kernel_act_as),
> LSM_HOOK_INIT(kernel_create_files_as, selinux_kernel_create_files_as),
> LSM_HOOK_INIT(kernel_module_request, selinux_kernel_module_request),
> + LSM_HOOK_INIT(kernel_load_data, selinux_kernel_load_data),
> LSM_HOOK_INIT(kernel_read_file, selinux_kernel_read_file),
> LSM_HOOK_INIT(task_setpgid, selinux_task_setpgid),
> LSM_HOOK_INIT(task_getpgid, selinux_task_getpgid),
> --
> 2.7.5
>
--
Kees Cook
Pixel Security