diff options
author | Paul Mackerras <paulus@samba.org> | 2005-10-30 21:37:12 -0500 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2005-10-30 21:37:12 -0500 |
commit | 23fd07750a789a66fe88cf173d52a18f1a387da4 (patch) | |
tree | 06fdd6df35fdb835abdaa9b754d62f6b84b97250 /security | |
parent | bd787d438a59266af3c9f6351644c85ef1dd21fe (diff) | |
parent | ed28f96ac1960f30f818374d65be71d2fdf811b0 (diff) |
Merge ../linux-2.6 by hand
Diffstat (limited to 'security')
-rw-r--r-- | security/dummy.c | 27 | ||||
-rw-r--r-- | security/keys/key.c | 56 | ||||
-rw-r--r-- | security/keys/keyctl.c | 13 | ||||
-rw-r--r-- | security/keys/keyring.c | 21 | ||||
-rw-r--r-- | security/keys/permission.c | 7 | ||||
-rw-r--r-- | security/keys/process_keys.c | 9 | ||||
-rw-r--r-- | security/keys/user_defined.c | 49 | ||||
-rw-r--r-- | security/selinux/hooks.c | 82 | ||||
-rw-r--r-- | security/selinux/netif.c | 3 | ||||
-rw-r--r-- | security/selinux/selinuxfs.c | 50 | ||||
-rw-r--r-- | security/selinux/ss/conditional.c | 12 | ||||
-rw-r--r-- | security/selinux/ss/ebitmap.c | 9 | ||||
-rw-r--r-- | security/selinux/ss/hashtab.c | 6 | ||||
-rw-r--r-- | security/selinux/ss/policydb.c | 51 | ||||
-rw-r--r-- | security/selinux/ss/services.c | 11 |
15 files changed, 215 insertions, 191 deletions
diff --git a/security/dummy.c b/security/dummy.c index 9623a61dfc76..3ca5f2b828a0 100644 --- a/security/dummy.c +++ b/security/dummy.c | |||
@@ -377,7 +377,7 @@ static int dummy_inode_removexattr (struct dentry *dentry, char *name) | |||
377 | return 0; | 377 | return 0; |
378 | } | 378 | } |
379 | 379 | ||
380 | static int dummy_inode_getsecurity(struct inode *inode, const char *name, void *buffer, size_t size) | 380 | static int dummy_inode_getsecurity(struct inode *inode, const char *name, void *buffer, size_t size, int err) |
381 | { | 381 | { |
382 | return -EOPNOTSUPP; | 382 | return -EOPNOTSUPP; |
383 | } | 383 | } |
@@ -768,7 +768,7 @@ static int dummy_socket_getpeersec(struct socket *sock, char __user *optval, | |||
768 | return -ENOPROTOOPT; | 768 | return -ENOPROTOOPT; |
769 | } | 769 | } |
770 | 770 | ||
771 | static inline int dummy_sk_alloc_security (struct sock *sk, int family, int priority) | 771 | static inline int dummy_sk_alloc_security (struct sock *sk, int family, gfp_t priority) |
772 | { | 772 | { |
773 | return 0; | 773 | return 0; |
774 | } | 774 | } |
@@ -803,6 +803,23 @@ static int dummy_setprocattr(struct task_struct *p, char *name, void *value, siz | |||
803 | return -EINVAL; | 803 | return -EINVAL; |
804 | } | 804 | } |
805 | 805 | ||
806 | #ifdef CONFIG_KEYS | ||
807 | static inline int dummy_key_alloc(struct key *key) | ||
808 | { | ||
809 | return 0; | ||
810 | } | ||
811 | |||
812 | static inline void dummy_key_free(struct key *key) | ||
813 | { | ||
814 | } | ||
815 | |||
816 | static inline int dummy_key_permission(key_ref_t key_ref, | ||
817 | struct task_struct *context, | ||
818 | key_perm_t perm) | ||
819 | { | ||
820 | return 0; | ||
821 | } | ||
822 | #endif /* CONFIG_KEYS */ | ||
806 | 823 | ||
807 | struct security_operations dummy_security_ops; | 824 | struct security_operations dummy_security_ops; |
808 | 825 | ||
@@ -954,5 +971,11 @@ void security_fixup_ops (struct security_operations *ops) | |||
954 | set_to_dummy_if_null(ops, sk_alloc_security); | 971 | set_to_dummy_if_null(ops, sk_alloc_security); |
955 | set_to_dummy_if_null(ops, sk_free_security); | 972 | set_to_dummy_if_null(ops, sk_free_security); |
956 | #endif /* CONFIG_SECURITY_NETWORK */ | 973 | #endif /* CONFIG_SECURITY_NETWORK */ |
974 | #ifdef CONFIG_KEYS | ||
975 | set_to_dummy_if_null(ops, key_alloc); | ||
976 | set_to_dummy_if_null(ops, key_free); | ||
977 | set_to_dummy_if_null(ops, key_permission); | ||
978 | #endif /* CONFIG_KEYS */ | ||
979 | |||
957 | } | 980 | } |
958 | 981 | ||
diff --git a/security/keys/key.c b/security/keys/key.c index 2182be9e9309..ccde17aff616 100644 --- a/security/keys/key.c +++ b/security/keys/key.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* key.c: basic authentication token and access key management | 1 | /* key.c: basic authentication token and access key management |
2 | * | 2 | * |
3 | * Copyright (C) 2004-5 Red Hat, Inc. All Rights Reserved. | 3 | * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved. |
4 | * Written by David Howells (dhowells@redhat.com) | 4 | * Written by David Howells (dhowells@redhat.com) |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or | 6 | * This program is free software; you can redistribute it and/or |
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/init.h> | 13 | #include <linux/init.h> |
14 | #include <linux/sched.h> | 14 | #include <linux/sched.h> |
15 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
16 | #include <linux/security.h> | ||
16 | #include <linux/workqueue.h> | 17 | #include <linux/workqueue.h> |
17 | #include <linux/err.h> | 18 | #include <linux/err.h> |
18 | #include "internal.h" | 19 | #include "internal.h" |
@@ -253,6 +254,7 @@ struct key *key_alloc(struct key_type *type, const char *desc, | |||
253 | struct key_user *user = NULL; | 254 | struct key_user *user = NULL; |
254 | struct key *key; | 255 | struct key *key; |
255 | size_t desclen, quotalen; | 256 | size_t desclen, quotalen; |
257 | int ret; | ||
256 | 258 | ||
257 | key = ERR_PTR(-EINVAL); | 259 | key = ERR_PTR(-EINVAL); |
258 | if (!desc || !*desc) | 260 | if (!desc || !*desc) |
@@ -305,6 +307,7 @@ struct key *key_alloc(struct key_type *type, const char *desc, | |||
305 | key->flags = 0; | 307 | key->flags = 0; |
306 | key->expiry = 0; | 308 | key->expiry = 0; |
307 | key->payload.data = NULL; | 309 | key->payload.data = NULL; |
310 | key->security = NULL; | ||
308 | 311 | ||
309 | if (!not_in_quota) | 312 | if (!not_in_quota) |
310 | key->flags |= 1 << KEY_FLAG_IN_QUOTA; | 313 | key->flags |= 1 << KEY_FLAG_IN_QUOTA; |
@@ -315,16 +318,34 @@ struct key *key_alloc(struct key_type *type, const char *desc, | |||
315 | key->magic = KEY_DEBUG_MAGIC; | 318 | key->magic = KEY_DEBUG_MAGIC; |
316 | #endif | 319 | #endif |
317 | 320 | ||
321 | /* let the security module know about the key */ | ||
322 | ret = security_key_alloc(key); | ||
323 | if (ret < 0) | ||
324 | goto security_error; | ||
325 | |||
318 | /* publish the key by giving it a serial number */ | 326 | /* publish the key by giving it a serial number */ |
319 | atomic_inc(&user->nkeys); | 327 | atomic_inc(&user->nkeys); |
320 | key_alloc_serial(key); | 328 | key_alloc_serial(key); |
321 | 329 | ||
322 | error: | 330 | error: |
323 | return key; | 331 | return key; |
324 | 332 | ||
325 | no_memory_3: | 333 | security_error: |
334 | kfree(key->description); | ||
335 | kmem_cache_free(key_jar, key); | ||
336 | if (!not_in_quota) { | ||
337 | spin_lock(&user->lock); | ||
338 | user->qnkeys--; | ||
339 | user->qnbytes -= quotalen; | ||
340 | spin_unlock(&user->lock); | ||
341 | } | ||
342 | key_user_put(user); | ||
343 | key = ERR_PTR(ret); | ||
344 | goto error; | ||
345 | |||
346 | no_memory_3: | ||
326 | kmem_cache_free(key_jar, key); | 347 | kmem_cache_free(key_jar, key); |
327 | no_memory_2: | 348 | no_memory_2: |
328 | if (!not_in_quota) { | 349 | if (!not_in_quota) { |
329 | spin_lock(&user->lock); | 350 | spin_lock(&user->lock); |
330 | user->qnkeys--; | 351 | user->qnkeys--; |
@@ -332,11 +353,11 @@ struct key *key_alloc(struct key_type *type, const char *desc, | |||
332 | spin_unlock(&user->lock); | 353 | spin_unlock(&user->lock); |
333 | } | 354 | } |
334 | key_user_put(user); | 355 | key_user_put(user); |
335 | no_memory_1: | 356 | no_memory_1: |
336 | key = ERR_PTR(-ENOMEM); | 357 | key = ERR_PTR(-ENOMEM); |
337 | goto error; | 358 | goto error; |
338 | 359 | ||
339 | no_quota: | 360 | no_quota: |
340 | spin_unlock(&user->lock); | 361 | spin_unlock(&user->lock); |
341 | key_user_put(user); | 362 | key_user_put(user); |
342 | key = ERR_PTR(-EDQUOT); | 363 | key = ERR_PTR(-EDQUOT); |
@@ -556,6 +577,8 @@ static void key_cleanup(void *data) | |||
556 | 577 | ||
557 | key_check(key); | 578 | key_check(key); |
558 | 579 | ||
580 | security_key_free(key); | ||
581 | |||
559 | /* deal with the user's key tracking and quota */ | 582 | /* deal with the user's key tracking and quota */ |
560 | if (test_bit(KEY_FLAG_IN_QUOTA, &key->flags)) { | 583 | if (test_bit(KEY_FLAG_IN_QUOTA, &key->flags)) { |
561 | spin_lock(&key->user->lock); | 584 | spin_lock(&key->user->lock); |
@@ -700,8 +723,8 @@ static inline key_ref_t __key_update(key_ref_t key_ref, | |||
700 | int ret; | 723 | int ret; |
701 | 724 | ||
702 | /* need write permission on the key to update it */ | 725 | /* need write permission on the key to update it */ |
703 | ret = -EACCES; | 726 | ret = key_permission(key_ref, KEY_WRITE); |
704 | if (!key_permission(key_ref, KEY_WRITE)) | 727 | if (ret < 0) |
705 | goto error; | 728 | goto error; |
706 | 729 | ||
707 | ret = -EEXIST; | 730 | ret = -EEXIST; |
@@ -711,7 +734,6 @@ static inline key_ref_t __key_update(key_ref_t key_ref, | |||
711 | down_write(&key->sem); | 734 | down_write(&key->sem); |
712 | 735 | ||
713 | ret = key->type->update(key, payload, plen); | 736 | ret = key->type->update(key, payload, plen); |
714 | |||
715 | if (ret == 0) | 737 | if (ret == 0) |
716 | /* updating a negative key instantiates it */ | 738 | /* updating a negative key instantiates it */ |
717 | clear_bit(KEY_FLAG_NEGATIVE, &key->flags); | 739 | clear_bit(KEY_FLAG_NEGATIVE, &key->flags); |
@@ -768,9 +790,11 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref, | |||
768 | 790 | ||
769 | /* if we're going to allocate a new key, we're going to have | 791 | /* if we're going to allocate a new key, we're going to have |
770 | * to modify the keyring */ | 792 | * to modify the keyring */ |
771 | key_ref = ERR_PTR(-EACCES); | 793 | ret = key_permission(keyring_ref, KEY_WRITE); |
772 | if (!key_permission(keyring_ref, KEY_WRITE)) | 794 | if (ret < 0) { |
795 | key_ref = ERR_PTR(ret); | ||
773 | goto error_3; | 796 | goto error_3; |
797 | } | ||
774 | 798 | ||
775 | /* search for an existing key of the same type and description in the | 799 | /* search for an existing key of the same type and description in the |
776 | * destination keyring | 800 | * destination keyring |
@@ -780,8 +804,8 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref, | |||
780 | goto found_matching_key; | 804 | goto found_matching_key; |
781 | 805 | ||
782 | /* decide on the permissions we want */ | 806 | /* decide on the permissions we want */ |
783 | perm = KEY_POS_VIEW | KEY_POS_SEARCH | KEY_POS_LINK; | 807 | perm = KEY_POS_VIEW | KEY_POS_SEARCH | KEY_POS_LINK | KEY_POS_SETATTR; |
784 | perm |= KEY_USR_VIEW | KEY_USR_SEARCH | KEY_USR_LINK; | 808 | perm |= KEY_USR_VIEW | KEY_USR_SEARCH | KEY_USR_LINK | KEY_USR_SETATTR; |
785 | 809 | ||
786 | if (ktype->read) | 810 | if (ktype->read) |
787 | perm |= KEY_POS_READ | KEY_USR_READ; | 811 | perm |= KEY_POS_READ | KEY_USR_READ; |
@@ -840,16 +864,16 @@ int key_update(key_ref_t key_ref, const void *payload, size_t plen) | |||
840 | key_check(key); | 864 | key_check(key); |
841 | 865 | ||
842 | /* the key must be writable */ | 866 | /* the key must be writable */ |
843 | ret = -EACCES; | 867 | ret = key_permission(key_ref, KEY_WRITE); |
844 | if (!key_permission(key_ref, KEY_WRITE)) | 868 | if (ret < 0) |
845 | goto error; | 869 | goto error; |
846 | 870 | ||
847 | /* attempt to update it if supported */ | 871 | /* attempt to update it if supported */ |
848 | ret = -EOPNOTSUPP; | 872 | ret = -EOPNOTSUPP; |
849 | if (key->type->update) { | 873 | if (key->type->update) { |
850 | down_write(&key->sem); | 874 | down_write(&key->sem); |
851 | ret = key->type->update(key, payload, plen); | ||
852 | 875 | ||
876 | ret = key->type->update(key, payload, plen); | ||
853 | if (ret == 0) | 877 | if (ret == 0) |
854 | /* updating a negative key instantiates it */ | 878 | /* updating a negative key instantiates it */ |
855 | clear_bit(KEY_FLAG_NEGATIVE, &key->flags); | 879 | clear_bit(KEY_FLAG_NEGATIVE, &key->flags); |
diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c index 4c670ee6acf9..b7a468fabdf9 100644 --- a/security/keys/keyctl.c +++ b/security/keys/keyctl.c | |||
@@ -624,8 +624,8 @@ long keyctl_keyring_search(key_serial_t ringid, | |||
624 | 624 | ||
625 | /* link the resulting key to the destination keyring if we can */ | 625 | /* link the resulting key to the destination keyring if we can */ |
626 | if (dest_ref) { | 626 | if (dest_ref) { |
627 | ret = -EACCES; | 627 | ret = key_permission(key_ref, KEY_LINK); |
628 | if (!key_permission(key_ref, KEY_LINK)) | 628 | if (ret < 0) |
629 | goto error6; | 629 | goto error6; |
630 | 630 | ||
631 | ret = key_link(key_ref_to_ptr(dest_ref), key_ref_to_ptr(key_ref)); | 631 | ret = key_link(key_ref_to_ptr(dest_ref), key_ref_to_ptr(key_ref)); |
@@ -676,8 +676,11 @@ long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen) | |||
676 | key = key_ref_to_ptr(key_ref); | 676 | key = key_ref_to_ptr(key_ref); |
677 | 677 | ||
678 | /* see if we can read it directly */ | 678 | /* see if we can read it directly */ |
679 | if (key_permission(key_ref, KEY_READ)) | 679 | ret = key_permission(key_ref, KEY_READ); |
680 | if (ret == 0) | ||
680 | goto can_read_key; | 681 | goto can_read_key; |
682 | if (ret != -EACCES) | ||
683 | goto error; | ||
681 | 684 | ||
682 | /* we can't; see if it's searchable from this process's keyrings | 685 | /* we can't; see if it's searchable from this process's keyrings |
683 | * - we automatically take account of the fact that it may be | 686 | * - we automatically take account of the fact that it may be |
@@ -726,7 +729,7 @@ long keyctl_chown_key(key_serial_t id, uid_t uid, gid_t gid) | |||
726 | if (uid == (uid_t) -1 && gid == (gid_t) -1) | 729 | if (uid == (uid_t) -1 && gid == (gid_t) -1) |
727 | goto error; | 730 | goto error; |
728 | 731 | ||
729 | key_ref = lookup_user_key(NULL, id, 1, 1, 0); | 732 | key_ref = lookup_user_key(NULL, id, 1, 1, KEY_SETATTR); |
730 | if (IS_ERR(key_ref)) { | 733 | if (IS_ERR(key_ref)) { |
731 | ret = PTR_ERR(key_ref); | 734 | ret = PTR_ERR(key_ref); |
732 | goto error; | 735 | goto error; |
@@ -786,7 +789,7 @@ long keyctl_setperm_key(key_serial_t id, key_perm_t perm) | |||
786 | if (perm & ~(KEY_POS_ALL | KEY_USR_ALL | KEY_GRP_ALL | KEY_OTH_ALL)) | 789 | if (perm & ~(KEY_POS_ALL | KEY_USR_ALL | KEY_GRP_ALL | KEY_OTH_ALL)) |
787 | goto error; | 790 | goto error; |
788 | 791 | ||
789 | key_ref = lookup_user_key(NULL, id, 1, 1, 0); | 792 | key_ref = lookup_user_key(NULL, id, 1, 1, KEY_SETATTR); |
790 | if (IS_ERR(key_ref)) { | 793 | if (IS_ERR(key_ref)) { |
791 | ret = PTR_ERR(key_ref); | 794 | ret = PTR_ERR(key_ref); |
792 | goto error; | 795 | goto error; |
diff --git a/security/keys/keyring.c b/security/keys/keyring.c index 0639396dd441..e1cc4dd79012 100644 --- a/security/keys/keyring.c +++ b/security/keys/keyring.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/init.h> | 13 | #include <linux/init.h> |
14 | #include <linux/sched.h> | 14 | #include <linux/sched.h> |
15 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
16 | #include <linux/security.h> | ||
16 | #include <linux/seq_file.h> | 17 | #include <linux/seq_file.h> |
17 | #include <linux/err.h> | 18 | #include <linux/err.h> |
18 | #include <asm/uaccess.h> | 19 | #include <asm/uaccess.h> |
@@ -309,7 +310,9 @@ struct key *keyring_alloc(const char *description, uid_t uid, gid_t gid, | |||
309 | int ret; | 310 | int ret; |
310 | 311 | ||
311 | keyring = key_alloc(&key_type_keyring, description, | 312 | keyring = key_alloc(&key_type_keyring, description, |
312 | uid, gid, KEY_POS_ALL | KEY_USR_ALL, not_in_quota); | 313 | uid, gid, |
314 | (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_ALL, | ||
315 | not_in_quota); | ||
313 | 316 | ||
314 | if (!IS_ERR(keyring)) { | 317 | if (!IS_ERR(keyring)) { |
315 | ret = key_instantiate_and_link(keyring, NULL, 0, dest, NULL); | 318 | ret = key_instantiate_and_link(keyring, NULL, 0, dest, NULL); |
@@ -359,9 +362,11 @@ key_ref_t keyring_search_aux(key_ref_t keyring_ref, | |||
359 | key_check(keyring); | 362 | key_check(keyring); |
360 | 363 | ||
361 | /* top keyring must have search permission to begin the search */ | 364 | /* top keyring must have search permission to begin the search */ |
362 | key_ref = ERR_PTR(-EACCES); | 365 | err = key_task_permission(keyring_ref, context, KEY_SEARCH); |
363 | if (!key_task_permission(keyring_ref, context, KEY_SEARCH)) | 366 | if (err < 0) { |
367 | key_ref = ERR_PTR(err); | ||
364 | goto error; | 368 | goto error; |
369 | } | ||
365 | 370 | ||
366 | key_ref = ERR_PTR(-ENOTDIR); | 371 | key_ref = ERR_PTR(-ENOTDIR); |
367 | if (keyring->type != &key_type_keyring) | 372 | if (keyring->type != &key_type_keyring) |
@@ -402,8 +407,8 @@ descend: | |||
402 | continue; | 407 | continue; |
403 | 408 | ||
404 | /* key must have search permissions */ | 409 | /* key must have search permissions */ |
405 | if (!key_task_permission(make_key_ref(key, possessed), | 410 | if (key_task_permission(make_key_ref(key, possessed), |
406 | context, KEY_SEARCH)) | 411 | context, KEY_SEARCH) < 0) |
407 | continue; | 412 | continue; |
408 | 413 | ||
409 | /* we set a different error code if we find a negative key */ | 414 | /* we set a different error code if we find a negative key */ |
@@ -430,7 +435,7 @@ ascend: | |||
430 | continue; | 435 | continue; |
431 | 436 | ||
432 | if (!key_task_permission(make_key_ref(key, possessed), | 437 | if (!key_task_permission(make_key_ref(key, possessed), |
433 | context, KEY_SEARCH)) | 438 | context, KEY_SEARCH) < 0) |
434 | continue; | 439 | continue; |
435 | 440 | ||
436 | /* stack the current position */ | 441 | /* stack the current position */ |
@@ -521,7 +526,7 @@ key_ref_t __keyring_search_one(key_ref_t keyring_ref, | |||
521 | (!key->type->match || | 526 | (!key->type->match || |
522 | key->type->match(key, description)) && | 527 | key->type->match(key, description)) && |
523 | key_permission(make_key_ref(key, possessed), | 528 | key_permission(make_key_ref(key, possessed), |
524 | perm) && | 529 | perm) < 0 && |
525 | !test_bit(KEY_FLAG_REVOKED, &key->flags) | 530 | !test_bit(KEY_FLAG_REVOKED, &key->flags) |
526 | ) | 531 | ) |
527 | goto found; | 532 | goto found; |
@@ -617,7 +622,7 @@ struct key *find_keyring_by_name(const char *name, key_serial_t bound) | |||
617 | continue; | 622 | continue; |
618 | 623 | ||
619 | if (!key_permission(make_key_ref(keyring, 0), | 624 | if (!key_permission(make_key_ref(keyring, 0), |
620 | KEY_SEARCH)) | 625 | KEY_SEARCH) < 0) |
621 | continue; | 626 | continue; |
622 | 627 | ||
623 | /* found a potential candidate, but we still need to | 628 | /* found a potential candidate, but we still need to |
diff --git a/security/keys/permission.c b/security/keys/permission.c index 03db073ba45c..e7f579c0eaf5 100644 --- a/security/keys/permission.c +++ b/security/keys/permission.c | |||
@@ -10,6 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/security.h> | ||
13 | #include "internal.h" | 14 | #include "internal.h" |
14 | 15 | ||
15 | /*****************************************************************************/ | 16 | /*****************************************************************************/ |
@@ -63,7 +64,11 @@ use_these_perms: | |||
63 | 64 | ||
64 | kperm = kperm & perm & KEY_ALL; | 65 | kperm = kperm & perm & KEY_ALL; |
65 | 66 | ||
66 | return kperm == perm; | 67 | if (kperm != perm) |
68 | return -EACCES; | ||
69 | |||
70 | /* let LSM be the final arbiter */ | ||
71 | return security_key_permission(key_ref, context, perm); | ||
67 | 72 | ||
68 | } /* end key_task_permission() */ | 73 | } /* end key_task_permission() */ |
69 | 74 | ||
diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c index d42d2158ce13..566b1cc0118a 100644 --- a/security/keys/process_keys.c +++ b/security/keys/process_keys.c | |||
@@ -39,7 +39,7 @@ struct key root_user_keyring = { | |||
39 | .type = &key_type_keyring, | 39 | .type = &key_type_keyring, |
40 | .user = &root_key_user, | 40 | .user = &root_key_user, |
41 | .sem = __RWSEM_INITIALIZER(root_user_keyring.sem), | 41 | .sem = __RWSEM_INITIALIZER(root_user_keyring.sem), |
42 | .perm = KEY_POS_ALL | KEY_USR_ALL, | 42 | .perm = (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_ALL, |
43 | .flags = 1 << KEY_FLAG_INSTANTIATED, | 43 | .flags = 1 << KEY_FLAG_INSTANTIATED, |
44 | .description = "_uid.0", | 44 | .description = "_uid.0", |
45 | #ifdef KEY_DEBUGGING | 45 | #ifdef KEY_DEBUGGING |
@@ -54,7 +54,7 @@ struct key root_session_keyring = { | |||
54 | .type = &key_type_keyring, | 54 | .type = &key_type_keyring, |
55 | .user = &root_key_user, | 55 | .user = &root_key_user, |
56 | .sem = __RWSEM_INITIALIZER(root_session_keyring.sem), | 56 | .sem = __RWSEM_INITIALIZER(root_session_keyring.sem), |
57 | .perm = KEY_POS_ALL | KEY_USR_ALL, | 57 | .perm = (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_ALL, |
58 | .flags = 1 << KEY_FLAG_INSTANTIATED, | 58 | .flags = 1 << KEY_FLAG_INSTANTIATED, |
59 | .description = "_uid_ses.0", | 59 | .description = "_uid_ses.0", |
60 | #ifdef KEY_DEBUGGING | 60 | #ifdef KEY_DEBUGGING |
@@ -666,9 +666,8 @@ key_ref_t lookup_user_key(struct task_struct *context, key_serial_t id, | |||
666 | goto invalid_key; | 666 | goto invalid_key; |
667 | 667 | ||
668 | /* check the permissions */ | 668 | /* check the permissions */ |
669 | ret = -EACCES; | 669 | ret = key_task_permission(key_ref, context, perm); |
670 | 670 | if (ret < 0) | |
671 | if (!key_task_permission(key_ref, context, perm)) | ||
672 | goto invalid_key; | 671 | goto invalid_key; |
673 | 672 | ||
674 | error: | 673 | error: |
diff --git a/security/keys/user_defined.c b/security/keys/user_defined.c index e446acba73d3..cbda3b2780a1 100644 --- a/security/keys/user_defined.c +++ b/security/keys/user_defined.c | |||
@@ -15,18 +15,10 @@ | |||
15 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
16 | #include <linux/seq_file.h> | 16 | #include <linux/seq_file.h> |
17 | #include <linux/err.h> | 17 | #include <linux/err.h> |
18 | #include <keys/user-type.h> | ||
18 | #include <asm/uaccess.h> | 19 | #include <asm/uaccess.h> |
19 | #include "internal.h" | 20 | #include "internal.h" |
20 | 21 | ||
21 | static int user_instantiate(struct key *key, const void *data, size_t datalen); | ||
22 | static int user_duplicate(struct key *key, const struct key *source); | ||
23 | static int user_update(struct key *key, const void *data, size_t datalen); | ||
24 | static int user_match(const struct key *key, const void *criterion); | ||
25 | static void user_destroy(struct key *key); | ||
26 | static void user_describe(const struct key *user, struct seq_file *m); | ||
27 | static long user_read(const struct key *key, | ||
28 | char __user *buffer, size_t buflen); | ||
29 | |||
30 | /* | 22 | /* |
31 | * user defined keys take an arbitrary string as the description and an | 23 | * user defined keys take an arbitrary string as the description and an |
32 | * arbitrary blob of data as the payload | 24 | * arbitrary blob of data as the payload |
@@ -42,19 +34,13 @@ struct key_type key_type_user = { | |||
42 | .read = user_read, | 34 | .read = user_read, |
43 | }; | 35 | }; |
44 | 36 | ||
45 | struct user_key_payload { | ||
46 | struct rcu_head rcu; /* RCU destructor */ | ||
47 | unsigned short datalen; /* length of this data */ | ||
48 | char data[0]; /* actual data */ | ||
49 | }; | ||
50 | |||
51 | EXPORT_SYMBOL_GPL(key_type_user); | 37 | EXPORT_SYMBOL_GPL(key_type_user); |
52 | 38 | ||
53 | /*****************************************************************************/ | 39 | /*****************************************************************************/ |
54 | /* | 40 | /* |
55 | * instantiate a user defined key | 41 | * instantiate a user defined key |
56 | */ | 42 | */ |
57 | static int user_instantiate(struct key *key, const void *data, size_t datalen) | 43 | int user_instantiate(struct key *key, const void *data, size_t datalen) |
58 | { | 44 | { |
59 | struct user_key_payload *upayload; | 45 | struct user_key_payload *upayload; |
60 | int ret; | 46 | int ret; |
@@ -78,18 +64,20 @@ static int user_instantiate(struct key *key, const void *data, size_t datalen) | |||
78 | rcu_assign_pointer(key->payload.data, upayload); | 64 | rcu_assign_pointer(key->payload.data, upayload); |
79 | ret = 0; | 65 | ret = 0; |
80 | 66 | ||
81 | error: | 67 | error: |
82 | return ret; | 68 | return ret; |
83 | 69 | ||
84 | } /* end user_instantiate() */ | 70 | } /* end user_instantiate() */ |
85 | 71 | ||
72 | EXPORT_SYMBOL_GPL(user_instantiate); | ||
73 | |||
86 | /*****************************************************************************/ | 74 | /*****************************************************************************/ |
87 | /* | 75 | /* |
88 | * duplicate a user defined key | 76 | * duplicate a user defined key |
89 | * - both keys' semaphores are locked against further modification | 77 | * - both keys' semaphores are locked against further modification |
90 | * - the new key cannot yet be accessed | 78 | * - the new key cannot yet be accessed |
91 | */ | 79 | */ |
92 | static int user_duplicate(struct key *key, const struct key *source) | 80 | int user_duplicate(struct key *key, const struct key *source) |
93 | { | 81 | { |
94 | struct user_key_payload *upayload, *spayload; | 82 | struct user_key_payload *upayload, *spayload; |
95 | int ret; | 83 | int ret; |
@@ -112,6 +100,8 @@ static int user_duplicate(struct key *key, const struct key *source) | |||
112 | 100 | ||
113 | } /* end user_duplicate() */ | 101 | } /* end user_duplicate() */ |
114 | 102 | ||
103 | EXPORT_SYMBOL_GPL(user_duplicate); | ||
104 | |||
115 | /*****************************************************************************/ | 105 | /*****************************************************************************/ |
116 | /* | 106 | /* |
117 | * dispose of the old data from an updated user defined key | 107 | * dispose of the old data from an updated user defined key |
@@ -131,7 +121,7 @@ static void user_update_rcu_disposal(struct rcu_head *rcu) | |||
131 | * update a user defined key | 121 | * update a user defined key |
132 | * - the key's semaphore is write-locked | 122 | * - the key's semaphore is write-locked |
133 | */ | 123 | */ |
134 | static int user_update(struct key *key, const void *data, size_t datalen) | 124 | int user_update(struct key *key, const void *data, size_t datalen) |
135 | { | 125 | { |
136 | struct user_key_payload *upayload, *zap; | 126 | struct user_key_payload *upayload, *zap; |
137 | int ret; | 127 | int ret; |
@@ -163,26 +153,30 @@ static int user_update(struct key *key, const void *data, size_t datalen) | |||
163 | 153 | ||
164 | call_rcu(&zap->rcu, user_update_rcu_disposal); | 154 | call_rcu(&zap->rcu, user_update_rcu_disposal); |
165 | 155 | ||
166 | error: | 156 | error: |
167 | return ret; | 157 | return ret; |
168 | 158 | ||
169 | } /* end user_update() */ | 159 | } /* end user_update() */ |
170 | 160 | ||
161 | EXPORT_SYMBOL_GPL(user_update); | ||
162 | |||
171 | /*****************************************************************************/ | 163 | /*****************************************************************************/ |
172 | /* | 164 | /* |
173 | * match users on their name | 165 | * match users on their name |
174 | */ | 166 | */ |
175 | static int user_match(const struct key *key, const void *description) | 167 | int user_match(const struct key *key, const void *description) |
176 | { | 168 | { |
177 | return strcmp(key->description, description) == 0; | 169 | return strcmp(key->description, description) == 0; |
178 | 170 | ||
179 | } /* end user_match() */ | 171 | } /* end user_match() */ |
180 | 172 | ||
173 | EXPORT_SYMBOL_GPL(user_match); | ||
174 | |||
181 | /*****************************************************************************/ | 175 | /*****************************************************************************/ |
182 | /* | 176 | /* |
183 | * dispose of the data dangling from the corpse of a user | 177 | * dispose of the data dangling from the corpse of a user |
184 | */ | 178 | */ |
185 | static void user_destroy(struct key *key) | 179 | void user_destroy(struct key *key) |
186 | { | 180 | { |
187 | struct user_key_payload *upayload = key->payload.data; | 181 | struct user_key_payload *upayload = key->payload.data; |
188 | 182 | ||
@@ -190,11 +184,13 @@ static void user_destroy(struct key *key) | |||
190 | 184 | ||
191 | } /* end user_destroy() */ | 185 | } /* end user_destroy() */ |
192 | 186 | ||
187 | EXPORT_SYMBOL_GPL(user_destroy); | ||
188 | |||
193 | /*****************************************************************************/ | 189 | /*****************************************************************************/ |
194 | /* | 190 | /* |
195 | * describe the user key | 191 | * describe the user key |
196 | */ | 192 | */ |
197 | static void user_describe(const struct key *key, struct seq_file *m) | 193 | void user_describe(const struct key *key, struct seq_file *m) |
198 | { | 194 | { |
199 | seq_puts(m, key->description); | 195 | seq_puts(m, key->description); |
200 | 196 | ||
@@ -202,13 +198,14 @@ static void user_describe(const struct key *key, struct seq_file *m) | |||
202 | 198 | ||
203 | } /* end user_describe() */ | 199 | } /* end user_describe() */ |
204 | 200 | ||
201 | EXPORT_SYMBOL_GPL(user_describe); | ||
202 | |||
205 | /*****************************************************************************/ | 203 | /*****************************************************************************/ |
206 | /* | 204 | /* |
207 | * read the key data | 205 | * read the key data |
208 | * - the key's semaphore is read-locked | 206 | * - the key's semaphore is read-locked |
209 | */ | 207 | */ |
210 | static long user_read(const struct key *key, | 208 | long user_read(const struct key *key, char __user *buffer, size_t buflen) |
211 | char __user *buffer, size_t buflen) | ||
212 | { | 209 | { |
213 | struct user_key_payload *upayload; | 210 | struct user_key_payload *upayload; |
214 | long ret; | 211 | long ret; |
@@ -228,3 +225,5 @@ static long user_read(const struct key *key, | |||
228 | return ret; | 225 | return ret; |
229 | 226 | ||
230 | } /* end user_read() */ | 227 | } /* end user_read() */ |
228 | |||
229 | EXPORT_SYMBOL_GPL(user_read); | ||
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index b13be15165f5..45c41490d521 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c | |||
@@ -122,11 +122,10 @@ static int task_alloc_security(struct task_struct *task) | |||
122 | { | 122 | { |
123 | struct task_security_struct *tsec; | 123 | struct task_security_struct *tsec; |
124 | 124 | ||
125 | tsec = kmalloc(sizeof(struct task_security_struct), GFP_KERNEL); | 125 | tsec = kzalloc(sizeof(struct task_security_struct), GFP_KERNEL); |
126 | if (!tsec) | 126 | if (!tsec) |
127 | return -ENOMEM; | 127 | return -ENOMEM; |
128 | 128 | ||
129 | memset(tsec, 0, sizeof(struct task_security_struct)); | ||
130 | tsec->magic = SELINUX_MAGIC; | 129 | tsec->magic = SELINUX_MAGIC; |
131 | tsec->task = task; | 130 | tsec->task = task; |
132 | tsec->osid = tsec->sid = tsec->ptrace_sid = SECINITSID_UNLABELED; | 131 | tsec->osid = tsec->sid = tsec->ptrace_sid = SECINITSID_UNLABELED; |
@@ -151,11 +150,10 @@ static int inode_alloc_security(struct inode *inode) | |||
151 | struct task_security_struct *tsec = current->security; | 150 | struct task_security_struct *tsec = current->security; |
152 | struct inode_security_struct *isec; | 151 | struct inode_security_struct *isec; |
153 | 152 | ||
154 | isec = kmalloc(sizeof(struct inode_security_struct), GFP_KERNEL); | 153 | isec = kzalloc(sizeof(struct inode_security_struct), GFP_KERNEL); |
155 | if (!isec) | 154 | if (!isec) |
156 | return -ENOMEM; | 155 | return -ENOMEM; |
157 | 156 | ||
158 | memset(isec, 0, sizeof(struct inode_security_struct)); | ||
159 | init_MUTEX(&isec->sem); | 157 | init_MUTEX(&isec->sem); |
160 | INIT_LIST_HEAD(&isec->list); | 158 | INIT_LIST_HEAD(&isec->list); |
161 | isec->magic = SELINUX_MAGIC; | 159 | isec->magic = SELINUX_MAGIC; |
@@ -193,11 +191,10 @@ static int file_alloc_security(struct file *file) | |||
193 | struct task_security_struct *tsec = current->security; | 191 | struct task_security_struct *tsec = current->security; |
194 | struct file_security_struct *fsec; | 192 | struct file_security_struct *fsec; |
195 | 193 | ||
196 | fsec = kmalloc(sizeof(struct file_security_struct), GFP_ATOMIC); | 194 | fsec = kzalloc(sizeof(struct file_security_struct), GFP_ATOMIC); |
197 | if (!fsec) | 195 | if (!fsec) |
198 | return -ENOMEM; | 196 | return -ENOMEM; |
199 | 197 | ||
200 | memset(fsec, 0, sizeof(struct file_security_struct)); | ||
201 | fsec->magic = SELINUX_MAGIC; | 198 | fsec->magic = SELINUX_MAGIC; |
202 | fsec->file = file; | 199 | fsec->file = file; |
203 | if (tsec && tsec->magic == SELINUX_MAGIC) { | 200 | if (tsec && tsec->magic == SELINUX_MAGIC) { |
@@ -227,11 +224,10 @@ static int superblock_alloc_security(struct super_block *sb) | |||
227 | { | 224 | { |
228 | struct superblock_security_struct *sbsec; | 225 | struct superblock_security_struct *sbsec; |
229 | 226 | ||
230 | sbsec = kmalloc(sizeof(struct superblock_security_struct), GFP_KERNEL); | 227 | sbsec = kzalloc(sizeof(struct superblock_security_struct), GFP_KERNEL); |
231 | if (!sbsec) | 228 | if (!sbsec) |
232 | return -ENOMEM; | 229 | return -ENOMEM; |
233 | 230 | ||
234 | memset(sbsec, 0, sizeof(struct superblock_security_struct)); | ||
235 | init_MUTEX(&sbsec->sem); | 231 | init_MUTEX(&sbsec->sem); |
236 | INIT_LIST_HEAD(&sbsec->list); | 232 | INIT_LIST_HEAD(&sbsec->list); |
237 | INIT_LIST_HEAD(&sbsec->isec_head); | 233 | INIT_LIST_HEAD(&sbsec->isec_head); |
@@ -262,18 +258,17 @@ static void superblock_free_security(struct super_block *sb) | |||
262 | } | 258 | } |
263 | 259 | ||
264 | #ifdef CONFIG_SECURITY_NETWORK | 260 | #ifdef CONFIG_SECURITY_NETWORK |
265 | static int sk_alloc_security(struct sock *sk, int family, int priority) | 261 | static int sk_alloc_security(struct sock *sk, int family, gfp_t priority) |
266 | { | 262 | { |
267 | struct sk_security_struct *ssec; | 263 | struct sk_security_struct *ssec; |
268 | 264 | ||
269 | if (family != PF_UNIX) | 265 | if (family != PF_UNIX) |
270 | return 0; | 266 | return 0; |
271 | 267 | ||
272 | ssec = kmalloc(sizeof(*ssec), priority); | 268 | ssec = kzalloc(sizeof(*ssec), priority); |
273 | if (!ssec) | 269 | if (!ssec) |
274 | return -ENOMEM; | 270 | return -ENOMEM; |
275 | 271 | ||
276 | memset(ssec, 0, sizeof(*ssec)); | ||
277 | ssec->magic = SELINUX_MAGIC; | 272 | ssec->magic = SELINUX_MAGIC; |
278 | ssec->sk = sk; | 273 | ssec->sk = sk; |
279 | ssec->peer_sid = SECINITSID_UNLABELED; | 274 | ssec->peer_sid = SECINITSID_UNLABELED; |
@@ -1483,11 +1478,10 @@ static int selinux_bprm_alloc_security(struct linux_binprm *bprm) | |||
1483 | { | 1478 | { |
1484 | struct bprm_security_struct *bsec; | 1479 | struct bprm_security_struct *bsec; |
1485 | 1480 | ||
1486 | bsec = kmalloc(sizeof(struct bprm_security_struct), GFP_KERNEL); | 1481 | bsec = kzalloc(sizeof(struct bprm_security_struct), GFP_KERNEL); |
1487 | if (!bsec) | 1482 | if (!bsec) |
1488 | return -ENOMEM; | 1483 | return -ENOMEM; |
1489 | 1484 | ||
1490 | memset(bsec, 0, sizeof *bsec); | ||
1491 | bsec->magic = SELINUX_MAGIC; | 1485 | bsec->magic = SELINUX_MAGIC; |
1492 | bsec->bprm = bprm; | 1486 | bsec->bprm = bprm; |
1493 | bsec->sid = SECINITSID_UNLABELED; | 1487 | bsec->sid = SECINITSID_UNLABELED; |
@@ -1615,7 +1609,7 @@ static inline void flush_unauthorized_files(struct files_struct * files) | |||
1615 | 1609 | ||
1616 | if (tty) { | 1610 | if (tty) { |
1617 | file_list_lock(); | 1611 | file_list_lock(); |
1618 | file = list_entry(tty->tty_files.next, typeof(*file), f_list); | 1612 | file = list_entry(tty->tty_files.next, typeof(*file), f_u.fu_list); |
1619 | if (file) { | 1613 | if (file) { |
1620 | /* Revalidate access to controlling tty. | 1614 | /* Revalidate access to controlling tty. |
1621 | Use inode_has_perm on the tty inode directly rather | 1615 | Use inode_has_perm on the tty inode directly rather |
@@ -2211,12 +2205,6 @@ static void selinux_inode_post_setxattr(struct dentry *dentry, char *name, | |||
2211 | 2205 | ||
2212 | static int selinux_inode_getxattr (struct dentry *dentry, char *name) | 2206 | static int selinux_inode_getxattr (struct dentry *dentry, char *name) |
2213 | { | 2207 | { |
2214 | struct inode *inode = dentry->d_inode; | ||
2215 | struct superblock_security_struct *sbsec = inode->i_sb->s_security; | ||
2216 | |||
2217 | if (sbsec->behavior == SECURITY_FS_USE_MNTPOINT) | ||
2218 | return -EOPNOTSUPP; | ||
2219 | |||
2220 | return dentry_has_perm(current, NULL, dentry, FILE__GETATTR); | 2208 | return dentry_has_perm(current, NULL, dentry, FILE__GETATTR); |
2221 | } | 2209 | } |
2222 | 2210 | ||
@@ -2247,33 +2235,54 @@ static int selinux_inode_removexattr (struct dentry *dentry, char *name) | |||
2247 | return -EACCES; | 2235 | return -EACCES; |
2248 | } | 2236 | } |
2249 | 2237 | ||
2250 | static int selinux_inode_getsecurity(struct inode *inode, const char *name, void *buffer, size_t size) | 2238 | /* |
2239 | * Copy the in-core inode security context value to the user. If the | ||
2240 | * getxattr() prior to this succeeded, check to see if we need to | ||
2241 | * canonicalize the value to be finally returned to the user. | ||
2242 | * | ||
2243 | * Permission check is handled by selinux_inode_getxattr hook. | ||
2244 | */ | ||
2245 | static int selinux_inode_getsecurity(struct inode *inode, const char *name, void *buffer, size_t size, int err) | ||
2251 | { | 2246 | { |
2252 | struct inode_security_struct *isec = inode->i_security; | 2247 | struct inode_security_struct *isec = inode->i_security; |
2253 | char *context; | 2248 | char *context; |
2254 | unsigned len; | 2249 | unsigned len; |
2255 | int rc; | 2250 | int rc; |
2256 | 2251 | ||
2257 | /* Permission check handled by selinux_inode_getxattr hook.*/ | 2252 | if (strcmp(name, XATTR_SELINUX_SUFFIX)) { |
2258 | 2253 | rc = -EOPNOTSUPP; | |
2259 | if (strcmp(name, XATTR_SELINUX_SUFFIX)) | 2254 | goto out; |
2260 | return -EOPNOTSUPP; | 2255 | } |
2261 | 2256 | ||
2262 | rc = security_sid_to_context(isec->sid, &context, &len); | 2257 | rc = security_sid_to_context(isec->sid, &context, &len); |
2263 | if (rc) | 2258 | if (rc) |
2264 | return rc; | 2259 | goto out; |
2265 | 2260 | ||
2261 | /* Probe for required buffer size */ | ||
2266 | if (!buffer || !size) { | 2262 | if (!buffer || !size) { |
2267 | kfree(context); | 2263 | rc = len; |
2268 | return len; | 2264 | goto out_free; |
2269 | } | 2265 | } |
2266 | |||
2270 | if (size < len) { | 2267 | if (size < len) { |
2271 | kfree(context); | 2268 | rc = -ERANGE; |
2272 | return -ERANGE; | 2269 | goto out_free; |
2270 | } | ||
2271 | |||
2272 | if (err > 0) { | ||
2273 | if ((len == err) && !(memcmp(context, buffer, len))) { | ||
2274 | /* Don't need to canonicalize value */ | ||
2275 | rc = err; | ||
2276 | goto out_free; | ||
2277 | } | ||
2278 | memset(buffer, 0, size); | ||
2273 | } | 2279 | } |
2274 | memcpy(buffer, context, len); | 2280 | memcpy(buffer, context, len); |
2281 | rc = len; | ||
2282 | out_free: | ||
2275 | kfree(context); | 2283 | kfree(context); |
2276 | return len; | 2284 | out: |
2285 | return rc; | ||
2277 | } | 2286 | } |
2278 | 2287 | ||
2279 | static int selinux_inode_setsecurity(struct inode *inode, const char *name, | 2288 | static int selinux_inode_setsecurity(struct inode *inode, const char *name, |
@@ -2704,8 +2713,7 @@ static int selinux_task_kill(struct task_struct *p, struct siginfo *info, int si | |||
2704 | if (rc) | 2713 | if (rc) |
2705 | return rc; | 2714 | return rc; |
2706 | 2715 | ||
2707 | if (info && ((unsigned long)info == 1 || | 2716 | if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info))) |
2708 | (unsigned long)info == 2 || SI_FROMKERNEL(info))) | ||
2709 | return 0; | 2717 | return 0; |
2710 | 2718 | ||
2711 | if (!sig) | 2719 | if (!sig) |
@@ -3380,7 +3388,7 @@ out: | |||
3380 | return err; | 3388 | return err; |
3381 | } | 3389 | } |
3382 | 3390 | ||
3383 | static int selinux_sk_alloc_security(struct sock *sk, int family, int priority) | 3391 | static int selinux_sk_alloc_security(struct sock *sk, int family, gfp_t priority) |
3384 | { | 3392 | { |
3385 | return sk_alloc_security(sk, family, priority); | 3393 | return sk_alloc_security(sk, family, priority); |
3386 | } | 3394 | } |
@@ -3599,11 +3607,10 @@ static int ipc_alloc_security(struct task_struct *task, | |||
3599 | struct task_security_struct *tsec = task->security; | 3607 | struct task_security_struct *tsec = task->security; |
3600 | struct ipc_security_struct *isec; | 3608 | struct ipc_security_struct *isec; |
3601 | 3609 | ||
3602 | isec = kmalloc(sizeof(struct ipc_security_struct), GFP_KERNEL); | 3610 | isec = kzalloc(sizeof(struct ipc_security_struct), GFP_KERNEL); |
3603 | if (!isec) | 3611 | if (!isec) |
3604 | return -ENOMEM; | 3612 | return -ENOMEM; |
3605 | 3613 | ||
3606 | memset(isec, 0, sizeof(struct ipc_security_struct)); | ||
3607 | isec->magic = SELINUX_MAGIC; | 3614 | isec->magic = SELINUX_MAGIC; |
3608 | isec->sclass = sclass; | 3615 | isec->sclass = sclass; |
3609 | isec->ipc_perm = perm; | 3616 | isec->ipc_perm = perm; |
@@ -3631,11 +3638,10 @@ static int msg_msg_alloc_security(struct msg_msg *msg) | |||
3631 | { | 3638 | { |
3632 | struct msg_security_struct *msec; | 3639 | struct msg_security_struct *msec; |
3633 | 3640 | ||
3634 | msec = kmalloc(sizeof(struct msg_security_struct), GFP_KERNEL); | 3641 | msec = kzalloc(sizeof(struct msg_security_struct), GFP_KERNEL); |
3635 | if (!msec) | 3642 | if (!msec) |
3636 | return -ENOMEM; | 3643 | return -ENOMEM; |
3637 | 3644 | ||
3638 | memset(msec, 0, sizeof(struct msg_security_struct)); | ||
3639 | msec->magic = SELINUX_MAGIC; | 3645 | msec->magic = SELINUX_MAGIC; |
3640 | msec->msg = msg; | 3646 | msec->msg = msg; |
3641 | msec->sid = SECINITSID_UNLABELED; | 3647 | msec->sid = SECINITSID_UNLABELED; |
diff --git a/security/selinux/netif.c b/security/selinux/netif.c index 718d7be9f4dd..b10c34e8a743 100644 --- a/security/selinux/netif.c +++ b/security/selinux/netif.c | |||
@@ -114,13 +114,12 @@ static struct sel_netif *sel_netif_lookup(struct net_device *dev) | |||
114 | if (likely(netif != NULL)) | 114 | if (likely(netif != NULL)) |
115 | goto out; | 115 | goto out; |
116 | 116 | ||
117 | new = kmalloc(sizeof(*new), GFP_ATOMIC); | 117 | new = kzalloc(sizeof(*new), GFP_ATOMIC); |
118 | if (!new) { | 118 | if (!new) { |
119 | netif = ERR_PTR(-ENOMEM); | 119 | netif = ERR_PTR(-ENOMEM); |
120 | goto out; | 120 | goto out; |
121 | } | 121 | } |
122 | 122 | ||
123 | memset(new, 0, sizeof(*new)); | ||
124 | nsec = &new->nsec; | 123 | nsec = &new->nsec; |
125 | 124 | ||
126 | ret = security_netif_sid(dev->name, &nsec->if_sid, &nsec->msg_sid); | 125 | ret = security_netif_sid(dev->name, &nsec->if_sid, &nsec->msg_sid); |
diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c index a45cc971e735..fdc382389720 100644 --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c | |||
@@ -105,7 +105,7 @@ static ssize_t sel_write_enforce(struct file * file, const char __user * buf, | |||
105 | ssize_t length; | 105 | ssize_t length; |
106 | int new_value; | 106 | int new_value; |
107 | 107 | ||
108 | if (count < 0 || count >= PAGE_SIZE) | 108 | if (count >= PAGE_SIZE) |
109 | return -ENOMEM; | 109 | return -ENOMEM; |
110 | if (*ppos != 0) { | 110 | if (*ppos != 0) { |
111 | /* No partial writes. */ | 111 | /* No partial writes. */ |
@@ -155,7 +155,7 @@ static ssize_t sel_write_disable(struct file * file, const char __user * buf, | |||
155 | int new_value; | 155 | int new_value; |
156 | extern int selinux_disable(void); | 156 | extern int selinux_disable(void); |
157 | 157 | ||
158 | if (count < 0 || count >= PAGE_SIZE) | 158 | if (count >= PAGE_SIZE) |
159 | return -ENOMEM; | 159 | return -ENOMEM; |
160 | if (*ppos != 0) { | 160 | if (*ppos != 0) { |
161 | /* No partial writes. */ | 161 | /* No partial writes. */ |
@@ -242,7 +242,7 @@ static ssize_t sel_write_load(struct file * file, const char __user * buf, | |||
242 | goto out; | 242 | goto out; |
243 | } | 243 | } |
244 | 244 | ||
245 | if ((count < 0) || (count > 64 * 1024 * 1024) | 245 | if ((count > 64 * 1024 * 1024) |
246 | || (data = vmalloc(count)) == NULL) { | 246 | || (data = vmalloc(count)) == NULL) { |
247 | length = -ENOMEM; | 247 | length = -ENOMEM; |
248 | goto out; | 248 | goto out; |
@@ -284,7 +284,7 @@ static ssize_t sel_write_context(struct file * file, const char __user * buf, | |||
284 | if (length) | 284 | if (length) |
285 | return length; | 285 | return length; |
286 | 286 | ||
287 | if (count < 0 || count >= PAGE_SIZE) | 287 | if (count >= PAGE_SIZE) |
288 | return -ENOMEM; | 288 | return -ENOMEM; |
289 | if (*ppos != 0) { | 289 | if (*ppos != 0) { |
290 | /* No partial writes. */ | 290 | /* No partial writes. */ |
@@ -332,7 +332,7 @@ static ssize_t sel_write_checkreqprot(struct file * file, const char __user * bu | |||
332 | if (length) | 332 | if (length) |
333 | return length; | 333 | return length; |
334 | 334 | ||
335 | if (count < 0 || count >= PAGE_SIZE) | 335 | if (count >= PAGE_SIZE) |
336 | return -ENOMEM; | 336 | return -ENOMEM; |
337 | if (*ppos != 0) { | 337 | if (*ppos != 0) { |
338 | /* No partial writes. */ | 338 | /* No partial writes. */ |
@@ -424,15 +424,13 @@ static ssize_t sel_write_access(struct file * file, char *buf, size_t size) | |||
424 | return length; | 424 | return length; |
425 | 425 | ||
426 | length = -ENOMEM; | 426 | length = -ENOMEM; |
427 | scon = kmalloc(size+1, GFP_KERNEL); | 427 | scon = kzalloc(size+1, GFP_KERNEL); |
428 | if (!scon) | 428 | if (!scon) |
429 | return length; | 429 | return length; |
430 | memset(scon, 0, size+1); | ||
431 | 430 | ||
432 | tcon = kmalloc(size+1, GFP_KERNEL); | 431 | tcon = kzalloc(size+1, GFP_KERNEL); |
433 | if (!tcon) | 432 | if (!tcon) |
434 | goto out; | 433 | goto out; |
435 | memset(tcon, 0, size+1); | ||
436 | 434 | ||
437 | length = -EINVAL; | 435 | length = -EINVAL; |
438 | if (sscanf(buf, "%s %s %hu %x", scon, tcon, &tclass, &req) != 4) | 436 | if (sscanf(buf, "%s %s %hu %x", scon, tcon, &tclass, &req) != 4) |
@@ -475,15 +473,13 @@ static ssize_t sel_write_create(struct file * file, char *buf, size_t size) | |||
475 | return length; | 473 | return length; |
476 | 474 | ||
477 | length = -ENOMEM; | 475 | length = -ENOMEM; |
478 | scon = kmalloc(size+1, GFP_KERNEL); | 476 | scon = kzalloc(size+1, GFP_KERNEL); |
479 | if (!scon) | 477 | if (!scon) |
480 | return length; | 478 | return length; |
481 | memset(scon, 0, size+1); | ||
482 | 479 | ||
483 | tcon = kmalloc(size+1, GFP_KERNEL); | 480 | tcon = kzalloc(size+1, GFP_KERNEL); |
484 | if (!tcon) | 481 | if (!tcon) |
485 | goto out; | 482 | goto out; |
486 | memset(tcon, 0, size+1); | ||
487 | 483 | ||
488 | length = -EINVAL; | 484 | length = -EINVAL; |
489 | if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3) | 485 | if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3) |
@@ -536,15 +532,13 @@ static ssize_t sel_write_relabel(struct file * file, char *buf, size_t size) | |||
536 | return length; | 532 | return length; |
537 | 533 | ||
538 | length = -ENOMEM; | 534 | length = -ENOMEM; |
539 | scon = kmalloc(size+1, GFP_KERNEL); | 535 | scon = kzalloc(size+1, GFP_KERNEL); |
540 | if (!scon) | 536 | if (!scon) |
541 | return length; | 537 | return length; |
542 | memset(scon, 0, size+1); | ||
543 | 538 | ||
544 | tcon = kmalloc(size+1, GFP_KERNEL); | 539 | tcon = kzalloc(size+1, GFP_KERNEL); |
545 | if (!tcon) | 540 | if (!tcon) |
546 | goto out; | 541 | goto out; |
547 | memset(tcon, 0, size+1); | ||
548 | 542 | ||
549 | length = -EINVAL; | 543 | length = -EINVAL; |
550 | if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3) | 544 | if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3) |
@@ -595,15 +589,13 @@ static ssize_t sel_write_user(struct file * file, char *buf, size_t size) | |||
595 | return length; | 589 | return length; |
596 | 590 | ||
597 | length = -ENOMEM; | 591 | length = -ENOMEM; |
598 | con = kmalloc(size+1, GFP_KERNEL); | 592 | con = kzalloc(size+1, GFP_KERNEL); |
599 | if (!con) | 593 | if (!con) |
600 | return length; | 594 | return length; |
601 | memset(con, 0, size+1); | ||
602 | 595 | ||
603 | user = kmalloc(size+1, GFP_KERNEL); | 596 | user = kzalloc(size+1, GFP_KERNEL); |
604 | if (!user) | 597 | if (!user) |
605 | goto out; | 598 | goto out; |
606 | memset(user, 0, size+1); | ||
607 | 599 | ||
608 | length = -EINVAL; | 600 | length = -EINVAL; |
609 | if (sscanf(buf, "%s %s", con, user) != 2) | 601 | if (sscanf(buf, "%s %s", con, user) != 2) |
@@ -658,15 +650,13 @@ static ssize_t sel_write_member(struct file * file, char *buf, size_t size) | |||
658 | return length; | 650 | return length; |
659 | 651 | ||
660 | length = -ENOMEM; | 652 | length = -ENOMEM; |
661 | scon = kmalloc(size+1, GFP_KERNEL); | 653 | scon = kzalloc(size+1, GFP_KERNEL); |
662 | if (!scon) | 654 | if (!scon) |
663 | return length; | 655 | return length; |
664 | memset(scon, 0, size+1); | ||
665 | 656 | ||
666 | tcon = kmalloc(size+1, GFP_KERNEL); | 657 | tcon = kzalloc(size+1, GFP_KERNEL); |
667 | if (!tcon) | 658 | if (!tcon) |
668 | goto out; | 659 | goto out; |
669 | memset(tcon, 0, size+1); | ||
670 | 660 | ||
671 | length = -EINVAL; | 661 | length = -EINVAL; |
672 | if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3) | 662 | if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3) |
@@ -739,7 +729,7 @@ static ssize_t sel_read_bool(struct file *filep, char __user *buf, | |||
739 | if (!filep->f_op) | 729 | if (!filep->f_op) |
740 | goto out; | 730 | goto out; |
741 | 731 | ||
742 | if (count < 0 || count > PAGE_SIZE) { | 732 | if (count > PAGE_SIZE) { |
743 | ret = -EINVAL; | 733 | ret = -EINVAL; |
744 | goto out; | 734 | goto out; |
745 | } | 735 | } |
@@ -800,7 +790,7 @@ static ssize_t sel_write_bool(struct file *filep, const char __user *buf, | |||
800 | if (!filep->f_op) | 790 | if (!filep->f_op) |
801 | goto out; | 791 | goto out; |
802 | 792 | ||
803 | if (count < 0 || count >= PAGE_SIZE) { | 793 | if (count >= PAGE_SIZE) { |
804 | length = -ENOMEM; | 794 | length = -ENOMEM; |
805 | goto out; | 795 | goto out; |
806 | } | 796 | } |
@@ -858,7 +848,7 @@ static ssize_t sel_commit_bools_write(struct file *filep, | |||
858 | if (!filep->f_op) | 848 | if (!filep->f_op) |
859 | goto out; | 849 | goto out; |
860 | 850 | ||
861 | if (count < 0 || count >= PAGE_SIZE) { | 851 | if (count >= PAGE_SIZE) { |
862 | length = -ENOMEM; | 852 | length = -ENOMEM; |
863 | goto out; | 853 | goto out; |
864 | } | 854 | } |
@@ -924,7 +914,7 @@ static void sel_remove_bools(struct dentry *de) | |||
924 | 914 | ||
925 | file_list_lock(); | 915 | file_list_lock(); |
926 | list_for_each(p, &sb->s_files) { | 916 | list_for_each(p, &sb->s_files) { |
927 | struct file * filp = list_entry(p, struct file, f_list); | 917 | struct file * filp = list_entry(p, struct file, f_u.fu_list); |
928 | struct dentry * dentry = filp->f_dentry; | 918 | struct dentry * dentry = filp->f_dentry; |
929 | 919 | ||
930 | if (dentry->d_parent != de) { | 920 | if (dentry->d_parent != de) { |
@@ -1032,7 +1022,7 @@ static ssize_t sel_write_avc_cache_threshold(struct file * file, | |||
1032 | ssize_t ret; | 1022 | ssize_t ret; |
1033 | int new_value; | 1023 | int new_value; |
1034 | 1024 | ||
1035 | if (count < 0 || count >= PAGE_SIZE) { | 1025 | if (count >= PAGE_SIZE) { |
1036 | ret = -ENOMEM; | 1026 | ret = -ENOMEM; |
1037 | goto out; | 1027 | goto out; |
1038 | } | 1028 | } |
diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/conditional.c index daf288007460..d2737edba541 100644 --- a/security/selinux/ss/conditional.c +++ b/security/selinux/ss/conditional.c | |||
@@ -220,10 +220,9 @@ int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp) | |||
220 | u32 len; | 220 | u32 len; |
221 | int rc; | 221 | int rc; |
222 | 222 | ||
223 | booldatum = kmalloc(sizeof(struct cond_bool_datum), GFP_KERNEL); | 223 | booldatum = kzalloc(sizeof(struct cond_bool_datum), GFP_KERNEL); |
224 | if (!booldatum) | 224 | if (!booldatum) |
225 | return -1; | 225 | return -1; |
226 | memset(booldatum, 0, sizeof(struct cond_bool_datum)); | ||
227 | 226 | ||
228 | rc = next_entry(buf, fp, sizeof buf); | 227 | rc = next_entry(buf, fp, sizeof buf); |
229 | if (rc < 0) | 228 | if (rc < 0) |
@@ -321,10 +320,9 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum | |||
321 | goto err; | 320 | goto err; |
322 | } | 321 | } |
323 | 322 | ||
324 | list = kmalloc(sizeof(struct cond_av_list), GFP_KERNEL); | 323 | list = kzalloc(sizeof(struct cond_av_list), GFP_KERNEL); |
325 | if (!list) | 324 | if (!list) |
326 | goto err; | 325 | goto err; |
327 | memset(list, 0, sizeof(*list)); | ||
328 | 326 | ||
329 | list->node = node_ptr; | 327 | list->node = node_ptr; |
330 | if (!data->head) | 328 | if (!data->head) |
@@ -414,11 +412,10 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp) | |||
414 | if (rc < 0) | 412 | if (rc < 0) |
415 | goto err; | 413 | goto err; |
416 | 414 | ||
417 | expr = kmalloc(sizeof(struct cond_expr), GFP_KERNEL); | 415 | expr = kzalloc(sizeof(struct cond_expr), GFP_KERNEL); |
418 | if (!expr) { | 416 | if (!expr) { |
419 | goto err; | 417 | goto err; |
420 | } | 418 | } |
421 | memset(expr, 0, sizeof(struct cond_expr)); | ||
422 | 419 | ||
423 | expr->expr_type = le32_to_cpu(buf[0]); | 420 | expr->expr_type = le32_to_cpu(buf[0]); |
424 | expr->bool = le32_to_cpu(buf[1]); | 421 | expr->bool = le32_to_cpu(buf[1]); |
@@ -460,10 +457,9 @@ int cond_read_list(struct policydb *p, void *fp) | |||
460 | len = le32_to_cpu(buf[0]); | 457 | len = le32_to_cpu(buf[0]); |
461 | 458 | ||
462 | for (i = 0; i < len; i++) { | 459 | for (i = 0; i < len; i++) { |
463 | node = kmalloc(sizeof(struct cond_node), GFP_KERNEL); | 460 | node = kzalloc(sizeof(struct cond_node), GFP_KERNEL); |
464 | if (!node) | 461 | if (!node) |
465 | goto err; | 462 | goto err; |
466 | memset(node, 0, sizeof(struct cond_node)); | ||
467 | 463 | ||
468 | if (cond_read_node(p, node, fp) != 0) | 464 | if (cond_read_node(p, node, fp) != 0) |
469 | goto err; | 465 | goto err; |
diff --git a/security/selinux/ss/ebitmap.c b/security/selinux/ss/ebitmap.c index d515154128cc..47024a6e1844 100644 --- a/security/selinux/ss/ebitmap.c +++ b/security/selinux/ss/ebitmap.c | |||
@@ -39,12 +39,11 @@ int ebitmap_cpy(struct ebitmap *dst, struct ebitmap *src) | |||
39 | n = src->node; | 39 | n = src->node; |
40 | prev = NULL; | 40 | prev = NULL; |
41 | while (n) { | 41 | while (n) { |
42 | new = kmalloc(sizeof(*new), GFP_ATOMIC); | 42 | new = kzalloc(sizeof(*new), GFP_ATOMIC); |
43 | if (!new) { | 43 | if (!new) { |
44 | ebitmap_destroy(dst); | 44 | ebitmap_destroy(dst); |
45 | return -ENOMEM; | 45 | return -ENOMEM; |
46 | } | 46 | } |
47 | memset(new, 0, sizeof(*new)); | ||
48 | new->startbit = n->startbit; | 47 | new->startbit = n->startbit; |
49 | new->map = n->map; | 48 | new->map = n->map; |
50 | new->next = NULL; | 49 | new->next = NULL; |
@@ -150,10 +149,9 @@ int ebitmap_set_bit(struct ebitmap *e, unsigned long bit, int value) | |||
150 | if (!value) | 149 | if (!value) |
151 | return 0; | 150 | return 0; |
152 | 151 | ||
153 | new = kmalloc(sizeof(*new), GFP_ATOMIC); | 152 | new = kzalloc(sizeof(*new), GFP_ATOMIC); |
154 | if (!new) | 153 | if (!new) |
155 | return -ENOMEM; | 154 | return -ENOMEM; |
156 | memset(new, 0, sizeof(*new)); | ||
157 | 155 | ||
158 | new->startbit = bit & ~(MAPSIZE - 1); | 156 | new->startbit = bit & ~(MAPSIZE - 1); |
159 | new->map = (MAPBIT << (bit - new->startbit)); | 157 | new->map = (MAPBIT << (bit - new->startbit)); |
@@ -232,13 +230,12 @@ int ebitmap_read(struct ebitmap *e, void *fp) | |||
232 | printk(KERN_ERR "security: ebitmap: truncated map\n"); | 230 | printk(KERN_ERR "security: ebitmap: truncated map\n"); |
233 | goto bad; | 231 | goto bad; |
234 | } | 232 | } |
235 | n = kmalloc(sizeof(*n), GFP_KERNEL); | 233 | n = kzalloc(sizeof(*n), GFP_KERNEL); |
236 | if (!n) { | 234 | if (!n) { |
237 | printk(KERN_ERR "security: ebitmap: out of memory\n"); | 235 | printk(KERN_ERR "security: ebitmap: out of memory\n"); |
238 | rc = -ENOMEM; | 236 | rc = -ENOMEM; |
239 | goto bad; | 237 | goto bad; |
240 | } | 238 | } |
241 | memset(n, 0, sizeof(*n)); | ||
242 | 239 | ||
243 | n->startbit = le32_to_cpu(buf[0]); | 240 | n->startbit = le32_to_cpu(buf[0]); |
244 | 241 | ||
diff --git a/security/selinux/ss/hashtab.c b/security/selinux/ss/hashtab.c index 26661fcc00ce..24e5ec957630 100644 --- a/security/selinux/ss/hashtab.c +++ b/security/selinux/ss/hashtab.c | |||
@@ -15,11 +15,10 @@ struct hashtab *hashtab_create(u32 (*hash_value)(struct hashtab *h, void *key), | |||
15 | struct hashtab *p; | 15 | struct hashtab *p; |
16 | u32 i; | 16 | u32 i; |
17 | 17 | ||
18 | p = kmalloc(sizeof(*p), GFP_KERNEL); | 18 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
19 | if (p == NULL) | 19 | if (p == NULL) |
20 | return p; | 20 | return p; |
21 | 21 | ||
22 | memset(p, 0, sizeof(*p)); | ||
23 | p->size = size; | 22 | p->size = size; |
24 | p->nel = 0; | 23 | p->nel = 0; |
25 | p->hash_value = hash_value; | 24 | p->hash_value = hash_value; |
@@ -55,10 +54,9 @@ int hashtab_insert(struct hashtab *h, void *key, void *datum) | |||
55 | if (cur && (h->keycmp(h, key, cur->key) == 0)) | 54 | if (cur && (h->keycmp(h, key, cur->key) == 0)) |
56 | return -EEXIST; | 55 | return -EEXIST; |
57 | 56 | ||
58 | newnode = kmalloc(sizeof(*newnode), GFP_KERNEL); | 57 | newnode = kzalloc(sizeof(*newnode), GFP_KERNEL); |
59 | if (newnode == NULL) | 58 | if (newnode == NULL) |
60 | return -ENOMEM; | 59 | return -ENOMEM; |
61 | memset(newnode, 0, sizeof(*newnode)); | ||
62 | newnode->key = key; | 60 | newnode->key = key; |
63 | newnode->datum = datum; | 61 | newnode->datum = datum; |
64 | if (prev) { | 62 | if (prev) { |
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index 8e6262d12aa9..2f5f539875f2 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c | |||
@@ -121,12 +121,11 @@ static int roles_init(struct policydb *p) | |||
121 | int rc; | 121 | int rc; |
122 | struct role_datum *role; | 122 | struct role_datum *role; |
123 | 123 | ||
124 | role = kmalloc(sizeof(*role), GFP_KERNEL); | 124 | role = kzalloc(sizeof(*role), GFP_KERNEL); |
125 | if (!role) { | 125 | if (!role) { |
126 | rc = -ENOMEM; | 126 | rc = -ENOMEM; |
127 | goto out; | 127 | goto out; |
128 | } | 128 | } |
129 | memset(role, 0, sizeof(*role)); | ||
130 | role->value = ++p->p_roles.nprim; | 129 | role->value = ++p->p_roles.nprim; |
131 | if (role->value != OBJECT_R_VAL) { | 130 | if (role->value != OBJECT_R_VAL) { |
132 | rc = -EINVAL; | 131 | rc = -EINVAL; |
@@ -851,12 +850,11 @@ static int perm_read(struct policydb *p, struct hashtab *h, void *fp) | |||
851 | __le32 buf[2]; | 850 | __le32 buf[2]; |
852 | u32 len; | 851 | u32 len; |
853 | 852 | ||
854 | perdatum = kmalloc(sizeof(*perdatum), GFP_KERNEL); | 853 | perdatum = kzalloc(sizeof(*perdatum), GFP_KERNEL); |
855 | if (!perdatum) { | 854 | if (!perdatum) { |
856 | rc = -ENOMEM; | 855 | rc = -ENOMEM; |
857 | goto out; | 856 | goto out; |
858 | } | 857 | } |
859 | memset(perdatum, 0, sizeof(*perdatum)); | ||
860 | 858 | ||
861 | rc = next_entry(buf, fp, sizeof buf); | 859 | rc = next_entry(buf, fp, sizeof buf); |
862 | if (rc < 0) | 860 | if (rc < 0) |
@@ -893,12 +891,11 @@ static int common_read(struct policydb *p, struct hashtab *h, void *fp) | |||
893 | u32 len, nel; | 891 | u32 len, nel; |
894 | int i, rc; | 892 | int i, rc; |
895 | 893 | ||
896 | comdatum = kmalloc(sizeof(*comdatum), GFP_KERNEL); | 894 | comdatum = kzalloc(sizeof(*comdatum), GFP_KERNEL); |
897 | if (!comdatum) { | 895 | if (!comdatum) { |
898 | rc = -ENOMEM; | 896 | rc = -ENOMEM; |
899 | goto out; | 897 | goto out; |
900 | } | 898 | } |
901 | memset(comdatum, 0, sizeof(*comdatum)); | ||
902 | 899 | ||
903 | rc = next_entry(buf, fp, sizeof buf); | 900 | rc = next_entry(buf, fp, sizeof buf); |
904 | if (rc < 0) | 901 | if (rc < 0) |
@@ -950,10 +947,9 @@ static int read_cons_helper(struct constraint_node **nodep, int ncons, | |||
950 | 947 | ||
951 | lc = NULL; | 948 | lc = NULL; |
952 | for (i = 0; i < ncons; i++) { | 949 | for (i = 0; i < ncons; i++) { |
953 | c = kmalloc(sizeof(*c), GFP_KERNEL); | 950 | c = kzalloc(sizeof(*c), GFP_KERNEL); |
954 | if (!c) | 951 | if (!c) |
955 | return -ENOMEM; | 952 | return -ENOMEM; |
956 | memset(c, 0, sizeof(*c)); | ||
957 | 953 | ||
958 | if (lc) { | 954 | if (lc) { |
959 | lc->next = c; | 955 | lc->next = c; |
@@ -969,10 +965,9 @@ static int read_cons_helper(struct constraint_node **nodep, int ncons, | |||
969 | le = NULL; | 965 | le = NULL; |
970 | depth = -1; | 966 | depth = -1; |
971 | for (j = 0; j < nexpr; j++) { | 967 | for (j = 0; j < nexpr; j++) { |
972 | e = kmalloc(sizeof(*e), GFP_KERNEL); | 968 | e = kzalloc(sizeof(*e), GFP_KERNEL); |
973 | if (!e) | 969 | if (!e) |
974 | return -ENOMEM; | 970 | return -ENOMEM; |
975 | memset(e, 0, sizeof(*e)); | ||
976 | 971 | ||
977 | if (le) { | 972 | if (le) { |
978 | le->next = e; | 973 | le->next = e; |
@@ -1033,12 +1028,11 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp) | |||
1033 | u32 len, len2, ncons, nel; | 1028 | u32 len, len2, ncons, nel; |
1034 | int i, rc; | 1029 | int i, rc; |
1035 | 1030 | ||
1036 | cladatum = kmalloc(sizeof(*cladatum), GFP_KERNEL); | 1031 | cladatum = kzalloc(sizeof(*cladatum), GFP_KERNEL); |
1037 | if (!cladatum) { | 1032 | if (!cladatum) { |
1038 | rc = -ENOMEM; | 1033 | rc = -ENOMEM; |
1039 | goto out; | 1034 | goto out; |
1040 | } | 1035 | } |
1041 | memset(cladatum, 0, sizeof(*cladatum)); | ||
1042 | 1036 | ||
1043 | rc = next_entry(buf, fp, sizeof(u32)*6); | 1037 | rc = next_entry(buf, fp, sizeof(u32)*6); |
1044 | if (rc < 0) | 1038 | if (rc < 0) |
@@ -1127,12 +1121,11 @@ static int role_read(struct policydb *p, struct hashtab *h, void *fp) | |||
1127 | __le32 buf[2]; | 1121 | __le32 buf[2]; |
1128 | u32 len; | 1122 | u32 len; |
1129 | 1123 | ||
1130 | role = kmalloc(sizeof(*role), GFP_KERNEL); | 1124 | role = kzalloc(sizeof(*role), GFP_KERNEL); |
1131 | if (!role) { | 1125 | if (!role) { |
1132 | rc = -ENOMEM; | 1126 | rc = -ENOMEM; |
1133 | goto out; | 1127 | goto out; |
1134 | } | 1128 | } |
1135 | memset(role, 0, sizeof(*role)); | ||
1136 | 1129 | ||
1137 | rc = next_entry(buf, fp, sizeof buf); | 1130 | rc = next_entry(buf, fp, sizeof buf); |
1138 | if (rc < 0) | 1131 | if (rc < 0) |
@@ -1188,12 +1181,11 @@ static int type_read(struct policydb *p, struct hashtab *h, void *fp) | |||
1188 | __le32 buf[3]; | 1181 | __le32 buf[3]; |
1189 | u32 len; | 1182 | u32 len; |
1190 | 1183 | ||
1191 | typdatum = kmalloc(sizeof(*typdatum),GFP_KERNEL); | 1184 | typdatum = kzalloc(sizeof(*typdatum),GFP_KERNEL); |
1192 | if (!typdatum) { | 1185 | if (!typdatum) { |
1193 | rc = -ENOMEM; | 1186 | rc = -ENOMEM; |
1194 | return rc; | 1187 | return rc; |
1195 | } | 1188 | } |
1196 | memset(typdatum, 0, sizeof(*typdatum)); | ||
1197 | 1189 | ||
1198 | rc = next_entry(buf, fp, sizeof buf); | 1190 | rc = next_entry(buf, fp, sizeof buf); |
1199 | if (rc < 0) | 1191 | if (rc < 0) |
@@ -1261,12 +1253,11 @@ static int user_read(struct policydb *p, struct hashtab *h, void *fp) | |||
1261 | __le32 buf[2]; | 1253 | __le32 buf[2]; |
1262 | u32 len; | 1254 | u32 len; |
1263 | 1255 | ||
1264 | usrdatum = kmalloc(sizeof(*usrdatum), GFP_KERNEL); | 1256 | usrdatum = kzalloc(sizeof(*usrdatum), GFP_KERNEL); |
1265 | if (!usrdatum) { | 1257 | if (!usrdatum) { |
1266 | rc = -ENOMEM; | 1258 | rc = -ENOMEM; |
1267 | goto out; | 1259 | goto out; |
1268 | } | 1260 | } |
1269 | memset(usrdatum, 0, sizeof(*usrdatum)); | ||
1270 | 1261 | ||
1271 | rc = next_entry(buf, fp, sizeof buf); | 1262 | rc = next_entry(buf, fp, sizeof buf); |
1272 | if (rc < 0) | 1263 | if (rc < 0) |
@@ -1316,12 +1307,11 @@ static int sens_read(struct policydb *p, struct hashtab *h, void *fp) | |||
1316 | __le32 buf[2]; | 1307 | __le32 buf[2]; |
1317 | u32 len; | 1308 | u32 len; |
1318 | 1309 | ||
1319 | levdatum = kmalloc(sizeof(*levdatum), GFP_ATOMIC); | 1310 | levdatum = kzalloc(sizeof(*levdatum), GFP_ATOMIC); |
1320 | if (!levdatum) { | 1311 | if (!levdatum) { |
1321 | rc = -ENOMEM; | 1312 | rc = -ENOMEM; |
1322 | goto out; | 1313 | goto out; |
1323 | } | 1314 | } |
1324 | memset(levdatum, 0, sizeof(*levdatum)); | ||
1325 | 1315 | ||
1326 | rc = next_entry(buf, fp, sizeof buf); | 1316 | rc = next_entry(buf, fp, sizeof buf); |
1327 | if (rc < 0) | 1317 | if (rc < 0) |
@@ -1368,12 +1358,11 @@ static int cat_read(struct policydb *p, struct hashtab *h, void *fp) | |||
1368 | __le32 buf[3]; | 1358 | __le32 buf[3]; |
1369 | u32 len; | 1359 | u32 len; |
1370 | 1360 | ||
1371 | catdatum = kmalloc(sizeof(*catdatum), GFP_ATOMIC); | 1361 | catdatum = kzalloc(sizeof(*catdatum), GFP_ATOMIC); |
1372 | if (!catdatum) { | 1362 | if (!catdatum) { |
1373 | rc = -ENOMEM; | 1363 | rc = -ENOMEM; |
1374 | goto out; | 1364 | goto out; |
1375 | } | 1365 | } |
1376 | memset(catdatum, 0, sizeof(*catdatum)); | ||
1377 | 1366 | ||
1378 | rc = next_entry(buf, fp, sizeof buf); | 1367 | rc = next_entry(buf, fp, sizeof buf); |
1379 | if (rc < 0) | 1368 | if (rc < 0) |
@@ -1567,12 +1556,11 @@ int policydb_read(struct policydb *p, void *fp) | |||
1567 | nel = le32_to_cpu(buf[0]); | 1556 | nel = le32_to_cpu(buf[0]); |
1568 | ltr = NULL; | 1557 | ltr = NULL; |
1569 | for (i = 0; i < nel; i++) { | 1558 | for (i = 0; i < nel; i++) { |
1570 | tr = kmalloc(sizeof(*tr), GFP_KERNEL); | 1559 | tr = kzalloc(sizeof(*tr), GFP_KERNEL); |
1571 | if (!tr) { | 1560 | if (!tr) { |
1572 | rc = -ENOMEM; | 1561 | rc = -ENOMEM; |
1573 | goto bad; | 1562 | goto bad; |
1574 | } | 1563 | } |
1575 | memset(tr, 0, sizeof(*tr)); | ||
1576 | if (ltr) { | 1564 | if (ltr) { |
1577 | ltr->next = tr; | 1565 | ltr->next = tr; |
1578 | } else { | 1566 | } else { |
@@ -1593,12 +1581,11 @@ int policydb_read(struct policydb *p, void *fp) | |||
1593 | nel = le32_to_cpu(buf[0]); | 1581 | nel = le32_to_cpu(buf[0]); |
1594 | lra = NULL; | 1582 | lra = NULL; |
1595 | for (i = 0; i < nel; i++) { | 1583 | for (i = 0; i < nel; i++) { |
1596 | ra = kmalloc(sizeof(*ra), GFP_KERNEL); | 1584 | ra = kzalloc(sizeof(*ra), GFP_KERNEL); |
1597 | if (!ra) { | 1585 | if (!ra) { |
1598 | rc = -ENOMEM; | 1586 | rc = -ENOMEM; |
1599 | goto bad; | 1587 | goto bad; |
1600 | } | 1588 | } |
1601 | memset(ra, 0, sizeof(*ra)); | ||
1602 | if (lra) { | 1589 | if (lra) { |
1603 | lra->next = ra; | 1590 | lra->next = ra; |
1604 | } else { | 1591 | } else { |
@@ -1627,12 +1614,11 @@ int policydb_read(struct policydb *p, void *fp) | |||
1627 | nel = le32_to_cpu(buf[0]); | 1614 | nel = le32_to_cpu(buf[0]); |
1628 | l = NULL; | 1615 | l = NULL; |
1629 | for (j = 0; j < nel; j++) { | 1616 | for (j = 0; j < nel; j++) { |
1630 | c = kmalloc(sizeof(*c), GFP_KERNEL); | 1617 | c = kzalloc(sizeof(*c), GFP_KERNEL); |
1631 | if (!c) { | 1618 | if (!c) { |
1632 | rc = -ENOMEM; | 1619 | rc = -ENOMEM; |
1633 | goto bad; | 1620 | goto bad; |
1634 | } | 1621 | } |
1635 | memset(c, 0, sizeof(*c)); | ||
1636 | if (l) { | 1622 | if (l) { |
1637 | l->next = c; | 1623 | l->next = c; |
1638 | } else { | 1624 | } else { |
@@ -1743,12 +1729,11 @@ int policydb_read(struct policydb *p, void *fp) | |||
1743 | if (rc < 0) | 1729 | if (rc < 0) |
1744 | goto bad; | 1730 | goto bad; |
1745 | len = le32_to_cpu(buf[0]); | 1731 | len = le32_to_cpu(buf[0]); |
1746 | newgenfs = kmalloc(sizeof(*newgenfs), GFP_KERNEL); | 1732 | newgenfs = kzalloc(sizeof(*newgenfs), GFP_KERNEL); |
1747 | if (!newgenfs) { | 1733 | if (!newgenfs) { |
1748 | rc = -ENOMEM; | 1734 | rc = -ENOMEM; |
1749 | goto bad; | 1735 | goto bad; |
1750 | } | 1736 | } |
1751 | memset(newgenfs, 0, sizeof(*newgenfs)); | ||
1752 | 1737 | ||
1753 | newgenfs->fstype = kmalloc(len + 1,GFP_KERNEL); | 1738 | newgenfs->fstype = kmalloc(len + 1,GFP_KERNEL); |
1754 | if (!newgenfs->fstype) { | 1739 | if (!newgenfs->fstype) { |
@@ -1790,12 +1775,11 @@ int policydb_read(struct policydb *p, void *fp) | |||
1790 | goto bad; | 1775 | goto bad; |
1791 | len = le32_to_cpu(buf[0]); | 1776 | len = le32_to_cpu(buf[0]); |
1792 | 1777 | ||
1793 | newc = kmalloc(sizeof(*newc), GFP_KERNEL); | 1778 | newc = kzalloc(sizeof(*newc), GFP_KERNEL); |
1794 | if (!newc) { | 1779 | if (!newc) { |
1795 | rc = -ENOMEM; | 1780 | rc = -ENOMEM; |
1796 | goto bad; | 1781 | goto bad; |
1797 | } | 1782 | } |
1798 | memset(newc, 0, sizeof(*newc)); | ||
1799 | 1783 | ||
1800 | newc->u.name = kmalloc(len + 1,GFP_KERNEL); | 1784 | newc->u.name = kmalloc(len + 1,GFP_KERNEL); |
1801 | if (!newc->u.name) { | 1785 | if (!newc->u.name) { |
@@ -1843,12 +1827,11 @@ int policydb_read(struct policydb *p, void *fp) | |||
1843 | nel = le32_to_cpu(buf[0]); | 1827 | nel = le32_to_cpu(buf[0]); |
1844 | lrt = NULL; | 1828 | lrt = NULL; |
1845 | for (i = 0; i < nel; i++) { | 1829 | for (i = 0; i < nel; i++) { |
1846 | rt = kmalloc(sizeof(*rt), GFP_KERNEL); | 1830 | rt = kzalloc(sizeof(*rt), GFP_KERNEL); |
1847 | if (!rt) { | 1831 | if (!rt) { |
1848 | rc = -ENOMEM; | 1832 | rc = -ENOMEM; |
1849 | goto bad; | 1833 | goto bad; |
1850 | } | 1834 | } |
1851 | memset(rt, 0, sizeof(*rt)); | ||
1852 | if (lrt) | 1835 | if (lrt) |
1853 | lrt->next = rt; | 1836 | lrt->next = rt; |
1854 | else | 1837 | else |
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c index aecdded55e74..44eb4d74908d 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c | |||
@@ -1531,12 +1531,11 @@ int security_get_user_sids(u32 fromsid, | |||
1531 | } | 1531 | } |
1532 | usercon.user = user->value; | 1532 | usercon.user = user->value; |
1533 | 1533 | ||
1534 | mysids = kmalloc(maxnel*sizeof(*mysids), GFP_ATOMIC); | 1534 | mysids = kcalloc(maxnel, sizeof(*mysids), GFP_ATOMIC); |
1535 | if (!mysids) { | 1535 | if (!mysids) { |
1536 | rc = -ENOMEM; | 1536 | rc = -ENOMEM; |
1537 | goto out_unlock; | 1537 | goto out_unlock; |
1538 | } | 1538 | } |
1539 | memset(mysids, 0, maxnel*sizeof(*mysids)); | ||
1540 | 1539 | ||
1541 | ebitmap_for_each_bit(&user->roles, rnode, i) { | 1540 | ebitmap_for_each_bit(&user->roles, rnode, i) { |
1542 | if (!ebitmap_node_get_bit(rnode, i)) | 1541 | if (!ebitmap_node_get_bit(rnode, i)) |
@@ -1566,13 +1565,12 @@ int security_get_user_sids(u32 fromsid, | |||
1566 | mysids[mynel++] = sid; | 1565 | mysids[mynel++] = sid; |
1567 | } else { | 1566 | } else { |
1568 | maxnel += SIDS_NEL; | 1567 | maxnel += SIDS_NEL; |
1569 | mysids2 = kmalloc(maxnel*sizeof(*mysids2), GFP_ATOMIC); | 1568 | mysids2 = kcalloc(maxnel, sizeof(*mysids2), GFP_ATOMIC); |
1570 | if (!mysids2) { | 1569 | if (!mysids2) { |
1571 | rc = -ENOMEM; | 1570 | rc = -ENOMEM; |
1572 | kfree(mysids); | 1571 | kfree(mysids); |
1573 | goto out_unlock; | 1572 | goto out_unlock; |
1574 | } | 1573 | } |
1575 | memset(mysids2, 0, maxnel*sizeof(*mysids2)); | ||
1576 | memcpy(mysids2, mysids, mynel * sizeof(*mysids2)); | 1574 | memcpy(mysids2, mysids, mynel * sizeof(*mysids2)); |
1577 | kfree(mysids); | 1575 | kfree(mysids); |
1578 | mysids = mysids2; | 1576 | mysids = mysids2; |
@@ -1714,12 +1712,11 @@ int security_get_bools(int *len, char ***names, int **values) | |||
1714 | goto out; | 1712 | goto out; |
1715 | } | 1713 | } |
1716 | 1714 | ||
1717 | *names = (char**)kmalloc(sizeof(char*) * *len, GFP_ATOMIC); | 1715 | *names = (char**)kcalloc(*len, sizeof(char*), GFP_ATOMIC); |
1718 | if (!*names) | 1716 | if (!*names) |
1719 | goto err; | 1717 | goto err; |
1720 | memset(*names, 0, sizeof(char*) * *len); | ||
1721 | 1718 | ||
1722 | *values = (int*)kmalloc(sizeof(int) * *len, GFP_ATOMIC); | 1719 | *values = (int*)kcalloc(*len, sizeof(int), GFP_ATOMIC); |
1723 | if (!*values) | 1720 | if (!*values) |
1724 | goto err; | 1721 | goto err; |
1725 | 1722 | ||