Skip to content

Commit 8c2f870

Browse files
committed
ALSA: info: Fix racy addition/deletion of nodes
The ALSA proc helper manages the child nodes in a linked list, but its addition and deletion is done without any lock. This leads to a corruption if they are operated concurrently. Usually this isn't a problem because the proc entries are added sequentially in the driver probe procedure itself. But the card registrations are done often asynchronously, and the crash could be actually reproduced with syzkaller. This patch papers over it by protecting the link addition and deletion with the parent's mutex. There is "access" mutex that is used for the file access, and this can be reused for this purpose as well. Reported-by: syzbot+48df349490c36f9f54ab@syzkaller.appspotmail.com Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 183ab39 commit 8c2f870

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎sound/core/info.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,11 @@ snd_info_create_entry(const char *name, struct snd_info_entry *parent,
713713
INIT_LIST_HEAD(&entry->list);
714714
entry->parent = parent;
715715
entry->module = module;
716-
if (parent)
716+
if (parent) {
717+
mutex_lock(&parent->access);
717718
list_add_tail(&entry->list, &parent->children);
719+
mutex_unlock(&parent->access);
720+
}
718721
return entry;
719722
}
720723

@@ -792,7 +795,12 @@ void snd_info_free_entry(struct snd_info_entry * entry)
792795
list_for_each_entry_safe(p, n, &entry->children, list)
793796
snd_info_free_entry(p);
794797

795-
list_del(&entry->list);
798+
p = entry->parent;
799+
if (p) {
800+
mutex_lock(&p->access);
801+
list_del(&entry->list);
802+
mutex_unlock(&p->access);
803+
}
796804
kfree(entry->name);
797805
if (entry->private_free)
798806
entry->private_free(entry);

0 commit comments

Comments
 (0)