Commit 1d91ac62 authored by Dmitry Kasatkin's avatar Dmitry Kasatkin Committed by Mimi Zohar

ima: skip memory allocation for empty files

Memory allocation is unnecessary for empty files.
This patch calculates the hash without memory allocation.
Signed-off-by: default avatarDmitry Kasatkin <d.kasatkin@samsung.com>
Signed-off-by: default avatarMimi Zohar <zohar@linux.vnet.ibm.com>
parent e0420039
...@@ -87,16 +87,20 @@ static int ima_calc_file_hash_tfm(struct file *file, ...@@ -87,16 +87,20 @@ static int ima_calc_file_hash_tfm(struct file *file,
if (rc != 0) if (rc != 0)
return rc; return rc;
rbuf = kzalloc(PAGE_SIZE, GFP_KERNEL); i_size = i_size_read(file_inode(file));
if (!rbuf) {
rc = -ENOMEM; if (i_size == 0)
goto out; goto out;
}
rbuf = kzalloc(PAGE_SIZE, GFP_KERNEL);
if (!rbuf)
return -ENOMEM;
if (!(file->f_mode & FMODE_READ)) { if (!(file->f_mode & FMODE_READ)) {
file->f_mode |= FMODE_READ; file->f_mode |= FMODE_READ;
read = 1; read = 1;
} }
i_size = i_size_read(file_inode(file));
while (offset < i_size) { while (offset < i_size) {
int rbuf_len; int rbuf_len;
...@@ -113,12 +117,12 @@ static int ima_calc_file_hash_tfm(struct file *file, ...@@ -113,12 +117,12 @@ static int ima_calc_file_hash_tfm(struct file *file,
if (rc) if (rc)
break; break;
} }
kfree(rbuf);
if (!rc)
rc = crypto_shash_final(&desc.shash, hash->digest);
if (read) if (read)
file->f_mode &= ~FMODE_READ; file->f_mode &= ~FMODE_READ;
kfree(rbuf);
out: out:
if (!rc)
rc = crypto_shash_final(&desc.shash, hash->digest);
return rc; return rc;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment