Skip to content

Commit 1e42dec

Browse files
saschahauergregkh
authored andcommitted
ima: always return negative code for error
[ Upstream commit f5e1040 ] integrity_kernel_read() returns the number of bytes read. If this is a short read then this positive value is returned from ima_calc_file_hash_atfm(). Currently this is only indirectly called from ima_calc_file_hash() and this function only tests for the return value being zero or nonzero and also doesn't forward the return value. Nevertheless there's no point in returning a positive value as an error, so translate a short read into -EINVAL. Signed-off-by: Sascha Hauer <[email protected]> Signed-off-by: Mimi Zohar <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent eec7ef3 commit 1e42dec

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

security/integrity/ima/ima_crypto.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,11 @@ static int ima_calc_file_hash_atfm(struct file *file,
298298
rbuf_len = min_t(loff_t, i_size - offset, rbuf_size[active]);
299299
rc = integrity_kernel_read(file, offset, rbuf[active],
300300
rbuf_len);
301-
if (rc != rbuf_len)
301+
if (rc != rbuf_len) {
302+
if (rc >= 0)
303+
rc = -EINVAL;
302304
goto out3;
305+
}
303306

304307
if (rbuf[1] && offset) {
305308
/* Using two buffers, and it is not the first

0 commit comments

Comments
 (0)