mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ALSA: sis7019: Don't shift the voice IRQ status by 32
@ 2026-11-22 10:08 Suyuan Wang via B4 Relay
  2026-11-23  9:00 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-22 10:08 UTC (permalink / raw)
  To: perex, tiwai; +Cc: linux-sound, linux-kernel

From: Suyuan Wang <stevewong@hust.edu.cn>

sis_voice_irq() walks the set bits of a PISR_A or PISR_B status word:

	bit = __ffs(status);
	status >>= bit + 1;

When voice 31 or 63 interrupts, bit is 31 and status is shifted by 32,
which is undefined for a u32. On x86 the shift count is masked to 0, so
status does not change, the loop never ends, and voice keeps moving 32
entries forward on every pass, past the end of sis->voices[], with
sis_update_voice() called on whatever is there. All of this runs in the
hard IRQ handler. Voices are handed out from 0 up, so voice 31 is in use
once enough playback streams are open.

Walk the bits with for_each_set_bit() and index the voice by bit number
instead. The voices are still updated in the same order.

Found with a static analysis tool and checked by hand.

Fixes: 175859bf1602 ("[ALSA] sis7019: support the SiS 7019 Audio Accelerator")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
Compile tested (i386, W=1). I don't have a SiS 7019, so I ran the old
and new loop in userspace on the same status words: with 0x80000000 the
old loop trips UBSan's shift check, and without it ASan reports a read
past the 64-entry voice array; the new loop updates voice 31 (or 63)
and stops.
---
 sound/pci/sis7019.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/sound/pci/sis7019.c b/sound/pci/sis7019.c
index fe5bda5af6a5..f31e62068ee3 100644
--- a/sound/pci/sis7019.c
+++ b/sound/pci/sis7019.c
@@ -278,15 +278,11 @@ static void sis_update_voice(struct voice *voice)
 
 static void sis_voice_irq(u32 status, struct voice *voice)
 {
+	unsigned long bits = status;
 	int bit;
 
-	while (status) {
-		bit = __ffs(status);
-		status >>= bit + 1;
-		voice += bit;
-		sis_update_voice(voice);
-		voice++;
-	}
+	for_each_set_bit(bit, &bits, 32)
+		sis_update_voice(&voice[bit]);
 }
 
 static irqreturn_t sis_interrupt(int irq, void *dev)





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

* Re: [PATCH] ALSA: sis7019: Don't shift the voice IRQ status by 32
  2026-11-22 10:08 [PATCH] ALSA: sis7019: Don't shift the voice IRQ status by 32 Suyuan Wang via B4 Relay
@ 2026-11-23  9:00 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-11-23  9:00 UTC (permalink / raw)
  To: shyckless; +Cc: perex, tiwai, linux-sound, linux-kernel

On Sun, 22 Nov 2026 11:08:16 +0100,
Suyuan Wang via B4 Relay wrote:
> 
> From: Suyuan Wang <stevewong@hust.edu.cn>
> 
> sis_voice_irq() walks the set bits of a PISR_A or PISR_B status word:
> 
> 	bit = __ffs(status);
> 	status >>= bit + 1;
> 
> When voice 31 or 63 interrupts, bit is 31 and status is shifted by 32,
> which is undefined for a u32. On x86 the shift count is masked to 0, so
> status does not change, the loop never ends, and voice keeps moving 32
> entries forward on every pass, past the end of sis->voices[], with
> sis_update_voice() called on whatever is there. All of this runs in the
> hard IRQ handler. Voices are handed out from 0 up, so voice 31 is in use
> once enough playback streams are open.
> 
> Walk the bits with for_each_set_bit() and index the voice by bit number
> instead. The voices are still updated in the same order.
> 
> Found with a static analysis tool and checked by hand.
> 
> Fixes: 175859bf1602 ("[ALSA] sis7019: support the SiS 7019 Audio Accelerator")
> Cc: stable@vger.kernel.org
> Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
> Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
> Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>

As this doesn't look like an urgent issue (for a legacy old code), I
applied to for-next branch.  Thanks.


Takashi

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

end of thread, other threads:[~2026-11-23  9:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-22 10:08 [PATCH] ALSA: sis7019: Don't shift the voice IRQ status by 32 Suyuan Wang via B4 Relay
2026-11-23  9:00 ` Takashi Iwai

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

all inboxes | Powered by JetHome®