Skip to content

Commit 854fdd5

Browse files
author
Mimi Zohar
committed
IMA: remove IMA imbalance checking
Now that i_readcount is maintained by the VFS layer, remove the imbalance checking in IMA. Cleans up the IMA code nicely. Signed-off-by: Mimi Zohar <zohar@us.ibm.com> Acked-by: Eric Paris <eparis@redhat.com>
1 parent 890275b commit 854fdd5

2 files changed

Lines changed: 4 additions & 104 deletions

File tree

‎security/integrity/ima/ima_iint.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,6 @@ void ima_inode_free(struct inode *inode)
137137
{
138138
struct ima_iint_cache *iint;
139139

140-
if (atomic_read(&inode->i_readcount))
141-
printk(KERN_INFO "%s: readcount: %u\n", __func__,
142-
atomic_read(&inode->i_readcount));
143-
144140
if (!IS_IMA(inode))
145141
return;
146142

‎security/integrity/ima/ima_main.c‎

Lines changed: 4 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
15685
static 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

216120
static int process_measurement(struct file *file, const unsigned char *filename,

0 commit comments

Comments
 (0)