Skip to content

Commit e456ef8

Browse files
tych0Mimi Zohar
authored andcommitted
ima: drop vla in ima_audit_measurement()
In keeping with the directive to get rid of VLAs [1], let's drop the VLA from ima_audit_measurement(). We need to adjust the return type of ima_audit_measurement, because now this function can fail if an allocation fails. [1]: https://lkml.org/lkml/2018/3/7/621 v2: just use audit_log_format instead of doing a second allocation v3: ignore failures in ima_audit_measurement() Signed-off-by: Tycho Andersen <[email protected]> Signed-off-by: Mimi Zohar <[email protected]>
1 parent fac37c6 commit e456ef8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

security/integrity/ima/ima_api.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,33 +311,37 @@ void ima_audit_measurement(struct integrity_iint_cache *iint,
311311
const unsigned char *filename)
312312
{
313313
struct audit_buffer *ab;
314-
char hash[(iint->ima_hash->length * 2) + 1];
314+
char *hash;
315315
const char *algo_name = hash_algo_name[iint->ima_hash->algo];
316-
char algo_hash[sizeof(hash) + strlen(algo_name) + 2];
317316
int i;
318317

319318
if (iint->flags & IMA_AUDITED)
320319
return;
321320

321+
hash = kzalloc((iint->ima_hash->length * 2) + 1, GFP_KERNEL);
322+
if (!hash)
323+
return;
324+
322325
for (i = 0; i < iint->ima_hash->length; i++)
323326
hex_byte_pack(hash + (i * 2), iint->ima_hash->digest[i]);
324327
hash[i * 2] = '\0';
325328

326329
ab = audit_log_start(current->audit_context, GFP_KERNEL,
327330
AUDIT_INTEGRITY_RULE);
328331
if (!ab)
329-
return;
332+
goto out;
330333

331334
audit_log_format(ab, "file=");
332335
audit_log_untrustedstring(ab, filename);
333-
audit_log_format(ab, " hash=");
334-
snprintf(algo_hash, sizeof(algo_hash), "%s:%s", algo_name, hash);
335-
audit_log_untrustedstring(ab, algo_hash);
336+
audit_log_format(ab, " hash=\"%s:%s\"", algo_name, hash);
336337

337338
audit_log_task_info(ab, current);
338339
audit_log_end(ab);
339340

340341
iint->flags |= IMA_AUDITED;
342+
out:
343+
kfree(hash);
344+
return;
341345
}
342346

343347
/*

0 commit comments

Comments
 (0)