File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change 2424
2525static struct crypto_shash * ima_shash_tfm ;
2626
27+ /**
28+ * ima_kernel_read - read file content
29+ *
30+ * This is a function for reading file content instead of kernel_read().
31+ * It does not perform locking checks to ensure it cannot be blocked.
32+ * It does not perform security checks because it is irrelevant for IMA.
33+ *
34+ */
35+ static int ima_kernel_read (struct file * file , loff_t offset ,
36+ char * addr , unsigned long count )
37+ {
38+ mm_segment_t old_fs ;
39+ char __user * buf = addr ;
40+ ssize_t ret ;
41+
42+ if (!(file -> f_mode & FMODE_READ ))
43+ return - EBADF ;
44+ if (!file -> f_op -> read && !file -> f_op -> aio_read )
45+ return - EINVAL ;
46+
47+ old_fs = get_fs ();
48+ set_fs (get_ds ());
49+ if (file -> f_op -> read )
50+ ret = file -> f_op -> read (file , buf , count , & offset );
51+ else
52+ ret = do_sync_read (file , buf , count , & offset );
53+ set_fs (old_fs );
54+ return ret ;
55+ }
56+
2757int ima_init_crypto (void )
2858{
2959 long rc ;
@@ -70,7 +100,7 @@ int ima_calc_file_hash(struct file *file, char *digest)
70100 while (offset < i_size ) {
71101 int rbuf_len ;
72102
73- rbuf_len = kernel_read (file , offset , rbuf , PAGE_SIZE );
103+ rbuf_len = ima_kernel_read (file , offset , rbuf , PAGE_SIZE );
74104 if (rbuf_len < 0 ) {
75105 rc = rbuf_len ;
76106 break ;
You can’t perform that action at this time.
0 commit comments