Commit b2a2c174 authored by Takashi Iwai's avatar Takashi Iwai Committed by Stefan Bader

ALSA: info: Fix racy addition/deletion of nodes

BugLink: https://bugs.launchpad.net/bugs/1828420

commit 8c2f8708 upstream.

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: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
parent c2f4874a
...@@ -724,8 +724,11 @@ snd_info_create_entry(const char *name, struct snd_info_entry *parent) ...@@ -724,8 +724,11 @@ snd_info_create_entry(const char *name, struct snd_info_entry *parent)
INIT_LIST_HEAD(&entry->children); INIT_LIST_HEAD(&entry->children);
INIT_LIST_HEAD(&entry->list); INIT_LIST_HEAD(&entry->list);
entry->parent = parent; entry->parent = parent;
if (parent) if (parent) {
mutex_lock(&parent->access);
list_add_tail(&entry->list, &parent->children); list_add_tail(&entry->list, &parent->children);
mutex_unlock(&parent->access);
}
return entry; return entry;
} }
...@@ -809,7 +812,12 @@ void snd_info_free_entry(struct snd_info_entry * entry) ...@@ -809,7 +812,12 @@ void snd_info_free_entry(struct snd_info_entry * entry)
list_for_each_entry_safe(p, n, &entry->children, list) list_for_each_entry_safe(p, n, &entry->children, list)
snd_info_free_entry(p); snd_info_free_entry(p);
list_del(&entry->list); p = entry->parent;
if (p) {
mutex_lock(&p->access);
list_del(&entry->list);
mutex_unlock(&p->access);
}
kfree(entry->name); kfree(entry->name);
if (entry->private_free) if (entry->private_free)
entry->private_free(entry); entry->private_free(entry);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment