diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2017-05-03 11:50:52 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-05-03 11:50:52 -0400 |
commit | 0302e28dee643932ee7b3c112ebccdbb9f8ec32c (patch) | |
tree | 405d4cb3f772ef069ed7f291adc4b74a4e73346e /security/selinux | |
parent | 89c9fea3c8034cdb2fd745f551cde0b507fd6893 (diff) | |
parent | 8979b02aaf1d6de8d52cc143aa4da961ed32e5a2 (diff) |
Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security
Pull security subsystem updates from James Morris:
"Highlights:
IMA:
- provide ">" and "<" operators for fowner/uid/euid rules
KEYS:
- add a system blacklist keyring
- add KEYCTL_RESTRICT_KEYRING, exposes keyring link restriction
functionality to userland via keyctl()
LSM:
- harden LSM API with __ro_after_init
- add prlmit security hook, implement for SELinux
- revive security_task_alloc hook
TPM:
- implement contextual TPM command 'spaces'"
* 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (98 commits)
tpm: Fix reference count to main device
tpm_tis: convert to using locality callbacks
tpm: fix handling of the TPM 2.0 event logs
tpm_crb: remove a cruft constant
keys: select CONFIG_CRYPTO when selecting DH / KDF
apparmor: Make path_max parameter readonly
apparmor: fix parameters so that the permission test is bypassed at boot
apparmor: fix invalid reference to index variable of iterator line 836
apparmor: use SHASH_DESC_ON_STACK
security/apparmor/lsm.c: set debug messages
apparmor: fix boolreturn.cocci warnings
Smack: Use GFP_KERNEL for smk_netlbl_mls().
smack: fix double free in smack_parse_opts_str()
KEYS: add SP800-56A KDF support for DH
KEYS: Keyring asymmetric key restrict method with chaining
KEYS: Restrict asymmetric key linkage using a specific keychain
KEYS: Add a lookup_restriction function for the asymmetric key type
KEYS: Add KEYCTL_RESTRICT_KEYRING
KEYS: Consistent ordering for __key_link_begin and restrict check
KEYS: Add an optional lookup_restriction hook to key_type
...
Diffstat (limited to 'security/selinux')
-rw-r--r-- | security/selinux/Kconfig | 6 | ||||
-rw-r--r-- | security/selinux/hooks.c | 26 | ||||
-rw-r--r-- | security/selinux/include/classmap.h | 2 | ||||
-rw-r--r-- | security/selinux/nlmsgtab.c | 10 | ||||
-rw-r--r-- | security/selinux/selinuxfs.c | 8 | ||||
-rw-r--r-- | security/selinux/ss/conditional.c | 14 | ||||
-rw-r--r-- | security/selinux/ss/hashtab.c | 10 | ||||
-rw-r--r-- | security/selinux/ss/policydb.c | 59 | ||||
-rw-r--r-- | security/selinux/ss/services.c | 2 | ||||
-rw-r--r-- | security/selinux/ss/sidtab.c | 6 |
10 files changed, 81 insertions, 62 deletions
diff --git a/security/selinux/Kconfig b/security/selinux/Kconfig index ea7e3efbe0f7..8af7a690eb40 100644 --- a/security/selinux/Kconfig +++ b/security/selinux/Kconfig | |||
@@ -40,6 +40,7 @@ config SECURITY_SELINUX_BOOTPARAM_VALUE | |||
40 | config SECURITY_SELINUX_DISABLE | 40 | config SECURITY_SELINUX_DISABLE |
41 | bool "NSA SELinux runtime disable" | 41 | bool "NSA SELinux runtime disable" |
42 | depends on SECURITY_SELINUX | 42 | depends on SECURITY_SELINUX |
43 | select SECURITY_WRITABLE_HOOKS | ||
43 | default n | 44 | default n |
44 | help | 45 | help |
45 | This option enables writing to a selinuxfs node 'disable', which | 46 | This option enables writing to a selinuxfs node 'disable', which |
@@ -50,6 +51,11 @@ config SECURITY_SELINUX_DISABLE | |||
50 | portability across platforms where boot parameters are difficult | 51 | portability across platforms where boot parameters are difficult |
51 | to employ. | 52 | to employ. |
52 | 53 | ||
54 | NOTE: selecting this option will disable the '__ro_after_init' | ||
55 | kernel hardening feature for security hooks. Please consider | ||
56 | using the selinux=0 boot parameter instead of enabling this | ||
57 | option. | ||
58 | |||
53 | If you are unsure how to answer this question, answer N. | 59 | If you are unsure how to answer this question, answer N. |
54 | 60 | ||
55 | config SECURITY_SELINUX_DEVELOP | 61 | config SECURITY_SELINUX_DEVELOP |
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 0c2ac318aa7f..e67a526d1f30 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c | |||
@@ -3920,6 +3920,21 @@ static int selinux_task_getioprio(struct task_struct *p) | |||
3920 | PROCESS__GETSCHED, NULL); | 3920 | PROCESS__GETSCHED, NULL); |
3921 | } | 3921 | } |
3922 | 3922 | ||
3923 | int selinux_task_prlimit(const struct cred *cred, const struct cred *tcred, | ||
3924 | unsigned int flags) | ||
3925 | { | ||
3926 | u32 av = 0; | ||
3927 | |||
3928 | if (!flags) | ||
3929 | return 0; | ||
3930 | if (flags & LSM_PRLIMIT_WRITE) | ||
3931 | av |= PROCESS__SETRLIMIT; | ||
3932 | if (flags & LSM_PRLIMIT_READ) | ||
3933 | av |= PROCESS__GETRLIMIT; | ||
3934 | return avc_has_perm(cred_sid(cred), cred_sid(tcred), | ||
3935 | SECCLASS_PROCESS, av, NULL); | ||
3936 | } | ||
3937 | |||
3923 | static int selinux_task_setrlimit(struct task_struct *p, unsigned int resource, | 3938 | static int selinux_task_setrlimit(struct task_struct *p, unsigned int resource, |
3924 | struct rlimit *new_rlim) | 3939 | struct rlimit *new_rlim) |
3925 | { | 3940 | { |
@@ -4352,10 +4367,18 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in | |||
4352 | u32 sid, node_perm; | 4367 | u32 sid, node_perm; |
4353 | 4368 | ||
4354 | if (family == PF_INET) { | 4369 | if (family == PF_INET) { |
4370 | if (addrlen < sizeof(struct sockaddr_in)) { | ||
4371 | err = -EINVAL; | ||
4372 | goto out; | ||
4373 | } | ||
4355 | addr4 = (struct sockaddr_in *)address; | 4374 | addr4 = (struct sockaddr_in *)address; |
4356 | snum = ntohs(addr4->sin_port); | 4375 | snum = ntohs(addr4->sin_port); |
4357 | addrp = (char *)&addr4->sin_addr.s_addr; | 4376 | addrp = (char *)&addr4->sin_addr.s_addr; |
4358 | } else { | 4377 | } else { |
4378 | if (addrlen < SIN6_LEN_RFC2133) { | ||
4379 | err = -EINVAL; | ||
4380 | goto out; | ||
4381 | } | ||
4359 | addr6 = (struct sockaddr_in6 *)address; | 4382 | addr6 = (struct sockaddr_in6 *)address; |
4360 | snum = ntohs(addr6->sin6_port); | 4383 | snum = ntohs(addr6->sin6_port); |
4361 | addrp = (char *)&addr6->sin6_addr.s6_addr; | 4384 | addrp = (char *)&addr6->sin6_addr.s6_addr; |
@@ -6108,7 +6131,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer) | |||
6108 | 6131 | ||
6109 | #endif | 6132 | #endif |
6110 | 6133 | ||
6111 | static struct security_hook_list selinux_hooks[] = { | 6134 | static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = { |
6112 | LSM_HOOK_INIT(binder_set_context_mgr, selinux_binder_set_context_mgr), | 6135 | LSM_HOOK_INIT(binder_set_context_mgr, selinux_binder_set_context_mgr), |
6113 | LSM_HOOK_INIT(binder_transaction, selinux_binder_transaction), | 6136 | LSM_HOOK_INIT(binder_transaction, selinux_binder_transaction), |
6114 | LSM_HOOK_INIT(binder_transfer_binder, selinux_binder_transfer_binder), | 6137 | LSM_HOOK_INIT(binder_transfer_binder, selinux_binder_transfer_binder), |
@@ -6206,6 +6229,7 @@ static struct security_hook_list selinux_hooks[] = { | |||
6206 | LSM_HOOK_INIT(task_setnice, selinux_task_setnice), | 6229 | LSM_HOOK_INIT(task_setnice, selinux_task_setnice), |
6207 | LSM_HOOK_INIT(task_setioprio, selinux_task_setioprio), | 6230 | LSM_HOOK_INIT(task_setioprio, selinux_task_setioprio), |
6208 | LSM_HOOK_INIT(task_getioprio, selinux_task_getioprio), | 6231 | LSM_HOOK_INIT(task_getioprio, selinux_task_getioprio), |
6232 | LSM_HOOK_INIT(task_prlimit, selinux_task_prlimit), | ||
6209 | LSM_HOOK_INIT(task_setrlimit, selinux_task_setrlimit), | 6233 | LSM_HOOK_INIT(task_setrlimit, selinux_task_setrlimit), |
6210 | LSM_HOOK_INIT(task_setscheduler, selinux_task_setscheduler), | 6234 | LSM_HOOK_INIT(task_setscheduler, selinux_task_setscheduler), |
6211 | LSM_HOOK_INIT(task_getscheduler, selinux_task_getscheduler), | 6235 | LSM_HOOK_INIT(task_getscheduler, selinux_task_getscheduler), |
diff --git a/security/selinux/include/classmap.h b/security/selinux/include/classmap.h index d429c4a1c551..1e0cc9b5de20 100644 --- a/security/selinux/include/classmap.h +++ b/security/selinux/include/classmap.h | |||
@@ -47,7 +47,7 @@ struct security_class_mapping secclass_map[] = { | |||
47 | "getattr", "setexec", "setfscreate", "noatsecure", "siginh", | 47 | "getattr", "setexec", "setfscreate", "noatsecure", "siginh", |
48 | "setrlimit", "rlimitinh", "dyntransition", "setcurrent", | 48 | "setrlimit", "rlimitinh", "dyntransition", "setcurrent", |
49 | "execmem", "execstack", "execheap", "setkeycreate", | 49 | "execmem", "execstack", "execheap", "setkeycreate", |
50 | "setsockcreate", NULL } }, | 50 | "setsockcreate", "getrlimit", NULL } }, |
51 | { "system", | 51 | { "system", |
52 | { "ipc_info", "syslog_read", "syslog_mod", | 52 | { "ipc_info", "syslog_read", "syslog_mod", |
53 | "syslog_console", "module_request", "module_load", NULL } }, | 53 | "syslog_console", "module_request", "module_load", NULL } }, |
diff --git a/security/selinux/nlmsgtab.c b/security/selinux/nlmsgtab.c index 8e67bb4c9cab..5aeaf30b7a13 100644 --- a/security/selinux/nlmsgtab.c +++ b/security/selinux/nlmsgtab.c | |||
@@ -28,7 +28,7 @@ struct nlmsg_perm { | |||
28 | u32 perm; | 28 | u32 perm; |
29 | }; | 29 | }; |
30 | 30 | ||
31 | static struct nlmsg_perm nlmsg_route_perms[] = | 31 | static const struct nlmsg_perm nlmsg_route_perms[] = |
32 | { | 32 | { |
33 | { RTM_NEWLINK, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, | 33 | { RTM_NEWLINK, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, |
34 | { RTM_DELLINK, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, | 34 | { RTM_DELLINK, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, |
@@ -81,7 +81,7 @@ static struct nlmsg_perm nlmsg_route_perms[] = | |||
81 | { RTM_GETSTATS, NETLINK_ROUTE_SOCKET__NLMSG_READ }, | 81 | { RTM_GETSTATS, NETLINK_ROUTE_SOCKET__NLMSG_READ }, |
82 | }; | 82 | }; |
83 | 83 | ||
84 | static struct nlmsg_perm nlmsg_tcpdiag_perms[] = | 84 | static const struct nlmsg_perm nlmsg_tcpdiag_perms[] = |
85 | { | 85 | { |
86 | { TCPDIAG_GETSOCK, NETLINK_TCPDIAG_SOCKET__NLMSG_READ }, | 86 | { TCPDIAG_GETSOCK, NETLINK_TCPDIAG_SOCKET__NLMSG_READ }, |
87 | { DCCPDIAG_GETSOCK, NETLINK_TCPDIAG_SOCKET__NLMSG_READ }, | 87 | { DCCPDIAG_GETSOCK, NETLINK_TCPDIAG_SOCKET__NLMSG_READ }, |
@@ -89,7 +89,7 @@ static struct nlmsg_perm nlmsg_tcpdiag_perms[] = | |||
89 | { SOCK_DESTROY, NETLINK_TCPDIAG_SOCKET__NLMSG_WRITE }, | 89 | { SOCK_DESTROY, NETLINK_TCPDIAG_SOCKET__NLMSG_WRITE }, |
90 | }; | 90 | }; |
91 | 91 | ||
92 | static struct nlmsg_perm nlmsg_xfrm_perms[] = | 92 | static const struct nlmsg_perm nlmsg_xfrm_perms[] = |
93 | { | 93 | { |
94 | { XFRM_MSG_NEWSA, NETLINK_XFRM_SOCKET__NLMSG_WRITE }, | 94 | { XFRM_MSG_NEWSA, NETLINK_XFRM_SOCKET__NLMSG_WRITE }, |
95 | { XFRM_MSG_DELSA, NETLINK_XFRM_SOCKET__NLMSG_WRITE }, | 95 | { XFRM_MSG_DELSA, NETLINK_XFRM_SOCKET__NLMSG_WRITE }, |
@@ -116,7 +116,7 @@ static struct nlmsg_perm nlmsg_xfrm_perms[] = | |||
116 | { XFRM_MSG_MAPPING, NETLINK_XFRM_SOCKET__NLMSG_READ }, | 116 | { XFRM_MSG_MAPPING, NETLINK_XFRM_SOCKET__NLMSG_READ }, |
117 | }; | 117 | }; |
118 | 118 | ||
119 | static struct nlmsg_perm nlmsg_audit_perms[] = | 119 | static const struct nlmsg_perm nlmsg_audit_perms[] = |
120 | { | 120 | { |
121 | { AUDIT_GET, NETLINK_AUDIT_SOCKET__NLMSG_READ }, | 121 | { AUDIT_GET, NETLINK_AUDIT_SOCKET__NLMSG_READ }, |
122 | { AUDIT_SET, NETLINK_AUDIT_SOCKET__NLMSG_WRITE }, | 122 | { AUDIT_SET, NETLINK_AUDIT_SOCKET__NLMSG_WRITE }, |
@@ -137,7 +137,7 @@ static struct nlmsg_perm nlmsg_audit_perms[] = | |||
137 | }; | 137 | }; |
138 | 138 | ||
139 | 139 | ||
140 | static int nlmsg_perm(u16 nlmsg_type, u32 *perm, struct nlmsg_perm *tab, size_t tabsize) | 140 | static int nlmsg_perm(u16 nlmsg_type, u32 *perm, const struct nlmsg_perm *tab, size_t tabsize) |
141 | { | 141 | { |
142 | int i, err = -EINVAL; | 142 | int i, err = -EINVAL; |
143 | 143 | ||
diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c index cb3fd98fb05a..ce7171884223 100644 --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c | |||
@@ -1456,10 +1456,10 @@ static int sel_avc_stats_seq_show(struct seq_file *seq, void *v) | |||
1456 | { | 1456 | { |
1457 | struct avc_cache_stats *st = v; | 1457 | struct avc_cache_stats *st = v; |
1458 | 1458 | ||
1459 | if (v == SEQ_START_TOKEN) | 1459 | if (v == SEQ_START_TOKEN) { |
1460 | seq_printf(seq, "lookups hits misses allocations reclaims " | 1460 | seq_puts(seq, |
1461 | "frees\n"); | 1461 | "lookups hits misses allocations reclaims frees\n"); |
1462 | else { | 1462 | } else { |
1463 | unsigned int lookups = st->lookups; | 1463 | unsigned int lookups = st->lookups; |
1464 | unsigned int misses = st->misses; | 1464 | unsigned int misses = st->misses; |
1465 | unsigned int hits = lookups - misses; | 1465 | unsigned int hits = lookups - misses; |
diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/conditional.c index 34afeadd9e73..771c96afe1d5 100644 --- a/security/selinux/ss/conditional.c +++ b/security/selinux/ss/conditional.c | |||
@@ -176,8 +176,9 @@ void cond_policydb_destroy(struct policydb *p) | |||
176 | int cond_init_bool_indexes(struct policydb *p) | 176 | int cond_init_bool_indexes(struct policydb *p) |
177 | { | 177 | { |
178 | kfree(p->bool_val_to_struct); | 178 | kfree(p->bool_val_to_struct); |
179 | p->bool_val_to_struct = | 179 | p->bool_val_to_struct = kmalloc_array(p->p_bools.nprim, |
180 | kmalloc(p->p_bools.nprim * sizeof(struct cond_bool_datum *), GFP_KERNEL); | 180 | sizeof(*p->bool_val_to_struct), |
181 | GFP_KERNEL); | ||
181 | if (!p->bool_val_to_struct) | 182 | if (!p->bool_val_to_struct) |
182 | return -ENOMEM; | 183 | return -ENOMEM; |
183 | return 0; | 184 | return 0; |
@@ -226,7 +227,7 @@ int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp) | |||
226 | u32 len; | 227 | u32 len; |
227 | int rc; | 228 | int rc; |
228 | 229 | ||
229 | booldatum = kzalloc(sizeof(struct cond_bool_datum), GFP_KERNEL); | 230 | booldatum = kzalloc(sizeof(*booldatum), GFP_KERNEL); |
230 | if (!booldatum) | 231 | if (!booldatum) |
231 | return -ENOMEM; | 232 | return -ENOMEM; |
232 | 233 | ||
@@ -331,7 +332,7 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum | |||
331 | goto err; | 332 | goto err; |
332 | } | 333 | } |
333 | 334 | ||
334 | list = kzalloc(sizeof(struct cond_av_list), GFP_KERNEL); | 335 | list = kzalloc(sizeof(*list), GFP_KERNEL); |
335 | if (!list) { | 336 | if (!list) { |
336 | rc = -ENOMEM; | 337 | rc = -ENOMEM; |
337 | goto err; | 338 | goto err; |
@@ -420,7 +421,7 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp) | |||
420 | goto err; | 421 | goto err; |
421 | 422 | ||
422 | rc = -ENOMEM; | 423 | rc = -ENOMEM; |
423 | expr = kzalloc(sizeof(struct cond_expr), GFP_KERNEL); | 424 | expr = kzalloc(sizeof(*expr), GFP_KERNEL); |
424 | if (!expr) | 425 | if (!expr) |
425 | goto err; | 426 | goto err; |
426 | 427 | ||
@@ -471,7 +472,7 @@ int cond_read_list(struct policydb *p, void *fp) | |||
471 | 472 | ||
472 | for (i = 0; i < len; i++) { | 473 | for (i = 0; i < len; i++) { |
473 | rc = -ENOMEM; | 474 | rc = -ENOMEM; |
474 | node = kzalloc(sizeof(struct cond_node), GFP_KERNEL); | 475 | node = kzalloc(sizeof(*node), GFP_KERNEL); |
475 | if (!node) | 476 | if (!node) |
476 | goto err; | 477 | goto err; |
477 | 478 | ||
@@ -663,5 +664,4 @@ void cond_compute_av(struct avtab *ctab, struct avtab_key *key, | |||
663 | (node->key.specified & AVTAB_XPERMS)) | 664 | (node->key.specified & AVTAB_XPERMS)) |
664 | services_compute_xperms_drivers(xperms, node); | 665 | services_compute_xperms_drivers(xperms, node); |
665 | } | 666 | } |
666 | return; | ||
667 | } | 667 | } |
diff --git a/security/selinux/ss/hashtab.c b/security/selinux/ss/hashtab.c index 2cc496149842..3858706a29fb 100644 --- a/security/selinux/ss/hashtab.c +++ b/security/selinux/ss/hashtab.c | |||
@@ -17,15 +17,15 @@ struct hashtab *hashtab_create(u32 (*hash_value)(struct hashtab *h, const void * | |||
17 | u32 i; | 17 | u32 i; |
18 | 18 | ||
19 | p = kzalloc(sizeof(*p), GFP_KERNEL); | 19 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
20 | if (p == NULL) | 20 | if (!p) |
21 | return p; | 21 | return p; |
22 | 22 | ||
23 | p->size = size; | 23 | p->size = size; |
24 | p->nel = 0; | 24 | p->nel = 0; |
25 | p->hash_value = hash_value; | 25 | p->hash_value = hash_value; |
26 | p->keycmp = keycmp; | 26 | p->keycmp = keycmp; |
27 | p->htable = kmalloc(sizeof(*(p->htable)) * size, GFP_KERNEL); | 27 | p->htable = kmalloc_array(size, sizeof(*p->htable), GFP_KERNEL); |
28 | if (p->htable == NULL) { | 28 | if (!p->htable) { |
29 | kfree(p); | 29 | kfree(p); |
30 | return NULL; | 30 | return NULL; |
31 | } | 31 | } |
@@ -58,7 +58,7 @@ int hashtab_insert(struct hashtab *h, void *key, void *datum) | |||
58 | return -EEXIST; | 58 | return -EEXIST; |
59 | 59 | ||
60 | newnode = kzalloc(sizeof(*newnode), GFP_KERNEL); | 60 | newnode = kzalloc(sizeof(*newnode), GFP_KERNEL); |
61 | if (newnode == NULL) | 61 | if (!newnode) |
62 | return -ENOMEM; | 62 | return -ENOMEM; |
63 | newnode->key = key; | 63 | newnode->key = key; |
64 | newnode->datum = datum; | 64 | newnode->datum = datum; |
@@ -87,7 +87,7 @@ void *hashtab_search(struct hashtab *h, const void *key) | |||
87 | while (cur && h->keycmp(h, key, cur->key) > 0) | 87 | while (cur && h->keycmp(h, key, cur->key) > 0) |
88 | cur = cur->next; | 88 | cur = cur->next; |
89 | 89 | ||
90 | if (cur == NULL || (h->keycmp(h, key, cur->key) != 0)) | 90 | if (!cur || (h->keycmp(h, key, cur->key) != 0)) |
91 | return NULL; | 91 | return NULL; |
92 | 92 | ||
93 | return cur->datum; | 93 | return cur->datum; |
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index 9c92f29a38ea..0080122760ad 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c | |||
@@ -178,10 +178,9 @@ static int roles_init(struct policydb *p) | |||
178 | int rc; | 178 | int rc; |
179 | struct role_datum *role; | 179 | struct role_datum *role; |
180 | 180 | ||
181 | rc = -ENOMEM; | ||
182 | role = kzalloc(sizeof(*role), GFP_KERNEL); | 181 | role = kzalloc(sizeof(*role), GFP_KERNEL); |
183 | if (!role) | 182 | if (!role) |
184 | goto out; | 183 | return -ENOMEM; |
185 | 184 | ||
186 | rc = -EINVAL; | 185 | rc = -EINVAL; |
187 | role->value = ++p->p_roles.nprim; | 186 | role->value = ++p->p_roles.nprim; |
@@ -540,23 +539,23 @@ static int policydb_index(struct policydb *p) | |||
540 | #endif | 539 | #endif |
541 | 540 | ||
542 | rc = -ENOMEM; | 541 | rc = -ENOMEM; |
543 | p->class_val_to_struct = | 542 | p->class_val_to_struct = kcalloc(p->p_classes.nprim, |
544 | kzalloc(p->p_classes.nprim * sizeof(*(p->class_val_to_struct)), | 543 | sizeof(*p->class_val_to_struct), |
545 | GFP_KERNEL); | 544 | GFP_KERNEL); |
546 | if (!p->class_val_to_struct) | 545 | if (!p->class_val_to_struct) |
547 | goto out; | 546 | goto out; |
548 | 547 | ||
549 | rc = -ENOMEM; | 548 | rc = -ENOMEM; |
550 | p->role_val_to_struct = | 549 | p->role_val_to_struct = kcalloc(p->p_roles.nprim, |
551 | kzalloc(p->p_roles.nprim * sizeof(*(p->role_val_to_struct)), | 550 | sizeof(*p->role_val_to_struct), |
552 | GFP_KERNEL); | 551 | GFP_KERNEL); |
553 | if (!p->role_val_to_struct) | 552 | if (!p->role_val_to_struct) |
554 | goto out; | 553 | goto out; |
555 | 554 | ||
556 | rc = -ENOMEM; | 555 | rc = -ENOMEM; |
557 | p->user_val_to_struct = | 556 | p->user_val_to_struct = kcalloc(p->p_users.nprim, |
558 | kzalloc(p->p_users.nprim * sizeof(*(p->user_val_to_struct)), | 557 | sizeof(*p->user_val_to_struct), |
559 | GFP_KERNEL); | 558 | GFP_KERNEL); |
560 | if (!p->user_val_to_struct) | 559 | if (!p->user_val_to_struct) |
561 | goto out; | 560 | goto out; |
562 | 561 | ||
@@ -880,8 +879,6 @@ void policydb_destroy(struct policydb *p) | |||
880 | ebitmap_destroy(&p->filename_trans_ttypes); | 879 | ebitmap_destroy(&p->filename_trans_ttypes); |
881 | ebitmap_destroy(&p->policycaps); | 880 | ebitmap_destroy(&p->policycaps); |
882 | ebitmap_destroy(&p->permissive_map); | 881 | ebitmap_destroy(&p->permissive_map); |
883 | |||
884 | return; | ||
885 | } | 882 | } |
886 | 883 | ||
887 | /* | 884 | /* |
@@ -1120,10 +1117,9 @@ static int perm_read(struct policydb *p, struct hashtab *h, void *fp) | |||
1120 | __le32 buf[2]; | 1117 | __le32 buf[2]; |
1121 | u32 len; | 1118 | u32 len; |
1122 | 1119 | ||
1123 | rc = -ENOMEM; | ||
1124 | perdatum = kzalloc(sizeof(*perdatum), GFP_KERNEL); | 1120 | perdatum = kzalloc(sizeof(*perdatum), GFP_KERNEL); |
1125 | if (!perdatum) | 1121 | if (!perdatum) |
1126 | goto bad; | 1122 | return -ENOMEM; |
1127 | 1123 | ||
1128 | rc = next_entry(buf, fp, sizeof buf); | 1124 | rc = next_entry(buf, fp, sizeof buf); |
1129 | if (rc) | 1125 | if (rc) |
@@ -1154,10 +1150,9 @@ static int common_read(struct policydb *p, struct hashtab *h, void *fp) | |||
1154 | u32 len, nel; | 1150 | u32 len, nel; |
1155 | int i, rc; | 1151 | int i, rc; |
1156 | 1152 | ||
1157 | rc = -ENOMEM; | ||
1158 | comdatum = kzalloc(sizeof(*comdatum), GFP_KERNEL); | 1153 | comdatum = kzalloc(sizeof(*comdatum), GFP_KERNEL); |
1159 | if (!comdatum) | 1154 | if (!comdatum) |
1160 | goto bad; | 1155 | return -ENOMEM; |
1161 | 1156 | ||
1162 | rc = next_entry(buf, fp, sizeof buf); | 1157 | rc = next_entry(buf, fp, sizeof buf); |
1163 | if (rc) | 1158 | if (rc) |
@@ -1320,10 +1315,9 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp) | |||
1320 | u32 len, len2, ncons, nel; | 1315 | u32 len, len2, ncons, nel; |
1321 | int i, rc; | 1316 | int i, rc; |
1322 | 1317 | ||
1323 | rc = -ENOMEM; | ||
1324 | cladatum = kzalloc(sizeof(*cladatum), GFP_KERNEL); | 1318 | cladatum = kzalloc(sizeof(*cladatum), GFP_KERNEL); |
1325 | if (!cladatum) | 1319 | if (!cladatum) |
1326 | goto bad; | 1320 | return -ENOMEM; |
1327 | 1321 | ||
1328 | rc = next_entry(buf, fp, sizeof(u32)*6); | 1322 | rc = next_entry(buf, fp, sizeof(u32)*6); |
1329 | if (rc) | 1323 | if (rc) |
@@ -1414,10 +1408,9 @@ static int role_read(struct policydb *p, struct hashtab *h, void *fp) | |||
1414 | __le32 buf[3]; | 1408 | __le32 buf[3]; |
1415 | u32 len; | 1409 | u32 len; |
1416 | 1410 | ||
1417 | rc = -ENOMEM; | ||
1418 | role = kzalloc(sizeof(*role), GFP_KERNEL); | 1411 | role = kzalloc(sizeof(*role), GFP_KERNEL); |
1419 | if (!role) | 1412 | if (!role) |
1420 | goto bad; | 1413 | return -ENOMEM; |
1421 | 1414 | ||
1422 | if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) | 1415 | if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) |
1423 | to_read = 3; | 1416 | to_read = 3; |
@@ -1471,10 +1464,9 @@ static int type_read(struct policydb *p, struct hashtab *h, void *fp) | |||
1471 | __le32 buf[4]; | 1464 | __le32 buf[4]; |
1472 | u32 len; | 1465 | u32 len; |
1473 | 1466 | ||
1474 | rc = -ENOMEM; | ||
1475 | typdatum = kzalloc(sizeof(*typdatum), GFP_KERNEL); | 1467 | typdatum = kzalloc(sizeof(*typdatum), GFP_KERNEL); |
1476 | if (!typdatum) | 1468 | if (!typdatum) |
1477 | goto bad; | 1469 | return -ENOMEM; |
1478 | 1470 | ||
1479 | if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) | 1471 | if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) |
1480 | to_read = 4; | 1472 | to_read = 4; |
@@ -1546,10 +1538,9 @@ static int user_read(struct policydb *p, struct hashtab *h, void *fp) | |||
1546 | __le32 buf[3]; | 1538 | __le32 buf[3]; |
1547 | u32 len; | 1539 | u32 len; |
1548 | 1540 | ||
1549 | rc = -ENOMEM; | ||
1550 | usrdatum = kzalloc(sizeof(*usrdatum), GFP_KERNEL); | 1541 | usrdatum = kzalloc(sizeof(*usrdatum), GFP_KERNEL); |
1551 | if (!usrdatum) | 1542 | if (!usrdatum) |
1552 | goto bad; | 1543 | return -ENOMEM; |
1553 | 1544 | ||
1554 | if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) | 1545 | if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) |
1555 | to_read = 3; | 1546 | to_read = 3; |
@@ -1597,10 +1588,9 @@ static int sens_read(struct policydb *p, struct hashtab *h, void *fp) | |||
1597 | __le32 buf[2]; | 1588 | __le32 buf[2]; |
1598 | u32 len; | 1589 | u32 len; |
1599 | 1590 | ||
1600 | rc = -ENOMEM; | ||
1601 | levdatum = kzalloc(sizeof(*levdatum), GFP_ATOMIC); | 1591 | levdatum = kzalloc(sizeof(*levdatum), GFP_ATOMIC); |
1602 | if (!levdatum) | 1592 | if (!levdatum) |
1603 | goto bad; | 1593 | return -ENOMEM; |
1604 | 1594 | ||
1605 | rc = next_entry(buf, fp, sizeof buf); | 1595 | rc = next_entry(buf, fp, sizeof buf); |
1606 | if (rc) | 1596 | if (rc) |
@@ -1614,7 +1604,7 @@ static int sens_read(struct policydb *p, struct hashtab *h, void *fp) | |||
1614 | goto bad; | 1604 | goto bad; |
1615 | 1605 | ||
1616 | rc = -ENOMEM; | 1606 | rc = -ENOMEM; |
1617 | levdatum->level = kmalloc(sizeof(struct mls_level), GFP_ATOMIC); | 1607 | levdatum->level = kmalloc(sizeof(*levdatum->level), GFP_ATOMIC); |
1618 | if (!levdatum->level) | 1608 | if (!levdatum->level) |
1619 | goto bad; | 1609 | goto bad; |
1620 | 1610 | ||
@@ -1639,10 +1629,9 @@ static int cat_read(struct policydb *p, struct hashtab *h, void *fp) | |||
1639 | __le32 buf[3]; | 1629 | __le32 buf[3]; |
1640 | u32 len; | 1630 | u32 len; |
1641 | 1631 | ||
1642 | rc = -ENOMEM; | ||
1643 | catdatum = kzalloc(sizeof(*catdatum), GFP_ATOMIC); | 1632 | catdatum = kzalloc(sizeof(*catdatum), GFP_ATOMIC); |
1644 | if (!catdatum) | 1633 | if (!catdatum) |
1645 | goto bad; | 1634 | return -ENOMEM; |
1646 | 1635 | ||
1647 | rc = next_entry(buf, fp, sizeof buf); | 1636 | rc = next_entry(buf, fp, sizeof buf); |
1648 | if (rc) | 1637 | if (rc) |
@@ -1854,7 +1843,7 @@ static int range_read(struct policydb *p, void *fp) | |||
1854 | 1843 | ||
1855 | rc = next_entry(buf, fp, sizeof(u32)); | 1844 | rc = next_entry(buf, fp, sizeof(u32)); |
1856 | if (rc) | 1845 | if (rc) |
1857 | goto out; | 1846 | return rc; |
1858 | 1847 | ||
1859 | nel = le32_to_cpu(buf[0]); | 1848 | nel = le32_to_cpu(buf[0]); |
1860 | for (i = 0; i < nel; i++) { | 1849 | for (i = 0; i < nel; i++) { |
@@ -1931,7 +1920,6 @@ static int filename_trans_read(struct policydb *p, void *fp) | |||
1931 | nel = le32_to_cpu(buf[0]); | 1920 | nel = le32_to_cpu(buf[0]); |
1932 | 1921 | ||
1933 | for (i = 0; i < nel; i++) { | 1922 | for (i = 0; i < nel; i++) { |
1934 | ft = NULL; | ||
1935 | otype = NULL; | 1923 | otype = NULL; |
1936 | name = NULL; | 1924 | name = NULL; |
1937 | 1925 | ||
@@ -2008,7 +1996,7 @@ static int genfs_read(struct policydb *p, void *fp) | |||
2008 | 1996 | ||
2009 | rc = next_entry(buf, fp, sizeof(u32)); | 1997 | rc = next_entry(buf, fp, sizeof(u32)); |
2010 | if (rc) | 1998 | if (rc) |
2011 | goto out; | 1999 | return rc; |
2012 | nel = le32_to_cpu(buf[0]); | 2000 | nel = le32_to_cpu(buf[0]); |
2013 | 2001 | ||
2014 | for (i = 0; i < nel; i++) { | 2002 | for (i = 0; i < nel; i++) { |
@@ -2100,9 +2088,10 @@ static int genfs_read(struct policydb *p, void *fp) | |||
2100 | } | 2088 | } |
2101 | rc = 0; | 2089 | rc = 0; |
2102 | out: | 2090 | out: |
2103 | if (newgenfs) | 2091 | if (newgenfs) { |
2104 | kfree(newgenfs->fstype); | 2092 | kfree(newgenfs->fstype); |
2105 | kfree(newgenfs); | 2093 | kfree(newgenfs); |
2094 | } | ||
2106 | ocontext_destroy(newc, OCON_FSUSE); | 2095 | ocontext_destroy(newc, OCON_FSUSE); |
2107 | 2096 | ||
2108 | return rc; | 2097 | return rc; |
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c index b4aa491a0a23..60d9b0252321 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c | |||
@@ -157,7 +157,7 @@ static int selinux_set_mapping(struct policydb *pol, | |||
157 | } | 157 | } |
158 | 158 | ||
159 | k = 0; | 159 | k = 0; |
160 | while (p_in->perms && p_in->perms[k]) { | 160 | while (p_in->perms[k]) { |
161 | /* An empty permission string skips ahead */ | 161 | /* An empty permission string skips ahead */ |
162 | if (!*p_in->perms[k]) { | 162 | if (!*p_in->perms[k]) { |
163 | k++; | 163 | k++; |
diff --git a/security/selinux/ss/sidtab.c b/security/selinux/ss/sidtab.c index 5840a35155fc..f6915f257486 100644 --- a/security/selinux/ss/sidtab.c +++ b/security/selinux/ss/sidtab.c | |||
@@ -18,7 +18,7 @@ int sidtab_init(struct sidtab *s) | |||
18 | { | 18 | { |
19 | int i; | 19 | int i; |
20 | 20 | ||
21 | s->htable = kmalloc(sizeof(*(s->htable)) * SIDTAB_SIZE, GFP_ATOMIC); | 21 | s->htable = kmalloc_array(SIDTAB_SIZE, sizeof(*s->htable), GFP_ATOMIC); |
22 | if (!s->htable) | 22 | if (!s->htable) |
23 | return -ENOMEM; | 23 | return -ENOMEM; |
24 | for (i = 0; i < SIDTAB_SIZE; i++) | 24 | for (i = 0; i < SIDTAB_SIZE; i++) |
@@ -54,7 +54,7 @@ int sidtab_insert(struct sidtab *s, u32 sid, struct context *context) | |||
54 | } | 54 | } |
55 | 55 | ||
56 | newnode = kmalloc(sizeof(*newnode), GFP_ATOMIC); | 56 | newnode = kmalloc(sizeof(*newnode), GFP_ATOMIC); |
57 | if (newnode == NULL) { | 57 | if (!newnode) { |
58 | rc = -ENOMEM; | 58 | rc = -ENOMEM; |
59 | goto out; | 59 | goto out; |
60 | } | 60 | } |
@@ -98,7 +98,7 @@ static struct context *sidtab_search_core(struct sidtab *s, u32 sid, int force) | |||
98 | if (force && cur && sid == cur->sid && cur->context.len) | 98 | if (force && cur && sid == cur->sid && cur->context.len) |
99 | return &cur->context; | 99 | return &cur->context; |
100 | 100 | ||
101 | if (cur == NULL || sid != cur->sid || cur->context.len) { | 101 | if (!cur || sid != cur->sid || cur->context.len) { |
102 | /* Remap invalid SIDs to the unlabeled SID. */ | 102 | /* Remap invalid SIDs to the unlabeled SID. */ |
103 | sid = SECINITSID_UNLABELED; | 103 | sid = SECINITSID_UNLABELED; |
104 | hvalue = SIDTAB_HASH(sid); | 104 | hvalue = SIDTAB_HASH(sid); |