forked from rubenslte/android_kernel_samsung_msm8226
CHROMIUM: security: introduce kernel_module_from_file hook
Now that kernel module origins can be reasoned about, provide a hook to the LSMs to make policy decisions about the module file. Signed-off-by: Kees Cook <keescook@chromium.org> Acked-by: Serge E. Hallyn <serge.hallyn@canonical.com> Acked-by: Eric Paris <eparis@redhat.com> [accepted into Rusty's modules-wip tree for linux-next: http://git.kernel.org/?p=linux/kernel/git/rusty/linux.git;a=shortlog;h=refs/heads/modules-wip] BUG=chromium-os:34134 TEST=parrot build, manual testing Change-Id: I97f5cc0a0f3c1c04e1dc886d6d20f5a6d82326ac Reviewed-on: https://gerrit.chromium.org/gerrit/34303 Tested-by: Kees Cook <keescook@chromium.org> Reviewed-by: Olof Johansson <olofj@chromium.org> Commit-Ready: Kees Cook <keescook@chromium.org>
This commit is contained in:
committed by
Francescodario Cuzzocrea
parent
58bb6cdba7
commit
fec70e69fe
@@ -695,6 +695,12 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
|
||||
* userspace to load a kernel module with the given name.
|
||||
* @kmod_name name of the module requested by the kernel
|
||||
* Return 0 if successful.
|
||||
* @kernel_module_from_file:
|
||||
* Load a kernel module from userspace.
|
||||
* @file contains the file structure pointing to the file containing
|
||||
* the kernel module to load. If the module is being loaded from a blob,
|
||||
* this argument will be NULL.
|
||||
* Return 0 if permission is granted.
|
||||
* @task_fix_setuid:
|
||||
* Update the module's state after setting one or more of the user
|
||||
* identity attributes of the current process. The @flags parameter
|
||||
@@ -1520,6 +1526,7 @@ struct security_operations {
|
||||
int (*kernel_act_as)(struct cred *new, u32 secid);
|
||||
int (*kernel_create_files_as)(struct cred *new, struct inode *inode);
|
||||
int (*kernel_module_request)(char *kmod_name);
|
||||
int (*kernel_module_from_file)(struct file *file);
|
||||
int (*task_fix_setuid) (struct cred *new, const struct cred *old,
|
||||
int flags);
|
||||
int (*task_setpgid) (struct task_struct *p, pid_t pgid);
|
||||
@@ -1787,6 +1794,7 @@ void security_transfer_creds(struct cred *new, const struct cred *old);
|
||||
int security_kernel_act_as(struct cred *new, u32 secid);
|
||||
int security_kernel_create_files_as(struct cred *new, struct inode *inode);
|
||||
int security_kernel_module_request(char *kmod_name);
|
||||
int security_kernel_module_from_file(struct file *file);
|
||||
int security_task_fix_setuid(struct cred *new, const struct cred *old,
|
||||
int flags);
|
||||
int security_task_setpgid(struct task_struct *p, pid_t pgid);
|
||||
@@ -2335,6 +2343,11 @@ static inline int security_kernel_module_request(char *kmod_name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int security_kernel_module_from_file(struct file *file)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int security_task_fix_setuid(struct cred *new,
|
||||
const struct cred *old,
|
||||
int flags)
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <linux/vmalloc.h>
|
||||
#include <linux/elf.h>
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/security.h>
|
||||
#include <linux/seq_file.h>
|
||||
#include <linux/syscalls.h>
|
||||
#include <linux/fcntl.h>
|
||||
@@ -2647,6 +2648,10 @@ int copy_module_from_user(const void __user *umod, unsigned long len,
|
||||
if (info->len < sizeof(*(info->hdr)))
|
||||
return -ENOEXEC;
|
||||
|
||||
err = security_kernel_module_from_file(NULL);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/* Suck in entire file: we'll want most of it. */
|
||||
info->hdr = vmalloc(info->len);
|
||||
if (!info->hdr)
|
||||
@@ -2685,6 +2690,10 @@ int copy_module_from_fd(int fd, struct load_info *info)
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
err = security_kernel_module_from_file(file);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
size = stat.size;
|
||||
info->hdr = vmalloc(size);
|
||||
if (!info->hdr) {
|
||||
|
||||
@@ -415,6 +415,11 @@ static int cap_kernel_module_request(char *kmod_name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cap_kernel_module_from_file(struct file *file)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cap_task_setpgid(struct task_struct *p, pid_t pgid)
|
||||
{
|
||||
return 0;
|
||||
@@ -990,6 +995,7 @@ void __init security_fixup_ops(struct security_operations *ops)
|
||||
set_to_cap_if_null(ops, kernel_act_as);
|
||||
set_to_cap_if_null(ops, kernel_create_files_as);
|
||||
set_to_cap_if_null(ops, kernel_module_request);
|
||||
set_to_cap_if_null(ops, kernel_module_from_file);
|
||||
set_to_cap_if_null(ops, task_fix_setuid);
|
||||
set_to_cap_if_null(ops, task_setpgid);
|
||||
set_to_cap_if_null(ops, task_getpgid);
|
||||
|
||||
@@ -807,6 +807,11 @@ int security_kernel_module_request(char *kmod_name)
|
||||
return security_ops->kernel_module_request(kmod_name);
|
||||
}
|
||||
|
||||
int security_kernel_module_from_file(struct file *file)
|
||||
{
|
||||
return security_ops->kernel_module_from_file(file);
|
||||
}
|
||||
|
||||
int security_task_fix_setuid(struct cred *new, const struct cred *old,
|
||||
int flags)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user