Commit 377179cd authored by Mimi Zohar's avatar Mimi Zohar Committed by James Morris

security: define new LSM hook named security_kernel_load_data

Differentiate between the kernel reading a file specified by userspace
from the kernel loading a buffer containing data provided by userspace.
This patch defines a new LSM hook named security_kernel_load_data().
Signed-off-by: default avatarMimi Zohar <zohar@linux.vnet.ibm.com>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Luis R. Rodriguez <mcgrof@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Acked-by: default avatarSerge Hallyn <serge@hallyn.com>
Acked-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarJames Morris <james.morris@microsoft.com>
parent 57b54d74
...@@ -576,6 +576,10 @@ ...@@ -576,6 +576,10 @@
* userspace to load a kernel module with the given name. * userspace to load a kernel module with the given name.
* @kmod_name name of the module requested by the kernel * @kmod_name name of the module requested by the kernel
* Return 0 if successful. * Return 0 if successful.
* @kernel_load_data:
* Load data provided by userspace.
* @id kernel load data identifier
* Return 0 if permission is granted.
* @kernel_read_file: * @kernel_read_file:
* Read a file specified by userspace. * Read a file specified by userspace.
* @file contains the file structure pointing to the file being read * @file contains the file structure pointing to the file being read
...@@ -1582,6 +1586,7 @@ union security_list_options { ...@@ -1582,6 +1586,7 @@ union security_list_options {
int (*kernel_act_as)(struct cred *new, u32 secid); int (*kernel_act_as)(struct cred *new, u32 secid);
int (*kernel_create_files_as)(struct cred *new, struct inode *inode); int (*kernel_create_files_as)(struct cred *new, struct inode *inode);
int (*kernel_module_request)(char *kmod_name); int (*kernel_module_request)(char *kmod_name);
int (*kernel_load_data)(enum kernel_load_data_id id);
int (*kernel_read_file)(struct file *file, enum kernel_read_file_id id); int (*kernel_read_file)(struct file *file, enum kernel_read_file_id id);
int (*kernel_post_read_file)(struct file *file, char *buf, loff_t size, int (*kernel_post_read_file)(struct file *file, char *buf, loff_t size,
enum kernel_read_file_id id); enum kernel_read_file_id id);
...@@ -1872,6 +1877,7 @@ struct security_hook_heads { ...@@ -1872,6 +1877,7 @@ struct security_hook_heads {
struct hlist_head cred_getsecid; struct hlist_head cred_getsecid;
struct hlist_head kernel_act_as; struct hlist_head kernel_act_as;
struct hlist_head kernel_create_files_as; struct hlist_head kernel_create_files_as;
struct hlist_head kernel_load_data;
struct hlist_head kernel_read_file; struct hlist_head kernel_read_file;
struct hlist_head kernel_post_read_file; struct hlist_head kernel_post_read_file;
struct hlist_head kernel_module_request; struct hlist_head kernel_module_request;
......
...@@ -159,6 +159,27 @@ extern int mmap_min_addr_handler(struct ctl_table *table, int write, ...@@ -159,6 +159,27 @@ extern int mmap_min_addr_handler(struct ctl_table *table, int write,
typedef int (*initxattrs) (struct inode *inode, typedef int (*initxattrs) (struct inode *inode,
const struct xattr *xattr_array, void *fs_data); const struct xattr *xattr_array, void *fs_data);
/* Keep the kernel_load_data_id enum in sync with kernel_read_file_id */
#define __data_id_enumify(ENUM, dummy) LOADING_ ## ENUM,
#define __data_id_stringify(dummy, str) #str,
enum kernel_load_data_id {
__kernel_read_file_id(__data_id_enumify)
};
static const char * const kernel_load_data_str[] = {
__kernel_read_file_id(__data_id_stringify)
};
static inline const char *kernel_load_data_id_str(enum kernel_load_data_id id)
{
if ((unsigned)id >= LOADING_MAX_ID)
return kernel_load_data_str[LOADING_UNKNOWN];
return kernel_load_data_str[id];
}
#ifdef CONFIG_SECURITY #ifdef CONFIG_SECURITY
struct security_mnt_opts { struct security_mnt_opts {
...@@ -320,6 +341,7 @@ void security_cred_getsecid(const struct cred *c, u32 *secid); ...@@ -320,6 +341,7 @@ void security_cred_getsecid(const struct cred *c, u32 *secid);
int security_kernel_act_as(struct cred *new, u32 secid); 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_create_files_as(struct cred *new, struct inode *inode);
int security_kernel_module_request(char *kmod_name); int security_kernel_module_request(char *kmod_name);
int security_kernel_load_data(enum kernel_load_data_id id);
int security_kernel_read_file(struct file *file, enum kernel_read_file_id id); int security_kernel_read_file(struct file *file, enum kernel_read_file_id id);
int security_kernel_post_read_file(struct file *file, char *buf, loff_t size, int security_kernel_post_read_file(struct file *file, char *buf, loff_t size,
enum kernel_read_file_id id); enum kernel_read_file_id id);
...@@ -909,6 +931,11 @@ static inline int security_kernel_module_request(char *kmod_name) ...@@ -909,6 +931,11 @@ static inline int security_kernel_module_request(char *kmod_name)
return 0; return 0;
} }
static inline int security_kernel_load_data(enum kernel_load_data_id id)
{
return 0;
}
static inline int security_kernel_read_file(struct file *file, static inline int security_kernel_read_file(struct file *file,
enum kernel_read_file_id id) enum kernel_read_file_id id)
{ {
......
...@@ -1056,6 +1056,11 @@ int security_kernel_post_read_file(struct file *file, char *buf, loff_t size, ...@@ -1056,6 +1056,11 @@ int security_kernel_post_read_file(struct file *file, char *buf, loff_t size,
} }
EXPORT_SYMBOL_GPL(security_kernel_post_read_file); EXPORT_SYMBOL_GPL(security_kernel_post_read_file);
int security_kernel_load_data(enum kernel_load_data_id id)
{
return call_int_hook(kernel_load_data, 0, id);
}
int security_task_fix_setuid(struct cred *new, const struct cred *old, int security_task_fix_setuid(struct cred *new, const struct cred *old,
int flags) int flags)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment