Re: [PATCH] ALSA: control: do not access controls without possession of r_w lock

From: Takashi Iwai
Date: Tue Sep 12 2023 - 04:50:28 EST


On Tue, 12 Sep 2023 10:45:30 +0200,
Ma Ke wrote:
>
> we should not access any of its memory when we don't ensure possession of
> a read/write lock. Otherwise we risk a use after free access, which allows
> local users to cause a denial of service and obtain sensitive information
> from kernel memory.

This function is called always under card->controls_rwsem.
So it should be OK as is.


thanks,

Takashi

>
> Signed-off-by: Ma Ke <make_ruc2021@xxxxxxx>
> ---
> sound/core/control.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/sound/core/control.c b/sound/core/control.c
> index 59c8658966d4..98782cc68ee1 100644
> --- a/sound/core/control.c
> +++ b/sound/core/control.c
> @@ -590,7 +590,8 @@ static int __snd_ctl_remove(struct snd_card *card,
> remove_hash_entries(card, kcontrol);
>
> card->controls_count -= kcontrol->count;
> - for (idx = 0; idx < kcontrol->count; idx++)
> + count = kcontrol->count;
> + for (idx = 0; idx < count; idx++)
> snd_ctl_notify_one(card, SNDRV_CTL_EVENT_MASK_REMOVE, kcontrol, idx);
> snd_ctl_free_one(kcontrol);
> return 0;
> --
> 2.37.2
>