Skip to content

Commit f410ff6

Browse files
committed
audit: Abstract hash key handling
Audit tree currently uses inode pointer as a key into the hash table. Getting that from notification mark will be somewhat more difficult with coming fsnotify changes. So abstract getting of hash key from the audit chunk and inode so that we can change the method to obtain a key easily. Reviewed-by: Miklos Szeredi <mszeredi@redhat.com> CC: Paul Moore <paul@paul-moore.com> Acked-by: Paul Moore <paul@paul-moore.com> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent c974764 commit f410ff6

1 file changed

Lines changed: 28 additions & 11 deletions

File tree

‎kernel/audit_tree.c‎

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,33 +163,48 @@ enum {HASH_SIZE = 128};
163163
static struct list_head chunk_hash_heads[HASH_SIZE];
164164
static __cacheline_aligned_in_smp DEFINE_SPINLOCK(hash_lock);
165165

166-
static inline struct list_head *chunk_hash(const struct inode *inode)
166+
/* Function to return search key in our hash from inode. */
167+
static unsigned long inode_to_key(const struct inode *inode)
167168
{
168-
unsigned long n = (unsigned long)inode / L1_CACHE_BYTES;
169+
return (unsigned long)inode;
170+
}
171+
172+
/*
173+
* Function to return search key in our hash from chunk. Key 0 is special and
174+
* should never be present in the hash.
175+
*/
176+
static unsigned long chunk_to_key(struct audit_chunk *chunk)
177+
{
178+
return (unsigned long)chunk->mark.inode;
179+
}
180+
181+
static inline struct list_head *chunk_hash(unsigned long key)
182+
{
183+
unsigned long n = key / L1_CACHE_BYTES;
169184
return chunk_hash_heads + n % HASH_SIZE;
170185
}
171186

172187
/* hash_lock & entry->lock is held by caller */
173188
static void insert_hash(struct audit_chunk *chunk)
174189
{
175-
struct fsnotify_mark *entry = &chunk->mark;
190+
unsigned long key = chunk_to_key(chunk);
176191
struct list_head *list;
177192

178-
if (!entry->inode)
193+
if (!key)
179194
return;
180-
list = chunk_hash(entry->inode);
195+
list = chunk_hash(key);
181196
list_add_rcu(&chunk->hash, list);
182197
}
183198

184199
/* called under rcu_read_lock */
185200
struct audit_chunk *audit_tree_lookup(const struct inode *inode)
186201
{
187-
struct list_head *list = chunk_hash(inode);
202+
unsigned long key = inode_to_key(inode);
203+
struct list_head *list = chunk_hash(key);
188204
struct audit_chunk *p;
189205

190206
list_for_each_entry_rcu(p, list, hash) {
191-
/* mark.inode may have gone NULL, but who cares? */
192-
if (p->mark.inode == inode) {
207+
if (chunk_to_key(p) == key) {
193208
atomic_long_inc(&p->refs);
194209
return p;
195210
}
@@ -588,7 +603,8 @@ int audit_remove_tree_rule(struct audit_krule *rule)
588603

589604
static int compare_root(struct vfsmount *mnt, void *arg)
590605
{
591-
return d_backing_inode(mnt->mnt_root) == arg;
606+
return inode_to_key(d_backing_inode(mnt->mnt_root)) ==
607+
(unsigned long)arg;
592608
}
593609

594610
void audit_trim_trees(void)
@@ -623,9 +639,10 @@ void audit_trim_trees(void)
623639
list_for_each_entry(node, &tree->chunks, list) {
624640
struct audit_chunk *chunk = find_chunk(node);
625641
/* this could be NULL if the watch is dying else where... */
626-
struct inode *inode = chunk->mark.inode;
627642
node->index |= 1U<<31;
628-
if (iterate_mounts(compare_root, inode, root_mnt))
643+
if (iterate_mounts(compare_root,
644+
(void *)chunk_to_key(chunk),
645+
root_mnt))
629646
node->index &= ~(1U<<31);
630647
}
631648
spin_unlock(&hash_lock);

0 commit comments

Comments
 (0)