linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ima: avoid appraise error for hash calc interrupt
@ 2019-11-11 19:23 Patrick Callaghan
  2019-11-11 22:29 ` Lakshmi Ramasubramanian
  2019-11-13  7:52 ` Sascha Hauer
  0 siblings, 2 replies; 10+ messages in thread
From: Patrick Callaghan @ 2019-11-11 19:23 UTC (permalink / raw)
  To: linux-integrity; +Cc: linux-kernel, Sascha Hauer, Patrick Callaghan, Mimi Zohar

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 <zohar@linux.ibm.com>
Signed-off-by: Patrick Callaghan <patrickc@linux.ibm.com>
---
 security/integrity/ima/ima_crypto.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c
index 73044fc..7967a69 100644
--- a/security/integrity/ima/ima_crypto.c
+++ b/security/integrity/ima/ima_crypto.c
@@ -362,8 +362,10 @@ static int ima_calc_file_hash_tfm(struct file *file,
 			rc = rbuf_len;
 			break;
 		}
-		if (rbuf_len == 0)
+		if (rbuf_len == 0) {	/* unexpected EOF */
+			rc = -EINVAL;
 			break;
+		}
 		offset += rbuf_len;
 
 		rc = crypto_shash_update(shash, rbuf, rbuf_len);
-- 
2.8.3


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-11-15 20:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-11 19:23 [PATCH] ima: avoid appraise error for hash calc interrupt Patrick Callaghan
2019-11-11 22:29 ` Lakshmi Ramasubramanian
2019-11-12 17:14   ` Mimi Zohar
2019-11-12 17:33     ` Lakshmi Ramasubramanian
2019-11-12 18:12       ` Mimi Zohar
2019-11-14 13:55         ` Patrick Callaghan
2019-11-14 18:45           ` Lakshmi Ramasubramanian
2019-11-15 15:25             ` Patrick Callaghan
2019-11-15 20:34               ` Lakshmi Ramasubramanian
2019-11-13  7:52 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).