Skip to content

Commit 923168a

Browse files
samasth-norwaymimizohar
authored andcommitted
ima: fix buffer overrun in ima_eventdigest_init_common
Function ima_eventdigest_init() calls ima_eventdigest_init_common() with HASH_ALGO__LAST which is then used to access the array hash_digest_size[] leading to buffer overrun. Have a conditional statement to handle this. Fixes: 9fab303 ("ima: fix violation measurement list record") Signed-off-by: Samasth Norway Ananda <[email protected]> Tested-by: Enrico Bravi (PhD at polito.it) <[email protected]> Cc: [email protected] # 5.19+ Signed-off-by: Mimi Zohar <[email protected]>
1 parent 8cf0b93 commit 923168a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

security/integrity/ima/ima_template_lib.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,21 @@ static int ima_eventdigest_init_common(const u8 *digest, u32 digestsize,
318318
hash_algo_name[hash_algo]);
319319
}
320320

321-
if (digest)
321+
if (digest) {
322322
memcpy(buffer + offset, digest, digestsize);
323-
else
323+
} else {
324324
/*
325325
* If digest is NULL, the event being recorded is a violation.
326326
* Make room for the digest by increasing the offset by the
327-
* hash algorithm digest size.
327+
* hash algorithm digest size. If the hash algorithm is not
328+
* specified increase the offset by IMA_DIGEST_SIZE which
329+
* fits SHA1 or MD5
328330
*/
329-
offset += hash_digest_size[hash_algo];
331+
if (hash_algo < HASH_ALGO__LAST)
332+
offset += hash_digest_size[hash_algo];
333+
else
334+
offset += IMA_DIGEST_SIZE;
335+
}
330336

331337
return ima_write_template_field_data(buffer, offset + digestsize,
332338
fmt, field_data);

0 commit comments

Comments
 (0)