Skip to content

Commit b1e4603

Browse files
jankarapcmoore
authored andcommitted
audit: Fix possible tagging failures
Audit tree code is replacing marks attached to inodes in non-atomic way. Thus fsnotify_find_mark() in tag_chunk() may find a mark that belongs to a chunk that is no longer valid one and will soon be destroyed. Tags added to such chunk will be simply lost. Fix the problem by making sure old mark is marked as going away (through fsnotify_detach_mark()) before dropping mark_mutex and thus in an atomic way wrt tag_chunk(). Note that this does not fix the problem completely as if tag_chunk() finds a mark that is going away, it fails with -ENOENT. But at least the failure is not silent and currently there's no way to search for another fsnotify mark attached to the inode. We'll fix this problem in later patch. Reviewed-by: Richard Guy Briggs <rgb@redhat.com> Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent a5789b0 commit b1e4603

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

‎kernel/audit_tree.c‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,9 @@ static void untag_chunk(struct node *p)
278278
list_del_init(&p->list);
279279
list_del_rcu(&chunk->hash);
280280
spin_unlock(&hash_lock);
281+
fsnotify_detach_mark(entry);
281282
mutex_unlock(&entry->group->mark_mutex);
282-
fsnotify_destroy_mark(entry, audit_tree_group);
283+
fsnotify_free_mark(entry);
283284
goto out;
284285
}
285286

@@ -320,8 +321,9 @@ static void untag_chunk(struct node *p)
320321
list_for_each_entry(owner, &new->trees, same_root)
321322
owner->root = new;
322323
spin_unlock(&hash_lock);
324+
fsnotify_detach_mark(entry);
323325
mutex_unlock(&entry->group->mark_mutex);
324-
fsnotify_destroy_mark(entry, audit_tree_group);
326+
fsnotify_free_mark(entry);
325327
fsnotify_put_mark(&new->mark); /* drop initial reference */
326328
goto out;
327329

@@ -364,8 +366,9 @@ static int create_chunk(struct inode *inode, struct audit_tree *tree)
364366
if (tree->goner) {
365367
spin_unlock(&hash_lock);
366368
chunk->dead = 1;
369+
fsnotify_detach_mark(entry);
367370
mutex_unlock(&audit_tree_group->mark_mutex);
368-
fsnotify_destroy_mark(entry, audit_tree_group);
371+
fsnotify_free_mark(entry);
369372
fsnotify_put_mark(entry);
370373
return 0;
371374
}
@@ -446,10 +449,9 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
446449
if (tree->goner) {
447450
spin_unlock(&hash_lock);
448451
chunk->dead = 1;
452+
fsnotify_detach_mark(chunk_entry);
449453
mutex_unlock(&audit_tree_group->mark_mutex);
450-
451-
fsnotify_destroy_mark(chunk_entry, audit_tree_group);
452-
454+
fsnotify_free_mark(chunk_entry);
453455
fsnotify_put_mark(chunk_entry);
454456
fsnotify_put_mark(old_entry);
455457
return 0;
@@ -477,8 +479,9 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
477479
list_add(&tree->same_root, &chunk->trees);
478480
}
479481
spin_unlock(&hash_lock);
482+
fsnotify_detach_mark(old_entry);
480483
mutex_unlock(&audit_tree_group->mark_mutex);
481-
fsnotify_destroy_mark(old_entry, audit_tree_group);
484+
fsnotify_free_mark(old_entry);
482485
fsnotify_put_mark(chunk_entry); /* drop initial reference */
483486
fsnotify_put_mark(old_entry); /* pair to fsnotify_find mark_entry */
484487
return 0;

0 commit comments

Comments
 (0)