]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
ima: always return negative code for error
authorSascha Hauer <s.hauer@pengutronix.de>
Tue, 2 Jul 2019 08:00:40 +0000 (10:00 +0200)
committerMimi Zohar <zohar@linux.ibm.com>
Mon, 5 Aug 2019 22:40:27 +0000 (18:40 -0400)
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>
security/integrity/ima/ima_crypto.c

index d4c7b8e1b083db14b9ca6380e7dd2878621f58e2..7532b062be5946e49d14a847f7f60366066176d1 100644 (file)
@@ -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