diff options
author | Mimi Zohar <zohar@linux.vnet.ibm.com> | 2018-07-13 14:05:56 -0400 |
---|---|---|
committer | James Morris <james.morris@microsoft.com> | 2018-07-16 15:31:57 -0400 |
commit | 377179cd28cd417dcfb4396edb824533431e607e (patch) | |
tree | 65c6670521648ce4a307cae400786f442952c532 | |
parent | 57b54d74dd5c559bd35f2affaf11d8828aaf5733 (diff) |
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: Mimi 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: Serge Hallyn <serge@hallyn.com>
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: James Morris <james.morris@microsoft.com>
-rw-r--r-- | include/linux/lsm_hooks.h | 6 | ||||
-rw-r--r-- | include/linux/security.h | 27 | ||||
-rw-r--r-- | security/security.c | 5 |
3 files changed, 38 insertions, 0 deletions
diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 8f1131c8dd54..a08bc2587b96 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h | |||
@@ -576,6 +576,10 @@ | |||
576 | * userspace to load a kernel module with the given name. | 576 | * userspace to load a kernel module with the given name. |
577 | * @kmod_name name of the module requested by the kernel | 577 | * @kmod_name name of the module requested by the kernel |
578 | * Return 0 if successful. | 578 | * Return 0 if successful. |
579 | * @kernel_load_data: | ||
580 | * Load data provided by userspace. | ||
581 | * @id kernel load data identifier | ||
582 | * Return 0 if permission is granted. | ||
579 | * @kernel_read_file: | 583 | * @kernel_read_file: |
580 | * Read a file specified by userspace. | 584 | * Read a file specified by userspace. |
581 | * @file contains the file structure pointing to the file being read | 585 | * @file contains the file structure pointing to the file being read |
@@ -1582,6 +1586,7 @@ union security_list_options { | |||
1582 | int (*kernel_act_as)(struct cred *new, u32 secid); | 1586 | int (*kernel_act_as)(struct cred *new, u32 secid); |
1583 | int (*kernel_create_files_as)(struct cred *new, struct inode *inode); | 1587 | int (*kernel_create_files_as)(struct cred *new, struct inode *inode); |
1584 | int (*kernel_module_request)(char *kmod_name); | 1588 | int (*kernel_module_request)(char *kmod_name); |
1589 | int (*kernel_load_data)(enum kernel_load_data_id id); | ||
1585 | int (*kernel_read_file)(struct file *file, enum kernel_read_file_id id); | 1590 | int (*kernel_read_file)(struct file *file, enum kernel_read_file_id id); |
1586 | int (*kernel_post_read_file)(struct file *file, char *buf, loff_t size, | 1591 | int (*kernel_post_read_file)(struct file *file, char *buf, loff_t size, |
1587 | enum kernel_read_file_id id); | 1592 | enum kernel_read_file_id id); |
@@ -1872,6 +1877,7 @@ struct security_hook_heads { | |||
1872 | struct hlist_head cred_getsecid; | 1877 | struct hlist_head cred_getsecid; |
1873 | struct hlist_head kernel_act_as; | 1878 | struct hlist_head kernel_act_as; |
1874 | struct hlist_head kernel_create_files_as; | 1879 | struct hlist_head kernel_create_files_as; |
1880 | struct hlist_head kernel_load_data; | ||
1875 | struct hlist_head kernel_read_file; | 1881 | struct hlist_head kernel_read_file; |
1876 | struct hlist_head kernel_post_read_file; | 1882 | struct hlist_head kernel_post_read_file; |
1877 | struct hlist_head kernel_module_request; | 1883 | struct hlist_head kernel_module_request; |
diff --git a/include/linux/security.h b/include/linux/security.h index 63030c85ee19..3410acfe139c 100644 --- a/include/linux/security.h +++ b/include/linux/security.h | |||
@@ -159,6 +159,27 @@ extern int mmap_min_addr_handler(struct ctl_table *table, int write, | |||
159 | typedef int (*initxattrs) (struct inode *inode, | 159 | typedef int (*initxattrs) (struct inode *inode, |
160 | const struct xattr *xattr_array, void *fs_data); | 160 | const struct xattr *xattr_array, void *fs_data); |
161 | 161 | ||
162 | |||
163 | /* Keep the kernel_load_data_id enum in sync with kernel_read_file_id */ | ||
164 | #define __data_id_enumify(ENUM, dummy) LOADING_ ## ENUM, | ||
165 | #define __data_id_stringify(dummy, str) #str, | ||
166 | |||
167 | enum kernel_load_data_id { | ||
168 | __kernel_read_file_id(__data_id_enumify) | ||
169 | }; | ||
170 | |||
171 | static const char * const kernel_load_data_str[] = { | ||
172 | __kernel_read_file_id(__data_id_stringify) | ||
173 | }; | ||
174 | |||
175 | static inline const char *kernel_load_data_id_str(enum kernel_load_data_id id) | ||
176 | { | ||
177 | if ((unsigned)id >= LOADING_MAX_ID) | ||
178 | return kernel_load_data_str[LOADING_UNKNOWN]; | ||
179 | |||
180 | return kernel_load_data_str[id]; | ||
181 | } | ||
182 | |||
162 | #ifdef CONFIG_SECURITY | 183 | #ifdef CONFIG_SECURITY |
163 | 184 | ||
164 | struct security_mnt_opts { | 185 | struct security_mnt_opts { |
@@ -320,6 +341,7 @@ void security_cred_getsecid(const struct cred *c, u32 *secid); | |||
320 | int security_kernel_act_as(struct cred *new, u32 secid); | 341 | int security_kernel_act_as(struct cred *new, u32 secid); |
321 | int security_kernel_create_files_as(struct cred *new, struct inode *inode); | 342 | int security_kernel_create_files_as(struct cred *new, struct inode *inode); |
322 | int security_kernel_module_request(char *kmod_name); | 343 | int security_kernel_module_request(char *kmod_name); |
344 | int security_kernel_load_data(enum kernel_load_data_id id); | ||
323 | int security_kernel_read_file(struct file *file, enum kernel_read_file_id id); | 345 | int security_kernel_read_file(struct file *file, enum kernel_read_file_id id); |
324 | int security_kernel_post_read_file(struct file *file, char *buf, loff_t size, | 346 | int security_kernel_post_read_file(struct file *file, char *buf, loff_t size, |
325 | enum kernel_read_file_id id); | 347 | enum kernel_read_file_id id); |
@@ -909,6 +931,11 @@ static inline int security_kernel_module_request(char *kmod_name) | |||
909 | return 0; | 931 | return 0; |
910 | } | 932 | } |
911 | 933 | ||
934 | static inline int security_kernel_load_data(enum kernel_load_data_id id) | ||
935 | { | ||
936 | return 0; | ||
937 | } | ||
938 | |||
912 | static inline int security_kernel_read_file(struct file *file, | 939 | static inline int security_kernel_read_file(struct file *file, |
913 | enum kernel_read_file_id id) | 940 | enum kernel_read_file_id id) |
914 | { | 941 | { |
diff --git a/security/security.c b/security/security.c index 68f46d849abe..c2de2f134854 100644 --- a/security/security.c +++ b/security/security.c | |||
@@ -1056,6 +1056,11 @@ int security_kernel_post_read_file(struct file *file, char *buf, loff_t size, | |||
1056 | } | 1056 | } |
1057 | EXPORT_SYMBOL_GPL(security_kernel_post_read_file); | 1057 | EXPORT_SYMBOL_GPL(security_kernel_post_read_file); |
1058 | 1058 | ||
1059 | int security_kernel_load_data(enum kernel_load_data_id id) | ||
1060 | { | ||
1061 | return call_int_hook(kernel_load_data, 0, id); | ||
1062 | } | ||
1063 | |||
1059 | int security_task_fix_setuid(struct cred *new, const struct cred *old, | 1064 | int security_task_fix_setuid(struct cred *new, const struct cred *old, |
1060 | int flags) | 1065 | int flags) |
1061 | { | 1066 | { |