Linux Sound subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: 徐晗翔 <xuhx@hust.edu.cn>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH] Re: ALSA: asihpi: free IRQ before snd_card_free()/HPI delete on HPI6205 removal (UAF)
Date: Wed, 25 Nov 2026 13:03:05 +0000	[thread overview]
Message-ID: <sashiko-outbox-233432@kernel.org> (raw)
In-Reply-To: <2c1d9b73.57c.1a212c1b142.Coremail.xuhx@hust.edu.cn>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] ALSA: asihpi: missing Signed-off-by trailer in commit message
- [Medium] ALSA: asihpi: free_irq() before snd_card_disconnect() in
  snd_asihpi_remove()
- [Low] ALSA: asihpi: missing Fixes trailer in bug-fix commit message
- [Low] ALSA: asihpi: free_irq() remains after HPI_ADAPTER_DELETE in
  asihpi_adapter_remove()
--

commit 66e65e67203827236524ee91f5a02759ca055bf4
Author: 徐晗翔 <xuhx@hust.edu.cn>

> ALSA: asihpi: free IRQ before snd_card_free()/HPI delete on HPI6205 removal (UAF)
>
> snd_asihpi_remove() freed the ALSA card and then sent
> HPI_ADAPTER_DELETE (kfree()ing the HPI6205 phw) BEFORE free_irq():
> both the primary handler (adapter_irq_query_and_clear() reads
> phw->prHSR) and the threaded handler (snd_card_asihpi_isr() reads
> a->snd_card->private_data) could run against freed memory.
>
> free_irq() -- the first operation that waits for the in-flight
> primary and threaded handlers -- now runs before snd_card_free()
> and before HPI_ADAPTER_DELETE, with hpi->irq cleared so the existing
> if (pa->irq) guard in asihpi_adapter_remove() does not double-free

[Severity: High]
The commit message is missing a Signed-off-by: trailer, which is required by
the Developer's Certificate of Origin (Documentation/process/submitting-patches.rst).

[Severity: Low]
Since this fixes a use-after-free bug on device removal, should the commit
message include a Fixes: trailer (and a closing period on the last sentence):

  Fixes: f9a376c3f6d7 ("ALSA: asihpi: Add support for stream interrupt.")

> diff --git a/sound/pci/asihpi/asihpi.c b/sound/pci/asihpi/asihpi.c
> index b78e96caef9d0..e3d863c4bdc88 100644
> --- a/sound/pci/asihpi/asihpi.c
> +++ b/sound/pci/asihpi/asihpi.c
> @@ -2927,6 +2927,20 @@ static void snd_asihpi_remove(struct pci_dev *pci_dev)
>  			HPI_ADAPTER_PROPERTY_IRQ_RATE, 0, 0));
>  	}
>  
> +	/* Free/quiesce the IRQ before the card and the HPI adapter objects
> +	 * go away: free_irq() is the first (and only) operation that waits
> +	 * for the in-flight primary and threaded handlers.  Afterwards
> +	 * snd_card_free() releases the card private area (read by
> +	 * snd_card_asihpi_isr() through a->snd_card->private_data) and
> +	 * asihpi_adapter_remove() sends HPI_ADAPTER_DELETE, which kfree()s
> +	 * the phw whose prHSR the primary handler dereferences through
> +	 * adapter_irq_query_and_clear().  asihpi_adapter_remove() keeps its
> +	 * if (pa->irq) guard, so this is not a double free_irq(). */
> +	if (hpi->irq) {
> +		free_irq(hpi->irq, hpi);
> +		hpi->irq = 0;
> +	}
> +
>  	snd_card_free(hpi->snd_card);
>  	hpi->snd_card = NULL;
>  	asihpi_adapter_remove(pci_dev);

[Severity: Medium]
Can a concurrent PCM trigger re-enable DSP interrupts on HPI6205 before
snd_card_free() disconnects the card, leaving the shared PCI INTx line
asserted after free_irq() removes asihpi_isr()?

CPU0                                  CPU1
snd_asihpi_remove()
  hpi_adapter_set_property(...,
    HPI_ADAPTER_PROPERTY_IRQ_RATE, 0, 0)
                                      snd_card_asihpi_trigger()
                                        snd_card_asihpi_pcm_int_start()
                                          hpi_adapter_set_property(...,
                                            HPI_ADAPTER_PROPERTY_IRQ_RATE,
                                            card->update_interval_frames, 0)
  free_irq(hpi->irq, hpi)
  snd_card_free(hpi->snd_card)
    snd_card_free_when_closed()
      snd_card_disconnect()
    wait_for_completion(&released)    <-- DSP asserts C6205_HSR_INTSRC with
                                          no handler to clear phw->prHSR

ALSA file operations remain active until snd_card_disconnect() runs inside
snd_card_free().  If a concurrent PCM start or pause-release trigger (or an
HPI_ADAPTER_SET_PROPERTY hwdep ioctl) sets HPI_ADAPTER_PROPERTY_IRQ_RATE back
to a non-zero value before snd_card_disconnect(), the DSP can assert the
shared level-triggered interrupt after free_irq() has unregistered
asihpi_isr().  Even after snd_card_disconnect() stops the stream by zeroing
HPI_ADAPTER_PROPERTY_IRQ_RATE, nothing clears C6205_HSR_INTSRC in phw->prHSR
while snd_card_free() waits for open descriptors to close, causing an
unhandled interrupt storm.  Calling snd_card_disconnect(hpi->snd_card) before
disabling HPI_ADAPTER_PROPERTY_IRQ_RATE and calling free_irq() would stop
active streams and block new userspace operations while keeping
hpi->snd_card allocated until snd_card_free().

[Severity: Low]
Does clearing hpi->irq here leave the free_irq() call in
asihpi_adapter_remove() as dead code while keeping the broken teardown order
in asihpi_adapter_remove() itself?

sound/pci/asihpi/hpioctl.c:asihpi_adapter_remove() {
    ...
	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
		HPI_ADAPTER_DELETE);
	hm.adapter_index = pa->adapter->index;
	hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);

	if (pa->irq)
		free_irq(pa->irq, pa);
    ...
}

asihpi_adapter_probe() requests the IRQ, and asihpi_adapter_remove() is its
teardown counterpart, where HPI_ADAPTER_DELETE still runs before free_irq().
Removing the duplicate free_irq() from asihpi_adapter_remove() (or moving it
before HPI_ADAPTER_DELETE) would avoid leaving dead code and a latent
use-after-free trap for any direct caller of asihpi_adapter_remove().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/2c1d9b73.57c.1a212c1b142.Coremail.xuhx@hust.edu.cn?part=1

  reply	other threads:[~2026-11-25 13:03 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4c7f9772.192e1.1a17d5c2ed5.Coremail.xuhx@hust.edu.cn>
     [not found] ` <2026102727-data-sequel-ce41@gregkh>
2026-11-13 11:58   ` ALSA: ctxfi: free atimer only after the timer IRQ is quiesced 徐晗翔
2026-11-13 16:30     ` Takashi Iwai
2026-11-25 12:51       ` [PATCH] Re: " 徐晗翔
2026-11-25 13:00         ` sashiko-bot
2026-11-13 12:03   ` ALSA: ctxfi: do not free a running system timer when timer_delete_sync_try() returns -1 (UAF) 徐晗翔
2026-11-25 12:51     ` [PATCH] " 徐晗翔
2026-11-25 13:05       ` sashiko-bot
2026-11-13 12:04   ` ALSA: asihpi: free IRQ before snd_card_free()/HPI delete on HPI6205 removal (UAF) 徐晗翔
2026-11-25 12:50     ` [PATCH] " 徐晗翔
2026-11-25 13:03       ` sashiko-bot [this message]
2026-11-13 12:06   ` ALSA: asihpi: quiesce PCM timer and IRQ before freeing dpcm on close (UAF) 徐晗翔
2026-11-25 12:50     ` [PATCH] " 徐晗翔
2026-11-25 13:06       ` sashiko-bot
2026-11-13 12:15   ` ALSA: pcm: link-group walk in timer callback can use a closed substream's freed runtime (UAF) 徐晗翔
2026-11-25 12:55     ` [PATCH] " 徐晗翔
2026-11-25 13:12       ` sashiko-bot
2026-11-13 12:28   ` ALSA: usb-audio: us144mkii: PCM close frees runtime while playback/feedback URB completion and capture work still use it (UAF) 徐晗翔
2026-11-25 12:48     ` [PATCH] " 徐晗翔
2026-11-25 13:13       ` sashiko-bot
2026-11-13 12:29   ` ALSA: usb-audio: us144mkii: queued stop_pcm_work calls snd_pcm_stop() after PCM close and dereferences NULL runtime 徐晗翔
2026-11-25 12:49     ` [PATCH] " 徐晗翔
2026-11-25 13:03       ` sashiko-bot
2026-11-22  7:43   ` sound: core: compress offload fd does not pin card or module, so card removal leaves a live fd pointing at freed snd_compr (KASAN UAF) 徐晗翔
2026-11-22  8:07     ` Takashi Iwai
2026-11-25 12:44       ` [PATCH] Re: " 徐晗翔
2026-11-22  7:48   ` sound: core: jack kcontrol is published before jack_kctl allocation, and the failure path frees it without removing it from card->controls (null-ptr-deref) 徐晗翔
2026-11-24  9:39     ` Sreeraj S Kurup
2026-11-25 12:43       ` 徐晗翔
2026-11-22  7:50   ` sound: core: rawmidi input close can re-queue event_work after cancel_work_sync() (UAF) 徐晗翔
2026-11-24 14:52     ` Krzysztof Kozlowski
2026-11-25 12:45       ` [PATCH] Re: " 徐晗翔
2026-11-22  7:52   ` sound: core: hwdep DSP_LOAD check-then-act is unlocked, allowing concurrent DSP_LOAD callbacks (UAF) 徐晗翔
2026-11-25 12:46     ` [PATCH] " 徐晗翔
2026-11-22  7:55   ` sound: core: get_available_index() calls snd_ctl_find_id() without controls_rwsem (UAF risk) 徐晗翔
2026-11-25 12:46     ` [PATCH] " 徐晗翔
2026-11-25 12:51       ` sashiko-bot
2026-11-22  7:56   ` sound: core: OSS mixer notify callback is invoked without module pin or mutex, racing with rmmod 徐晗翔
2026-11-25 12:47     ` [PATCH] " 徐晗翔
2026-11-22  7:57   ` sound: timer: snd_utimer_fops lacks .owner, so an open user timer fd does not pin snd-timer 徐晗翔
2026-11-25 12:48     ` [PATCH] " 徐晗翔

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=sashiko-outbox-233432@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xuhx@hust.edu.cn \
    /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