Re: [PATCH] ALSA: hwdep: do not free a still-open hwdep on single-device teardown
From: Takashi Iwai
Date: Wed Dec 02 2026 - 03:58:13 EST
On Wed, 02 Dec 2026 03:07:03 +0100,
Hanxiang Xu wrote:
>
> An independent teardown path calls snd_device_free(card, hwdep),
> which runs snd_hwdep_free(): it kfrees the struct snd_hwdep without
> waiting for hwdep->used to drop. Open descriptors keep
> file->private_data pointing at the freed object with the real hwdep
> f_ops, and their in-flight or later operations (ioctl/read/poll and
> the final close) are use-after-frees. The card-wide path swaps
> file->f_op for stub operations, but a single-device teardown never
> runs it.
>
> Refuse the free while hwdep->used is non-zero: __snd_device_free()
> still unlinks the snd_device wrapper, so the card never revisits the
> device, and the object stays valid for the open descriptors.
>
> Cc: <stable@xxxxxxxxxxxxxxx>
> Signed-off-by: Hanxiang Xu <xuhx@xxxxxxxxxxx>
This is no-no. You need a synchronization before release, instead.
Takashi