Skip to content

Commit 96c9e1d

Browse files
Patrick Callaghanmimizohar
authored andcommitted
ima: avoid appraise error for hash calc interrupt
The integrity_kernel_read() call in ima_calc_file_hash_tfm() can return a value of 0 before all bytes of the file are read. A value of 0 would normally indicate an EOF. This has been observed if a user process is causing a file appraisal and is terminated with a SIGTERM signal. The most common occurrence of seeing the problem is if a shutdown or systemd reload is initiated while files are being appraised. The problem is similar to commit <f5e1040196db> (ima: always return negative code for error) that fixed the problem in ima_calc_file_hash_atfm(). Suggested-by: Mimi Zohar <[email protected]> Signed-off-by: Patrick Callaghan <[email protected]> Reviewed-by: Sascha Hauer <[email protected]> Signed-off-by: Mimi Zohar <[email protected]>
1 parent e42617b commit 96c9e1d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

security/integrity/ima/ima_crypto.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,10 @@ static int ima_calc_file_hash_tfm(struct file *file,
362362
rc = rbuf_len;
363363
break;
364364
}
365-
if (rbuf_len == 0)
365+
if (rbuf_len == 0) { /* unexpected EOF */
366+
rc = -EINVAL;
366367
break;
368+
}
367369
offset += rbuf_len;
368370

369371
rc = crypto_shash_update(shash, rbuf, rbuf_len);

0 commit comments

Comments
 (0)