From: Takashi Iwai <tiwai@suse.de>
To: Duoming Zhou <duoming@zju.edu.cn>
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
tiwai@suse.com, perex@perex.cz
Subject: Re: [PATCH v2] ALSA: sh: aica: reorder cleanup operations to avoid UAF bugs
Date: Tue, 26 Mar 2024 12:19:50 +0100 [thread overview]
Message-ID: <87msqlutnt.wl-tiwai@suse.de> (raw)
In-Reply-To: <20240326094238.95442-1-duoming@zju.edu.cn>
On Tue, 26 Mar 2024 10:42:38 +0100,
Duoming Zhou wrote:
>
> The dreamcastcard->timer could schedule the spu_dma_work and the
> spu_dma_work could also arm the dreamcastcard->timer.
>
> When the snd_pcm_substream is closing, the aica_channel will be
> deallocated. But it could still be dereferenced in the worker
> thread. The reason is that del_timer() will return directly
> regardless of whether the timer handler is running or not and
> the worker could be rescheduled in the timer handler. As a result,
> the UAF bug will happen. The racy situation is shown below:
>
> (Thread 1) | (Thread 2)
> snd_aicapcm_pcm_close() |
> ... | run_spu_dma() //worker
> | mod_timer()
> flush_work() |
> del_timer() | aica_period_elapsed() //timer
> kfree(dreamcastcard->channel) | schedule_work()
> | run_spu_dma() //worker
> ... | dreamcastcard->channel-> //USE
>
> In order to mitigate this bug and other possible corner cases,
> call mod_timer() conditionally in run_spu_dma(), then implement
> PCM sync_stop op to cancel both the timer and worker. The sync_stop
> op will be called from PCM core appropriately when needed.
>
> Fixes: 198de43d758c ("[ALSA] Add ALSA support for the SEGA Dreamcast PCM device")
> Suggested-by: Takashi Iwai <tiwai@suse.de>
> Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
> ---
> Changes in v2:
> - call mod_timer() conditionally and implement PCM sync_stop op.
Thanks, applied now.
Takashi
prev parent reply other threads:[~2024-03-26 11:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-26 9:42 [PATCH v2] ALSA: sh: aica: reorder cleanup operations to avoid UAF bugs Duoming Zhou
2024-03-26 11:19 ` Takashi Iwai [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87msqlutnt.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=duoming@zju.edu.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox