audit: use fsnotify group lock helpers

audit inode marks pin the inode so there is no need to set the
FSNOTIFY_GROUP_NOFS flag.

Link: https://lore.kernel.org/r/20220422120327.3459282-9-amir73il@gmail.com
Suggested-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20220321112310.vpr7oxro2xkz5llh@quack3.lan/
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
This commit is contained in:
Amir Goldstein 2022-04-22 15:03:19 +03:00 committed by Jan Kara
parent 642054b870
commit 960bdff24c

View File

@ -351,7 +351,7 @@ static void untag_chunk(struct audit_chunk *chunk, struct fsnotify_mark *mark)
struct audit_chunk *new; struct audit_chunk *new;
int size; int size;
mutex_lock(&audit_tree_group->mark_mutex); fsnotify_group_lock(audit_tree_group);
/* /*
* mark_mutex stabilizes chunk attached to the mark so we can check * mark_mutex stabilizes chunk attached to the mark so we can check
* whether it didn't change while we've dropped hash_lock. * whether it didn't change while we've dropped hash_lock.
@ -368,7 +368,7 @@ static void untag_chunk(struct audit_chunk *chunk, struct fsnotify_mark *mark)
replace_mark_chunk(mark, NULL); replace_mark_chunk(mark, NULL);
spin_unlock(&hash_lock); spin_unlock(&hash_lock);
fsnotify_detach_mark(mark); fsnotify_detach_mark(mark);
mutex_unlock(&audit_tree_group->mark_mutex); fsnotify_group_unlock(audit_tree_group);
audit_mark_put_chunk(chunk); audit_mark_put_chunk(chunk);
fsnotify_free_mark(mark); fsnotify_free_mark(mark);
return; return;
@ -385,12 +385,12 @@ static void untag_chunk(struct audit_chunk *chunk, struct fsnotify_mark *mark)
*/ */
replace_chunk(new, chunk); replace_chunk(new, chunk);
spin_unlock(&hash_lock); spin_unlock(&hash_lock);
mutex_unlock(&audit_tree_group->mark_mutex); fsnotify_group_unlock(audit_tree_group);
audit_mark_put_chunk(chunk); audit_mark_put_chunk(chunk);
return; return;
out_mutex: out_mutex:
mutex_unlock(&audit_tree_group->mark_mutex); fsnotify_group_unlock(audit_tree_group);
} }
/* Call with group->mark_mutex held, releases it */ /* Call with group->mark_mutex held, releases it */
@ -400,19 +400,19 @@ static int create_chunk(struct inode *inode, struct audit_tree *tree)
struct audit_chunk *chunk = alloc_chunk(1); struct audit_chunk *chunk = alloc_chunk(1);
if (!chunk) { if (!chunk) {
mutex_unlock(&audit_tree_group->mark_mutex); fsnotify_group_unlock(audit_tree_group);
return -ENOMEM; return -ENOMEM;
} }
mark = alloc_mark(); mark = alloc_mark();
if (!mark) { if (!mark) {
mutex_unlock(&audit_tree_group->mark_mutex); fsnotify_group_unlock(audit_tree_group);
kfree(chunk); kfree(chunk);
return -ENOMEM; return -ENOMEM;
} }
if (fsnotify_add_inode_mark_locked(mark, inode, 0)) { if (fsnotify_add_inode_mark_locked(mark, inode, 0)) {
mutex_unlock(&audit_tree_group->mark_mutex); fsnotify_group_unlock(audit_tree_group);
fsnotify_put_mark(mark); fsnotify_put_mark(mark);
kfree(chunk); kfree(chunk);
return -ENOSPC; return -ENOSPC;
@ -422,7 +422,7 @@ static int create_chunk(struct inode *inode, struct audit_tree *tree)
if (tree->goner) { if (tree->goner) {
spin_unlock(&hash_lock); spin_unlock(&hash_lock);
fsnotify_detach_mark(mark); fsnotify_detach_mark(mark);
mutex_unlock(&audit_tree_group->mark_mutex); fsnotify_group_unlock(audit_tree_group);
fsnotify_free_mark(mark); fsnotify_free_mark(mark);
fsnotify_put_mark(mark); fsnotify_put_mark(mark);
kfree(chunk); kfree(chunk);
@ -444,7 +444,7 @@ static int create_chunk(struct inode *inode, struct audit_tree *tree)
*/ */
insert_hash(chunk); insert_hash(chunk);
spin_unlock(&hash_lock); spin_unlock(&hash_lock);
mutex_unlock(&audit_tree_group->mark_mutex); fsnotify_group_unlock(audit_tree_group);
/* /*
* Drop our initial reference. When mark we point to is getting freed, * Drop our initial reference. When mark we point to is getting freed,
* we get notification through ->freeing_mark callback and cleanup * we get notification through ->freeing_mark callback and cleanup
@ -462,7 +462,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
struct audit_node *p; struct audit_node *p;
int n; int n;
mutex_lock(&audit_tree_group->mark_mutex); fsnotify_group_lock(audit_tree_group);
mark = fsnotify_find_mark(&inode->i_fsnotify_marks, audit_tree_group); mark = fsnotify_find_mark(&inode->i_fsnotify_marks, audit_tree_group);
if (!mark) if (!mark)
return create_chunk(inode, tree); return create_chunk(inode, tree);
@ -478,7 +478,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
for (n = 0; n < old->count; n++) { for (n = 0; n < old->count; n++) {
if (old->owners[n].owner == tree) { if (old->owners[n].owner == tree) {
spin_unlock(&hash_lock); spin_unlock(&hash_lock);
mutex_unlock(&audit_tree_group->mark_mutex); fsnotify_group_unlock(audit_tree_group);
fsnotify_put_mark(mark); fsnotify_put_mark(mark);
return 0; return 0;
} }
@ -487,7 +487,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
chunk = alloc_chunk(old->count + 1); chunk = alloc_chunk(old->count + 1);
if (!chunk) { if (!chunk) {
mutex_unlock(&audit_tree_group->mark_mutex); fsnotify_group_unlock(audit_tree_group);
fsnotify_put_mark(mark); fsnotify_put_mark(mark);
return -ENOMEM; return -ENOMEM;
} }
@ -495,7 +495,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
spin_lock(&hash_lock); spin_lock(&hash_lock);
if (tree->goner) { if (tree->goner) {
spin_unlock(&hash_lock); spin_unlock(&hash_lock);
mutex_unlock(&audit_tree_group->mark_mutex); fsnotify_group_unlock(audit_tree_group);
fsnotify_put_mark(mark); fsnotify_put_mark(mark);
kfree(chunk); kfree(chunk);
return 0; return 0;
@ -515,7 +515,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
*/ */
replace_chunk(chunk, old); replace_chunk(chunk, old);
spin_unlock(&hash_lock); spin_unlock(&hash_lock);
mutex_unlock(&audit_tree_group->mark_mutex); fsnotify_group_unlock(audit_tree_group);
fsnotify_put_mark(mark); /* pair to fsnotify_find_mark */ fsnotify_put_mark(mark); /* pair to fsnotify_find_mark */
audit_mark_put_chunk(old); audit_mark_put_chunk(old);
@ -1044,12 +1044,12 @@ static void audit_tree_freeing_mark(struct fsnotify_mark *mark,
{ {
struct audit_chunk *chunk; struct audit_chunk *chunk;
mutex_lock(&mark->group->mark_mutex); fsnotify_group_lock(mark->group);
spin_lock(&hash_lock); spin_lock(&hash_lock);
chunk = mark_chunk(mark); chunk = mark_chunk(mark);
replace_mark_chunk(mark, NULL); replace_mark_chunk(mark, NULL);
spin_unlock(&hash_lock); spin_unlock(&hash_lock);
mutex_unlock(&mark->group->mark_mutex); fsnotify_group_unlock(mark->group);
if (chunk) { if (chunk) {
evict_chunk(chunk); evict_chunk(chunk);
audit_mark_put_chunk(chunk); audit_mark_put_chunk(chunk);