All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Patrick Callaghan <patrickc@linux.ibm.com>
Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org,
	Mimi Zohar <zohar@linux.ibm.com>
Subject: Re: [PATCH] ima: avoid appraise error for hash calc interrupt
Date: Wed, 13 Nov 2019 08:52:37 +0100	[thread overview]
Message-ID: <20191113075237.falq46vnmbtd5pa7@pengutronix.de> (raw)
In-Reply-To: <20191111192348.30535-1-patrickc@linux.ibm.com>

On Mon, Nov 11, 2019 at 02:23:48PM -0500, Patrick Callaghan wrote:
> 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;
> +		}

There's no point in calling crypto_shash_final() on incomplete data, so
setting rc to an error to avoid that seems the right thing to do to me,
so:

Reviewed-by: Sascha Hauer <s.hauer@pengutronix.de>

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

      parent reply	other threads:[~2019-11-13  7:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191113075237.falq46vnmbtd5pa7@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patrickc@linux.ibm.com \
    --cc=zohar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.