diff options
author | Roberto Sassu <roberto.sassu@polito.it> | 2013-11-25 14:18:52 -0500 |
---|---|---|
committer | Mimi Zohar <zohar@linux.vnet.ibm.com> | 2013-11-25 15:05:33 -0500 |
commit | dbc335d2dc3c437649eb6b39f4e9aee2a13eb0af (patch) | |
tree | b070f9d96f16ae2abf4c6a5b824d2b6c82716da2 /security | |
parent | 3e8e5503a33577d89bdb7469b851b11f507bbed6 (diff) |
ima: make a copy of template_fmt in template_desc_init_fields()
This patch makes a copy of the 'template_fmt' function argument so that
the latter will not be modified by strsep(), which does the splitting by
replacing the given separator with '\0'.
IMA: No TPM chip found, activating TPM-bypass!
Unable to handle kernel pointer dereference at virtual kernel address 0000000000842000
Oops: 0004 [#1] SMP
Modules linked in:
CPU: 3 PID: 1 Comm: swapper/0 Not tainted 3.12.0-rc2-00098-g3ce1217d6cd5 #17
task: 000000003ffa0000 ti: 000000003ff84000 task.ti: 000000003ff84000
Krnl PSW : 0704e00180000000 000000000044bf88 (strsep+0x7c/0xa0)
R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:2 PM:0 EA:3
Krnl GPRS: 000000000000007c 000000000000007c 000000003ff87d90 0000000000821fd8
0000000000000000 000000000000007c 0000000000aa37e0 0000000000aa9008
0000000000000051 0000000000a114d8 0000000100000002 0000000000842bde
0000000000842bdf 00000000006f97f0 000000000040062c 000000003ff87cf0
Krnl Code: 000000000044bf7c: a7f4000a brc 15,44bf90
000000000044bf80: b90200cc ltgr %r12,%r12
#000000000044bf84: a7840006 brc 8,44bf90
>000000000044bf88: 9200c000 mvi 0(%r12),0
000000000044bf8c: 41c0c001 la %r12,1(%r12)
000000000044bf90: e3c020000024 stg %r12,0(%r2)
000000000044bf96: b904002b lgr %r2,%r11
000000000044bf9a: ebbcf0700004 lmg %r11,%r12,112(%r15)
Call Trace:
([<00000000004005fe>] ima_init_template+0xa2/0x1bc)
[<0000000000a7c896>] ima_init+0x7a/0xa8
[<0000000000a7c938>] init_ima+0x24/0x40
[<00000000001000e8>] do_one_initcall+0x68/0x128
[<0000000000a4eb56>] kernel_init_freeable+0x20a/0x2b4
[<00000000006a1ff4>] kernel_init+0x30/0x178
[<00000000006b69fe>] kernel_thread_starter+0x6/0xc
[<00000000006b69f8>] kernel_thread_starter+0x0/0xc
Last Breaking-Event-Address:
[<000000000044bf42>] strsep+0x36/0xa0
Fixes commit: adf53a7 ima: new templates management mechanism
Changelog v1:
- make template_fmt 'const char *' (reported-by James Morris)
- fix kstrdup memory leak (reported-by James Morris)
Reported-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Roberto Sassu <roberto.sassu@polito.it>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
Tested-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Diffstat (limited to 'security')
-rw-r--r-- | security/integrity/ima/ima_template.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/security/integrity/ima/ima_template.c b/security/integrity/ima/ima_template.c index 4e5da990630b..913e1927f916 100644 --- a/security/integrity/ima/ima_template.c +++ b/security/integrity/ima/ima_template.c | |||
@@ -90,7 +90,7 @@ static struct ima_template_field *lookup_template_field(const char *field_id) | |||
90 | return NULL; | 90 | return NULL; |
91 | } | 91 | } |
92 | 92 | ||
93 | static int template_fmt_size(char *template_fmt) | 93 | static int template_fmt_size(const char *template_fmt) |
94 | { | 94 | { |
95 | char c; | 95 | char c; |
96 | int template_fmt_len = strlen(template_fmt); | 96 | int template_fmt_len = strlen(template_fmt); |
@@ -106,23 +106,28 @@ static int template_fmt_size(char *template_fmt) | |||
106 | return j + 1; | 106 | return j + 1; |
107 | } | 107 | } |
108 | 108 | ||
109 | static int template_desc_init_fields(char *template_fmt, | 109 | static int template_desc_init_fields(const char *template_fmt, |
110 | struct ima_template_field ***fields, | 110 | struct ima_template_field ***fields, |
111 | int *num_fields) | 111 | int *num_fields) |
112 | { | 112 | { |
113 | char *c, *template_fmt_ptr = template_fmt; | 113 | char *c, *template_fmt_copy; |
114 | int template_num_fields = template_fmt_size(template_fmt); | 114 | int template_num_fields = template_fmt_size(template_fmt); |
115 | int i, result = 0; | 115 | int i, result = 0; |
116 | 116 | ||
117 | if (template_num_fields > IMA_TEMPLATE_NUM_FIELDS_MAX) | 117 | if (template_num_fields > IMA_TEMPLATE_NUM_FIELDS_MAX) |
118 | return -EINVAL; | 118 | return -EINVAL; |
119 | 119 | ||
120 | /* copying is needed as strsep() modifies the original buffer */ | ||
121 | template_fmt_copy = kstrdup(template_fmt, GFP_KERNEL); | ||
122 | if (template_fmt_copy == NULL) | ||
123 | return -ENOMEM; | ||
124 | |||
120 | *fields = kzalloc(template_num_fields * sizeof(*fields), GFP_KERNEL); | 125 | *fields = kzalloc(template_num_fields * sizeof(*fields), GFP_KERNEL); |
121 | if (*fields == NULL) { | 126 | if (*fields == NULL) { |
122 | result = -ENOMEM; | 127 | result = -ENOMEM; |
123 | goto out; | 128 | goto out; |
124 | } | 129 | } |
125 | for (i = 0; (c = strsep(&template_fmt_ptr, "|")) != NULL && | 130 | for (i = 0; (c = strsep(&template_fmt_copy, "|")) != NULL && |
126 | i < template_num_fields; i++) { | 131 | i < template_num_fields; i++) { |
127 | struct ima_template_field *f = lookup_template_field(c); | 132 | struct ima_template_field *f = lookup_template_field(c); |
128 | 133 | ||
@@ -133,10 +138,12 @@ static int template_desc_init_fields(char *template_fmt, | |||
133 | (*fields)[i] = f; | 138 | (*fields)[i] = f; |
134 | } | 139 | } |
135 | *num_fields = i; | 140 | *num_fields = i; |
136 | return 0; | ||
137 | out: | 141 | out: |
138 | kfree(*fields); | 142 | if (result < 0) { |
139 | *fields = NULL; | 143 | kfree(*fields); |
144 | *fields = NULL; | ||
145 | } | ||
146 | kfree(template_fmt_copy); | ||
140 | return result; | 147 | return result; |
141 | } | 148 | } |
142 | 149 | ||