@@ -36,55 +36,6 @@ static int __init hash_setup(char *str)
3636}
3737__setup ("ima_hash=" , hash_setup );
3838
39- struct ima_imbalance {
40- struct hlist_node node ;
41- unsigned long fsmagic ;
42- };
43-
44- /*
45- * ima_limit_imbalance - emit one imbalance message per filesystem type
46- *
47- * Maintain list of filesystem types that do not measure files properly.
48- * Return false if unknown, true if known.
49- */
50- static bool ima_limit_imbalance (struct file * file )
51- {
52- static DEFINE_SPINLOCK (ima_imbalance_lock );
53- static HLIST_HEAD (ima_imbalance_list );
54-
55- struct super_block * sb = file -> f_dentry -> d_sb ;
56- struct ima_imbalance * entry ;
57- struct hlist_node * node ;
58- bool found = false;
59-
60- rcu_read_lock ();
61- hlist_for_each_entry_rcu (entry , node , & ima_imbalance_list , node ) {
62- if (entry -> fsmagic == sb -> s_magic ) {
63- found = true;
64- break ;
65- }
66- }
67- rcu_read_unlock ();
68- if (found )
69- goto out ;
70-
71- entry = kmalloc (sizeof (* entry ), GFP_NOFS );
72- if (!entry )
73- goto out ;
74- entry -> fsmagic = sb -> s_magic ;
75- spin_lock (& ima_imbalance_lock );
76- /*
77- * we could have raced and something else might have added this fs
78- * to the list, but we don't really care
79- */
80- hlist_add_head_rcu (& entry -> node , & ima_imbalance_list );
81- spin_unlock (& ima_imbalance_lock );
82- printk (KERN_INFO "IMA: unmeasured files on fsmagic: %lX\n" ,
83- entry -> fsmagic );
84- out :
85- return found ;
86- }
87-
8839/*
8940 * ima_rdwr_violation_check
9041 *
@@ -131,65 +82,20 @@ static void ima_rdwr_violation_check(struct file *file)
13182 "open_writers" );
13283}
13384
134- /*
135- * Decrement ima counts
136- */
137- static void ima_dec_counts (struct inode * inode , struct file * file )
138- {
139- mode_t mode = file -> f_mode ;
140-
141- assert_spin_locked (& inode -> i_lock );
142-
143- if ((mode & (FMODE_READ | FMODE_WRITE )) == FMODE_READ ) {
144- if (unlikely (atomic_read (& inode -> i_readcount ) == 0 )) {
145- if (!ima_limit_imbalance (file )) {
146- printk (KERN_INFO "%s: open/free imbalance (r:%u)\n" ,
147- __func__ ,
148- atomic_read (& inode -> i_readcount ));
149- dump_stack ();
150- }
151- return ;
152- }
153- }
154- }
155-
15685static void ima_check_last_writer (struct ima_iint_cache * iint ,
15786 struct inode * inode ,
15887 struct file * file )
15988{
16089 mode_t mode = file -> f_mode ;
16190
162- BUG_ON (!mutex_is_locked (& iint -> mutex ));
163- assert_spin_locked (& inode -> i_lock );
164-
91+ mutex_lock (& iint -> mutex );
16592 if (mode & FMODE_WRITE &&
16693 atomic_read (& inode -> i_writecount ) == 1 &&
16794 iint -> version != inode -> i_version )
16895 iint -> flags &= ~IMA_MEASURED ;
169- }
170-
171- static void ima_file_free_iint (struct ima_iint_cache * iint , struct inode * inode ,
172- struct file * file )
173- {
174- mutex_lock (& iint -> mutex );
175- spin_lock (& inode -> i_lock );
176-
177- ima_dec_counts (inode , file );
178- ima_check_last_writer (iint , inode , file );
179-
180- spin_unlock (& inode -> i_lock );
18196 mutex_unlock (& iint -> mutex );
18297}
18398
184- static void ima_file_free_noiint (struct inode * inode , struct file * file )
185- {
186- spin_lock (& inode -> i_lock );
187-
188- ima_dec_counts (inode , file );
189-
190- spin_unlock (& inode -> i_lock );
191- }
192-
19399/**
194100 * ima_file_free - called on __fput()
195101 * @file: pointer to file structure being freed
@@ -205,12 +111,10 @@ void ima_file_free(struct file *file)
205111 return ;
206112
207113 iint = ima_iint_find (inode );
114+ if (!iint )
115+ return ;
208116
209- if (iint )
210- ima_file_free_iint (iint , inode , file );
211- else
212- ima_file_free_noiint (inode , file );
213-
117+ ima_check_last_writer (iint , inode , file );
214118}
215119
216120static int process_measurement (struct file * file , const unsigned char * filename ,
0 commit comments