ALSA core info race condition
hi ALSA team,
there is a race condition in below API when accessing list API.
In file sound/core/info.c:
Added below patch to avoid list access of same parent node by two threads at same time causing list_debug crash.
sound/core/info.c +4 -1
@@ -747,8 +747,11 @@ snd_info_create_entry(const char *name, struct snd_info_entry *parent)INIT_LIST_HEAD (&entry->children);INIT_LIST_HEAD (&entry->list); entry->parent = parent; -if (parent) +if (parent) { +mutex_lock (&parent->access);list_add_tail (&entry->list, &parent->children); +mutex_unlock (&parent->access); + }return entry; }
Please check above logic looks fine, and help comment accordingly.
Thanks
Kasam
Quoted 27 lines · On Tue, 27 Jun 2017 21:12:18 +0200, [email protected] wrote:
hi ALSA team,
there is a race condition in below API when accessing list API.In file
sound/core/info.c:Added below patch to avoid list access of same parent node by two threads at same time causing
list_debugcrash.sound/core/info.c +4
-1@@ -747,8 +747,11 @@ snd_info_create_entry(const char *name, struct snd_info_entry *parent) INIT_LIST_HEAD(&entry->children);INIT_LIST_HEAD (&entry->list); entry->parent = parent; -if (parent) +if (parent) { +mutex_lock (&parent->access);list_add_tail (&entry->list, &parent->children); +mutex_unlock (&parent->access); + }return entry; }
Quoted 1 line
Please check above logic looks fine, and help comment accordingly.
Have you ever got the actual crash?
The function is supposed to be called only at probing, and its link base is the card object, so it's never called concurrently or the concurrency should be managed in the caller side.
Your "fix" looks OK, but it's likely superfluous from the actual usage. Still it might be safer to add a protection, though.
thanks,
Takashi
Quoted 36 lines · Takashi Iwai
Quoted 27 lines · On Tue, 27 Jun 2017 21:12:18 +0200, [email protected] wrote:
hi ALSA team,
there is a race condition in below API when accessing list API.In file
sound/core/info.c:Added below patch to avoid list access of same parent node by two threads at same time causing
list_debugcrash.sound/core/info.c +4
-1@@ -747,8 +747,11 @@ snd_info_create_entry(const char *name, struct snd_info_entry *parent) INIT_LIST_HEAD(&entry->children);INIT_LIST_HEAD (&entry->list); entry->parent = parent; -if (parent) +if (parent) { +mutex_lock (&parent->access);list_add_tail (&entry->list, &parent->children); +mutex_unlock (&parent->access); + }return entry; }Quoted 1 line
Please check above logic looks fine, and help comment accordingly.
Have you ever got the actual crash?
The function is supposed to be called only at probing, and its link base is the card object, so it's never called concurrently or the concurrency should be managed in the caller side.
Quoted 7 lines
Your "fix" looks OK, but it's likely superfluous from the actual usage. Still it might be safer to add a protection, though.
thanks,
Takashi
Yes Takashi, we found this crash happened on Qualcomm platform.
And as mentioned by you...it is used at bootup probe but from two different contexts, Even if I try to manage at client level ...it will be only workaround. so actual fix should be the patch I shared to avoid any similar issues in future.
thanks
Laxminath
Quoted 47 lines · On Wed, 28 Jun 2017 07:58:07 +0200, [email protected] wrote:
Quoted 36 lines · Takashi Iwai
Quoted 27 lines · On Tue, 27 Jun 2017 21:12:18 +0200, [email protected] wrote:
hi ALSA team,
there is a race condition in below API when accessing list API.In file
sound/core/info.c:Added below patch to avoid list access of same parent node by two threads at same time causing
list_debugcrash.sound/core/info.c +4
-1@@ -747,8 +747,11 @@ snd_info_create_entry(const char *name, struct snd_info_entry *parent) INIT_LIST_HEAD(&entry->children);INIT_LIST_HEAD (&entry->list); entry->parent = parent; -if (parent) +if (parent) { +mutex_lock (&parent->access);list_add_tail (&entry->list, &parent->children); +mutex_unlock (&parent->access); + }return entry; }Quoted 1 line
Please check above logic looks fine, and help comment accordingly.
Have you ever got the actual crash?
The function is supposed to be called only at probing, and its link base is the card object, so it's never called concurrently or the concurrency should be managed in the caller side.Quoted 7 lines
Your "fix" looks OK, but it's likely superfluous from the actual usage. Still it might be safer to add a protection, though.
thanks,
Takashi
Quoted 6 lines
Yes Takashi, we found this crash happened on Qualcomm platform. And as mentioned by you...it is used at bootup probe but from two different contexts,
Even if I try to manage at client level ...it will be only workaround. so actual fix
should be the patch I shared to avoid any similar issues in future.
Hrm, it already smells suspicious. The situation where the proc file creation on the same root is called concurrently implies the racy registration, not only about the proc...
But it makes no sense to discuss without the actual code, and the suggested change looks OK, as said. So please submit a proper patch in the usual manner.
thanks,
Takashi