aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Kasatkin2014-02-27 12:16:47 -0600
committerMimi Zohar2014-03-07 11:15:48 -0600
commit1d91ac6213003f525ac34da5e39cbb6612d19deb (patch)
tree8182a8b6df13e506b1888fce3395b75a9aa1f23b /security
parente0420039b643a832231028000a5c0d7358b14f3b (diff)
downloadlinux-phy-1d91ac6213003f525ac34da5e39cbb6612d19deb.tar.gz
linux-phy-1d91ac6213003f525ac34da5e39cbb6612d19deb.tar.xz
linux-phy-1d91ac6213003f525ac34da5e39cbb6612d19deb.zip
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: Dmitry Kasatkin <d.kasatkin@samsung.com> Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
Diffstat (limited to 'security')
-rw-r--r--security/integrity/ima/ima_crypto.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c
index d257e3631152..1bde8e627766 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,
87 if (rc != 0) 87 if (rc != 0)
88 return rc; 88 return rc;
89 89
90 rbuf = kzalloc(PAGE_SIZE, GFP_KERNEL); 90 i_size = i_size_read(file_inode(file));
91 if (!rbuf) { 91
92 rc = -ENOMEM; 92 if (i_size == 0)
93 goto out; 93 goto out;
94 } 94
95 rbuf = kzalloc(PAGE_SIZE, GFP_KERNEL);
96 if (!rbuf)
97 return -ENOMEM;
98
95 if (!(file->f_mode & FMODE_READ)) { 99 if (!(file->f_mode & FMODE_READ)) {
96 file->f_mode |= FMODE_READ; 100 file->f_mode |= FMODE_READ;
97 read = 1; 101 read = 1;
98 } 102 }
99 i_size = i_size_read(file_inode(file)); 103
100 while (offset < i_size) { 104 while (offset < i_size) {
101 int rbuf_len; 105 int rbuf_len;
102 106
@@ -113,12 +117,12 @@ static int ima_calc_file_hash_tfm(struct file *file,
113 if (rc) 117 if (rc)
114 break; 118 break;
115 } 119 }
116 kfree(rbuf);
117 if (!rc)
118 rc = crypto_shash_final(&desc.shash, hash->digest);
119 if (read) 120 if (read)
120 file->f_mode &= ~FMODE_READ; 121 file->f_mode &= ~FMODE_READ;
122 kfree(rbuf);
121out: 123out:
124 if (!rc)
125 rc = crypto_shash_final(&desc.shash, hash->digest);
122 return rc; 126 return rc;
123} 127}
124 128