diff options
author | John Johansen <john.johansen@canonical.com> | 2013-02-18 19:04:34 -0500 |
---|---|---|
committer | John Johansen <john.johansen@canonical.com> | 2013-04-28 03:36:09 -0400 |
commit | 0ca554b9fca425eb58325a36290deef698cef34b (patch) | |
tree | aa9cd7544db53f617f8bf6b0e441f97a55ed4181 /security | |
parent | 3cfcc19e0b5390c04cb5bfa4e8fde39395410e61 (diff) |
apparmor: add kvzalloc to handle zeroing for kvmalloc
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
Diffstat (limited to 'security')
-rw-r--r-- | security/apparmor/include/apparmor.h | 12 | ||||
-rw-r--r-- | security/apparmor/lib.c | 14 | ||||
-rw-r--r-- | security/apparmor/match.c | 4 |
3 files changed, 22 insertions, 8 deletions
diff --git a/security/apparmor/include/apparmor.h b/security/apparmor/include/apparmor.h index 40aedd9f73ea..1ba2ca56a6ef 100644 --- a/security/apparmor/include/apparmor.h +++ b/security/apparmor/include/apparmor.h | |||
@@ -15,6 +15,7 @@ | |||
15 | #ifndef __APPARMOR_H | 15 | #ifndef __APPARMOR_H |
16 | #define __APPARMOR_H | 16 | #define __APPARMOR_H |
17 | 17 | ||
18 | #include <linux/slab.h> | ||
18 | #include <linux/fs.h> | 19 | #include <linux/fs.h> |
19 | 20 | ||
20 | #include "match.h" | 21 | #include "match.h" |
@@ -64,9 +65,18 @@ extern int apparmor_initialized __initdata; | |||
64 | /* fn's in lib */ | 65 | /* fn's in lib */ |
65 | char *aa_split_fqname(char *args, char **ns_name); | 66 | char *aa_split_fqname(char *args, char **ns_name); |
66 | void aa_info_message(const char *str); | 67 | void aa_info_message(const char *str); |
67 | void *kvmalloc(size_t size); | 68 | void *__aa_kvmalloc(size_t size, gfp_t flags); |
68 | void kvfree(void *buffer); | 69 | void kvfree(void *buffer); |
69 | 70 | ||
71 | static inline void *kvmalloc(size_t size) | ||
72 | { | ||
73 | return __aa_kvmalloc(size, 0); | ||
74 | } | ||
75 | |||
76 | static inline void *kvzalloc(size_t size) | ||
77 | { | ||
78 | return __aa_kvmalloc(size, __GFP_ZERO); | ||
79 | } | ||
70 | 80 | ||
71 | /** | 81 | /** |
72 | * aa_strneq - compare null terminated @str to a non null terminated substring | 82 | * aa_strneq - compare null terminated @str to a non null terminated substring |
diff --git a/security/apparmor/lib.c b/security/apparmor/lib.c index 7430298116d6..d6e1f2148398 100644 --- a/security/apparmor/lib.c +++ b/security/apparmor/lib.c | |||
@@ -75,15 +75,16 @@ void aa_info_message(const char *str) | |||
75 | } | 75 | } |
76 | 76 | ||
77 | /** | 77 | /** |
78 | * kvmalloc - do allocation preferring kmalloc but falling back to vmalloc | 78 | * __aa_kvmalloc - do allocation preferring kmalloc but falling back to vmalloc |
79 | * @size: size of allocation | 79 | * @size: how many bytes of memory are required |
80 | * @flags: the type of memory to allocate (see kmalloc). | ||
80 | * | 81 | * |
81 | * Return: allocated buffer or NULL if failed | 82 | * Return: allocated buffer or NULL if failed |
82 | * | 83 | * |
83 | * It is possible that policy being loaded from the user is larger than | 84 | * It is possible that policy being loaded from the user is larger than |
84 | * what can be allocated by kmalloc, in those cases fall back to vmalloc. | 85 | * what can be allocated by kmalloc, in those cases fall back to vmalloc. |
85 | */ | 86 | */ |
86 | void *kvmalloc(size_t size) | 87 | void *__aa_kvmalloc(size_t size, gfp_t flags) |
87 | { | 88 | { |
88 | void *buffer = NULL; | 89 | void *buffer = NULL; |
89 | 90 | ||
@@ -92,14 +93,17 @@ void *kvmalloc(size_t size) | |||
92 | 93 | ||
93 | /* do not attempt kmalloc if we need more than 16 pages at once */ | 94 | /* do not attempt kmalloc if we need more than 16 pages at once */ |
94 | if (size <= (16*PAGE_SIZE)) | 95 | if (size <= (16*PAGE_SIZE)) |
95 | buffer = kmalloc(size, GFP_NOIO | __GFP_NOWARN); | 96 | buffer = kmalloc(size, flags | GFP_NOIO | __GFP_NOWARN); |
96 | if (!buffer) { | 97 | if (!buffer) { |
97 | /* see kvfree for why size must be at least work_struct size | 98 | /* see kvfree for why size must be at least work_struct size |
98 | * when allocated via vmalloc | 99 | * when allocated via vmalloc |
99 | */ | 100 | */ |
100 | if (size < sizeof(struct work_struct)) | 101 | if (size < sizeof(struct work_struct)) |
101 | size = sizeof(struct work_struct); | 102 | size = sizeof(struct work_struct); |
102 | buffer = vmalloc(size); | 103 | if (flags & __GFP_ZERO) |
104 | buffer = vzalloc(size); | ||
105 | else | ||
106 | buffer = vmalloc(size); | ||
103 | } | 107 | } |
104 | return buffer; | 108 | return buffer; |
105 | } | 109 | } |
diff --git a/security/apparmor/match.c b/security/apparmor/match.c index 90971a8c3789..dfd25a9c9a69 100644 --- a/security/apparmor/match.c +++ b/security/apparmor/match.c | |||
@@ -30,7 +30,7 @@ | |||
30 | * | 30 | * |
31 | * Returns: pointer to table else NULL on failure | 31 | * Returns: pointer to table else NULL on failure |
32 | * | 32 | * |
33 | * NOTE: must be freed by kvfree (not kmalloc) | 33 | * NOTE: must be freed by kvfree (not kfree) |
34 | */ | 34 | */ |
35 | static struct table_header *unpack_table(char *blob, size_t bsize) | 35 | static struct table_header *unpack_table(char *blob, size_t bsize) |
36 | { | 36 | { |
@@ -57,7 +57,7 @@ static struct table_header *unpack_table(char *blob, size_t bsize) | |||
57 | if (bsize < tsize) | 57 | if (bsize < tsize) |
58 | goto out; | 58 | goto out; |
59 | 59 | ||
60 | table = kvmalloc(tsize); | 60 | table = kvzalloc(tsize); |
61 | if (table) { | 61 | if (table) { |
62 | *table = th; | 62 | *table = th; |
63 | if (th.td_flags == YYTD_DATA8) | 63 | if (th.td_flags == YYTD_DATA8) |