lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 03 Mar 2014 21:03:15 -0500
From:	Mimi Zohar <zohar@...ux.vnet.ibm.com>
To:	Dmitry Kasatkin <d.kasatkin@...sung.com>
Cc:	linux-security-module@...r.kernel.org, jmorris@...ei.org,
	linux-kernel@...r.kernel.org, casey.schaufler@...el.com,
	dmitry.kasatkin@...il.com
Subject: Re: [PATCH 5/8] ima: skip memory allocation for empty files

On Fri, 2014-02-28 at 16:59 +0200, Dmitry Kasatkin wrote: 
> Memory allocation is unnecessary for empty files.
> This patch finalize the hash without memory allocation.
> 
> Signed-off-by: Dmitry Kasatkin <d.kasatkin@...sung.com>

Thanks.

Mimi 
> ---
>  security/integrity/ima/ima_crypto.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c
> index d257e36..1bde8e6 100644
> --- a/security/integrity/ima/ima_crypto.c
> +++ b/security/integrity/ima/ima_crypto.c
> @@ -87,16 +87,20 @@ static int ima_calc_file_hash_tfm(struct file *file,
>  	if (rc != 0)
>  		return rc;
> 
> -	rbuf = kzalloc(PAGE_SIZE, GFP_KERNEL);
> -	if (!rbuf) {
> -		rc = -ENOMEM;
> +	i_size = i_size_read(file_inode(file));
> +
> +	if (i_size == 0)
>  		goto out;
> -	}
> +
> +	rbuf = kzalloc(PAGE_SIZE, GFP_KERNEL);
> +	if (!rbuf)
> +		return -ENOMEM;
> +
>  	if (!(file->f_mode & FMODE_READ)) {
>  		file->f_mode |= FMODE_READ;
>  		read = 1;
>  	}
> -	i_size = i_size_read(file_inode(file));
> +
>  	while (offset < i_size) {
>  		int rbuf_len;
> 
> @@ -113,12 +117,12 @@ static int ima_calc_file_hash_tfm(struct file *file,
>  		if (rc)
>  			break;
>  	}
> -	kfree(rbuf);
> -	if (!rc)
> -		rc = crypto_shash_final(&desc.shash, hash->digest);
>  	if (read)
>  		file->f_mode &= ~FMODE_READ;
> +	kfree(rbuf);
>  out:
> +	if (!rc)
> +		rc = crypto_shash_final(&desc.shash, hash->digest);
>  	return rc;
>  }
> 


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ