Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ALSA: vmaster: Check follower callback errors
@ 2026-11-26  6:53 Sreeraj S Kurup
  2026-11-26  7:02 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Sreeraj S Kurup @ 2026-11-26  6:53 UTC (permalink / raw)
  To: perex, tiwai; +Cc: linux-kernel, linux-sound, Sreeraj S Kurup

Check the return values of follower_get_val() and
follower_put_val() in sync_followers().

Stop synchronization and return the error when either
callback fails.

Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
 sound/core/vmaster.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/sound/core/vmaster.c b/sound/core/vmaster.c
index f43144ba2797..88b38ee5ba5f 100644
--- a/sound/core/vmaster.c
+++ b/sound/core/vmaster.c
@@ -345,17 +345,27 @@ static int sync_followers(struct link_master *master, int old_val, int new_val)
 	struct link_follower *follower;
 	struct snd_ctl_elem_value *uval __free(kfree) =
 		kmalloc_obj(*uval);
+	int err;
 
 	if (!uval)
 		return -ENOMEM;
 	list_for_each_entry(follower, &master->followers, list) {
 		master->val = old_val;
 		uval->id = follower->follower.id;
-		follower_get_val(follower, uval);
+		err = follower_get_val(follower, uval);
+		if (err < 0)
+			goto error;
+
 		master->val = new_val;
-		follower_put_val(follower, uval);
+		err = follower_put_val(follower, uval);
+		if (err < 0)
+			goto error;
 	}
 	return 0;
+
+error:
+	master->val = old_val;
+	return err;
 }
 
 static int master_put(struct snd_kcontrol *kcontrol,
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ALSA: vmaster: Check follower callback errors
  2026-11-26  6:53 [PATCH] ALSA: vmaster: Check follower callback errors Sreeraj S Kurup
@ 2026-11-26  7:02 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-26  7:02 UTC (permalink / raw)
  To: Sreeraj S Kurup; +Cc: linux-sound

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] ALSA: vmaster: use-after-free in sync_followers() [1]
--

commit e1ba86351d2c61db18d124cbf361fe1a670040d9
Author: Sreeraj S Kurup <sreekuttan2156239@gmail.com>

ALSA: vmaster: Check follower callback errors

This commit checks the return values of follower_get_val() and
follower_put_val() in sync_followers() and aborts synchronization on error.

> diff --git a/sound/core/vmaster.c b/sound/core/vmaster.c
> index f43144ba27978..88b38ee5ba5f6 100644
> --- a/sound/core/vmaster.c
> +++ b/sound/core/vmaster.c
> @@ -345,17 +345,27 @@ static int sync_followers(struct link_master *master, int old_val, int new_val)
>  	struct link_follower *follower;
>  	struct snd_ctl_elem_value *uval __free(kfree) =
>  		kmalloc_obj(*uval);
> +	int err;
>  
>  	if (!uval)
>  		return -ENOMEM;
>  	list_for_each_entry(follower, &master->followers, list) {
>  		master->val = old_val;
>  		uval->id = follower->follower.id;
> -		follower_get_val(follower, uval);
> +		err = follower_get_val(follower, uval);

[Severity: Critical]
This problem wasn't introduced by this patch, but can traversing
master->followers here cause a use-after-free on follower [1]?

When an unsolicited hotplug jack event calls snd_ctl_sync_vmaster(), it
invokes sync_followers() without holding card->controls_rwsem.  A
concurrent snd_ctl_remove() can unlink and free a follower via
follower_free() while the list is being walked:

CPU0                                CPU1
snd_ctl_sync_vmaster()
  sync_followers()
    list_for_each_entry(follower, &master->followers, list)
                                    snd_ctl_remove()
                                      follower_free()
                                        list_del(&follower->list)
                                        kfree(follower)
      uval->id = follower->follower.id;  <-- use-after-free

[1] https://sashiko.dev/#/bug/linux-922db78b-8e7d-4396-bf14-07bd594a9a8a

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126065310.3451-1-sreekuttan2156239@gmail.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-26  7:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  6:53 [PATCH] ALSA: vmaster: Check follower callback errors Sreeraj S Kurup
2026-11-26  7:02 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox