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
6 Signed-off-by: John Johansen <john.johansen@canonical.com>
7 Acked-by: Steve Beattie <sbeattie@ubuntu.com>
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
17 +#include <linux/slab.h>
21 @@ -64,9 +65,18 @@ extern int apparmor_initialized __initdata;
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);
29 +static inline void *kvmalloc(size_t size)
31 + return __aa_kvmalloc(size, 0);
34 +static inline void *kvzalloc(size_t size)
36 + return __aa_kvmalloc(size, __GFP_ZERO);
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)
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).
55 * Return: allocated buffer or NULL if failed
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.
60 -void *kvmalloc(size_t size)
61 +void *__aa_kvmalloc(size_t size, gfp_t flags)
65 @@ -92,14 +93,17 @@ void *kvmalloc(size_t size)
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);
72 /* see kvfree for why size must be at least work_struct size
73 * when allocated via vmalloc
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);
81 + buffer = vmalloc(size);
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
91 * Returns: pointer to table else NULL on failure
93 - * NOTE: must be freed by kvfree (not kmalloc)
94 + * NOTE: must be freed by kvfree (not kfree)
96 static struct table_header *unpack_table(char *blob, size_t bsize)
98 @@ -57,7 +57,7 @@ static struct table_header *unpack_table(char *blob, size_t bsize)
102 - table = kvmalloc(tsize);
103 + table = kvzalloc(tsize);
106 if (th.td_flags == YYTD_DATA8)