Skip to content

Commit

Permalink
ima: always return negative code for error
Browse files Browse the repository at this point in the history
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 <s.hauer@pengutronix.de>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
  • Loading branch information
saschahauer authored and mimizohar committed Aug 5, 2019
1 parent e509225 commit f5e1040
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion security/integrity/ima/ima_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,11 @@ static int ima_calc_file_hash_atfm(struct file *file,
rbuf_len = min_t(loff_t, i_size - offset, rbuf_size[active]);
rc = integrity_kernel_read(file, offset, rbuf[active],
rbuf_len);
if (rc != rbuf_len)
if (rc != rbuf_len) {
if (rc >= 0)
rc = -EINVAL;
goto out3;
}

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

0 comments on commit f5e1040

Please sign in to comment.