aboutsummaryrefslogtreecommitdiffstats
path: root/security/integrity/ima/ima_crypto.c
diff options
context:
space:
mode:
Diffstat (limited to 'security/integrity/ima/ima_crypto.c')
-rw-r--r--security/integrity/ima/ima_crypto.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c
index 1bde8e627766..ccd0ac8fa9a0 100644
--- a/security/integrity/ima/ima_crypto.c
+++ b/security/integrity/ima/ima_crypto.c
@@ -27,6 +27,36 @@
27 27
28static struct crypto_shash *ima_shash_tfm; 28static struct crypto_shash *ima_shash_tfm;
29 29
30/**
31 * ima_kernel_read - read file content
32 *
33 * This is a function for reading file content instead of kernel_read().
34 * It does not perform locking checks to ensure it cannot be blocked.
35 * It does not perform security checks because it is irrelevant for IMA.
36 *
37 */
38static int ima_kernel_read(struct file *file, loff_t offset,
39 char *addr, unsigned long count)
40{
41 mm_segment_t old_fs;
42 char __user *buf = addr;
43 ssize_t ret;
44
45 if (!(file->f_mode & FMODE_READ))
46 return -EBADF;
47 if (!file->f_op->read && !file->f_op->aio_read)
48 return -EINVAL;
49
50 old_fs = get_fs();
51 set_fs(get_ds());
52 if (file->f_op->read)
53 ret = file->f_op->read(file, buf, count, &offset);
54 else
55 ret = do_sync_read(file, buf, count, &offset);
56 set_fs(old_fs);
57 return ret;
58}
59
30int ima_init_crypto(void) 60int ima_init_crypto(void)
31{ 61{
32 long rc; 62 long rc;
@@ -104,7 +134,7 @@ static int ima_calc_file_hash_tfm(struct file *file,
104 while (offset < i_size) { 134 while (offset < i_size) {
105 int rbuf_len; 135 int rbuf_len;
106 136
107 rbuf_len = kernel_read(file, offset, rbuf, PAGE_SIZE); 137 rbuf_len = ima_kernel_read(file, offset, rbuf, PAGE_SIZE);
108 if (rbuf_len < 0) { 138 if (rbuf_len < 0) {
109 rc = rbuf_len; 139 rc = rbuf_len;
110 break; 140 break;