Skip to content

Commit d76036a

Browse files
jankarapcmoore
authored andcommitted
audit: Fix use after free in audit_remove_watch_rule()
audit_remove_watch_rule() drops watch's reference to parent but then continues to work with it. That is not safe as parent can get freed once we drop our reference. The following is a trivial reproducer: mount -o loop image /mnt touch /mnt/file auditctl -w /mnt/file -p wax umount /mnt auditctl -D <crash in fsnotify_destroy_mark()> Grab our own reference in audit_remove_watch_rule() earlier to make sure mark does not get freed under us. CC: stable@vger.kernel.org Reported-by: Tony Jones <tonyj@suse.de> Signed-off-by: Jan Kara <jack@suse.cz> Tested-by: Tony Jones <tonyj@suse.de> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent b0659ae commit d76036a

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎kernel/audit_watch.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -457,13 +457,15 @@ void audit_remove_watch_rule(struct audit_krule *krule)
457457
list_del(&krule->rlist);
458458

459459
if (list_empty(&watch->rules)) {
460+
/*
461+
* audit_remove_watch() drops our reference to 'parent' which
462+
* can get freed. Grab our own reference to be safe.
463+
*/
464+
audit_get_parent(parent);
460465
audit_remove_watch(watch);
461-
462-
if (list_empty(&parent->watches)) {
463-
audit_get_parent(parent);
466+
if (list_empty(&parent->watches))
464467
fsnotify_destroy_mark(&parent->mark, audit_watch_group);
465-
audit_put_parent(parent);
466-
}
468+
audit_put_parent(parent);
467469
}
468470
}
469471

0 commit comments

Comments
 (0)