[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5ab256148e8ad5f9882e888dac809bc72cd3fe66.camel@chromium.org>
Date: Wed, 16 Sep 2020 14:41:33 +0200
From: Florent Revest <revest@...omium.org>
To: KP Singh <kpsingh@...omium.org>, linux-kernel@...r.kernel.org,
linux-security-module@...r.kernel.org
Cc: Mimi Zohar <zohar@...ux.ibm.com>, James Morris <jmorris@...ei.org>,
Kees Cook <keescook@...omium.org>,
Lakshmi Ramasubramanian <nramas@...ux.microsoft.com>,
Jann Horn <jannh@...gle.com>
Subject: Re: [PATCH] ima: Fix NULL pointer dereference in ima_file_hash
Reviewed-by: Florent Revest <revest@...omium.org>
On Wed, 2020-09-16 at 12:05 +0000, KP Singh wrote:
> From: KP Singh <kpsingh@...gle.com>
>
> ima_file_hash can be called when there is no iint->ima_hash available
> even though the inode exists in the integrity cache.
>
> An example where this can happen (suggested by Jann Horn):
>
> Process A does:
>
> while(1) {
> unlink("/tmp/imafoo");
> fd = open("/tmp/imafoo", O_RDWR|O_CREAT|O_TRUNC, 0700);
> if (fd == -1) {
> perror("open");
> continue;
> }
> write(fd, "A", 1);
> close(fd);
> }
>
> and Process B does:
>
> while (1) {
> int fd = open("/tmp/imafoo", O_RDONLY);
> if (fd == -1)
> continue;
> char *mapping = mmap(NULL, 0x1000, PROT_READ|PROT_EXEC,
> MAP_PRIVATE, fd, 0);
> if (mapping != MAP_FAILED)
> munmap(mapping, 0x1000);
> close(fd);
> }
>
> Due to the race to get the iint->mutex between ima_file_hash and
> process_measurement iint->ima_hash could still be NULL.
>
> Fixes: 6beea7afcc72 ("ima: add the ability to query the cached hash
> of a given file")
> Signed-off-by: KP Singh <kpsingh@...gle.com>
> ---
> security/integrity/ima/ima_main.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/security/integrity/ima/ima_main.c
> b/security/integrity/ima/ima_main.c
> index 8a91711ca79b..4c86cd4eece0 100644
> --- a/security/integrity/ima/ima_main.c
> +++ b/security/integrity/ima/ima_main.c
> @@ -531,6 +531,16 @@ int ima_file_hash(struct file *file, char *buf,
> size_t buf_size)
> return -EOPNOTSUPP;
>
> mutex_lock(&iint->mutex);
> +
> + /*
> + * ima_file_hash can be called when ima_collect_measurement has
> still
> + * not been called, we might not always have a hash.
> + */
> + if (!iint->ima_hash) {
> + mutex_unlock(&iint->mutex);
> + return -EOPNOTSUPP;
> + }
> +
> if (buf) {
> size_t copied_size;
>
Powered by blists - more mailing lists