]>
Commit | Line | Data |
---|---|---|
37e96ed9 DM |
1 | From 0ca554b9fca425eb58325a36290deef698cef34b Mon Sep 17 00:00:00 2001 |
2 | From: John Johansen <john.johansen@canonical.com> | |
3 | Date: Mon, 18 Feb 2013 16:04:34 -0800 | |
4 | Subject: apparmor: add kvzalloc to handle zeroing for kvmalloc | |
5 | ||
6 | Signed-off-by: John Johansen <john.johansen@canonical.com> | |
7 | Acked-by: Steve Beattie <sbeattie@ubuntu.com> | |
8 | ||
9 | diff --git a/security/apparmor/include/apparmor.h b/security/apparmor/include/apparmor.h | |
10 | index 40aedd9..1ba2ca5 100644 | |
11 | --- a/security/apparmor/include/apparmor.h | |
12 | +++ b/security/apparmor/include/apparmor.h | |
13 | @@ -15,6 +15,7 @@ | |
14 | #ifndef __APPARMOR_H | |
15 | #define __APPARMOR_H | |
16 | ||
17 | +#include <linux/slab.h> | |
18 | #include <linux/fs.h> | |
19 | ||
20 | #include "match.h" | |
21 | @@ -64,9 +65,18 @@ extern int apparmor_initialized __initdata; | |
22 | /* fn's in lib */ | |
23 | char *aa_split_fqname(char *args, char **ns_name); | |
24 | void aa_info_message(const char *str); | |
25 | -void *kvmalloc(size_t size); | |
26 | +void *__aa_kvmalloc(size_t size, gfp_t flags); | |
27 | void kvfree(void *buffer); | |
28 | ||
29 | +static inline void *kvmalloc(size_t size) | |
30 | +{ | |
31 | + return __aa_kvmalloc(size, 0); | |
32 | +} | |
33 | + | |
34 | +static inline void *kvzalloc(size_t size) | |
35 | +{ | |
36 | + return __aa_kvmalloc(size, __GFP_ZERO); | |
37 | +} | |
38 | ||
39 | /** | |
40 | * aa_strneq - compare null terminated @str to a non null terminated substring | |
41 | diff --git a/security/apparmor/lib.c b/security/apparmor/lib.c | |
42 | index 7430298..d6e1f21 100644 | |
43 | --- a/security/apparmor/lib.c | |
44 | +++ b/security/apparmor/lib.c | |
45 | @@ -75,15 +75,16 @@ void aa_info_message(const char *str) | |
46 | } | |
47 | ||
48 | /** | |
49 | - * kvmalloc - do allocation preferring kmalloc but falling back to vmalloc | |
50 | - * @size: size of allocation | |
51 | + * __aa_kvmalloc - do allocation preferring kmalloc but falling back to vmalloc | |
52 | + * @size: how many bytes of memory are required | |
53 | + * @flags: the type of memory to allocate (see kmalloc). | |
54 | * | |
55 | * Return: allocated buffer or NULL if failed | |
56 | * | |
57 | * It is possible that policy being loaded from the user is larger than | |
58 | * what can be allocated by kmalloc, in those cases fall back to vmalloc. | |
59 | */ | |
60 | -void *kvmalloc(size_t size) | |
61 | +void *__aa_kvmalloc(size_t size, gfp_t flags) | |
62 | { | |
63 | void *buffer = NULL; | |
64 | ||
65 | @@ -92,14 +93,17 @@ void *kvmalloc(size_t size) | |
66 | ||
67 | /* do not attempt kmalloc if we need more than 16 pages at once */ | |
68 | if (size <= (16*PAGE_SIZE)) | |
69 | - buffer = kmalloc(size, GFP_NOIO | __GFP_NOWARN); | |
70 | + buffer = kmalloc(size, flags | GFP_NOIO | __GFP_NOWARN); | |
71 | if (!buffer) { | |
72 | /* see kvfree for why size must be at least work_struct size | |
73 | * when allocated via vmalloc | |
74 | */ | |
75 | if (size < sizeof(struct work_struct)) | |
76 | size = sizeof(struct work_struct); | |
77 | - buffer = vmalloc(size); | |
78 | + if (flags & __GFP_ZERO) | |
79 | + buffer = vzalloc(size); | |
80 | + else | |
81 | + buffer = vmalloc(size); | |
82 | } | |
83 | return buffer; | |
84 | } | |
85 | diff --git a/security/apparmor/match.c b/security/apparmor/match.c | |
86 | index 90971a8..dfd25a9 100644 | |
87 | --- a/security/apparmor/match.c | |
88 | +++ b/security/apparmor/match.c | |
89 | @@ -30,7 +30,7 @@ | |
90 | * | |
91 | * Returns: pointer to table else NULL on failure | |
92 | * | |
93 | - * NOTE: must be freed by kvfree (not kmalloc) | |
94 | + * NOTE: must be freed by kvfree (not kfree) | |
95 | */ | |
96 | static struct table_header *unpack_table(char *blob, size_t bsize) | |
97 | { | |
98 | @@ -57,7 +57,7 @@ static struct table_header *unpack_table(char *blob, size_t bsize) | |
99 | if (bsize < tsize) | |
100 | goto out; | |
101 | ||
102 | - table = kvmalloc(tsize); | |
103 | + table = kvzalloc(tsize); | |
104 | if (table) { | |
105 | *table = th; | |
106 | if (th.td_flags == YYTD_DATA8) | |
107 | -- | |
108 | cgit v0.10.2 | |
109 |