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 2121#include <linux/slab.h>
2222#include "ima.h"
2323
24+ /**
25+ * ima_kernel_read - read file content
26+ *
27+ * This is a function for reading file content instead of kernel_read().
28+ * It does not perform locking checks to ensure it cannot be blocked.
29+ * It does not perform security checks because it is irrelevant for IMA.
30+ *
31+ */
32+ static int ima_kernel_read (struct file * file , loff_t offset ,
33+ char * addr , unsigned long count )
34+ {
35+ mm_segment_t old_fs ;
36+ char __user * buf = addr ;
37+ ssize_t ret ;
38+
39+ if (!(file -> f_mode & FMODE_READ ))
40+ return - EBADF ;
41+ if (!file -> f_op -> read && !file -> f_op -> aio_read )
42+ return - EINVAL ;
43+
44+ old_fs = get_fs ();
45+ set_fs (get_ds ());
46+ if (file -> f_op -> read )
47+ ret = file -> f_op -> read (file , buf , count , & offset );
48+ else
49+ ret = do_sync_read (file , buf , count , & offset );
50+ set_fs (old_fs );
51+ return ret ;
52+ }
53+
2454static int init_desc (struct hash_desc * desc )
2555{
2656 int rc ;
@@ -67,7 +97,7 @@ int ima_calc_hash(struct file *file, char *digest)
6797 while (offset < i_size ) {
6898 int rbuf_len ;
6999
70- rbuf_len = kernel_read (file , offset , rbuf , PAGE_SIZE );
100+ rbuf_len = ima_kernel_read (file , offset , rbuf , PAGE_SIZE );
71101 if (rbuf_len < 0 ) {
72102 rc = rbuf_len ;
73103 break ;
You can’t perform that action at this time.
0 commit comments