Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ALSA: wavefront: Fix integer overflow in sample size validation
@ 2025-11-04 14:10 moonafterrain
  2025-11-05  8:32 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: moonafterrain @ 2025-11-04 14:10 UTC (permalink / raw)
  To: Jaroslav Kysela, Takashi Iwai
  Cc: linux-sound, linux-kernel, stable, Yuhao Jiang, Junrui Luo

From: Junrui Luo <moonafterrain@outlook.com>

The wavefront_send_sample() function has an integer overflow issue
when validating sample size. The header->size field is u32 but gets
cast to int for comparison with dev->freemem

Fix by using unsigned comparison to avoid integer overflow.

Reported-by: Yuhao Jiang <danisjiang@gmail.com>
Reported-by: Junrui Luo <moonafterrain@outlook.com>
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Junrui Luo <moonafterrain@outlook.com>
---
 sound/isa/wavefront/wavefront_synth.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/isa/wavefront/wavefront_synth.c b/sound/isa/wavefront/wavefront_synth.c
index cd5c177943aa..4a8c507eae71 100644
--- a/sound/isa/wavefront/wavefront_synth.c
+++ b/sound/isa/wavefront/wavefront_synth.c
@@ -950,9 +950,9 @@ wavefront_send_sample (snd_wavefront_t *dev,
 	if (header->size) {
 		dev->freemem = wavefront_freemem (dev);
 
-		if (dev->freemem < (int)header->size) {
+		if ((unsigned int)dev->freemem < header->size) {
 			dev_err(dev->card->dev,
-				"insufficient memory to load %d byte sample.\n",
+				"insufficient memory to load %u byte sample.\n",
 				header->size);
 			return -ENOMEM;
 		}
-- 
2.51.1.dirty


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

* Re: [PATCH] ALSA: wavefront: Fix integer overflow in sample size validation
  2025-11-04 14:10 [PATCH] ALSA: wavefront: Fix integer overflow in sample size validation moonafterrain
@ 2025-11-05  8:32 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2025-11-05  8:32 UTC (permalink / raw)
  To: moonafterrain
  Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, linux-kernel, stable,
	Yuhao Jiang

On Tue, 04 Nov 2025 15:10:18 +0100,
moonafterrain@outlook.com wrote:
> 
> From: Junrui Luo <moonafterrain@outlook.com>
> 
> The wavefront_send_sample() function has an integer overflow issue
> when validating sample size. The header->size field is u32 but gets
> cast to int for comparison with dev->freemem
> 
> Fix by using unsigned comparison to avoid integer overflow.

This is not really a right fix, unfortunately.
wavefront_freemem() itself can return a negative value, and the cast
would ignore it.

A better alternative could be something like:
	if (dev->freemem < 0 || dev->freemem < header->size) {
so that the cast can be dropped to be compared as unsigned
implicitly.

Not sure whether this still triggers some warnings in the recent
compilers, though.  Need testing.


thanks,

Takashi

> 
> Reported-by: Yuhao Jiang <danisjiang@gmail.com>
> Reported-by: Junrui Luo <moonafterrain@outlook.com>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Cc: stable@vger.kernel.org
> Signed-off-by: Junrui Luo <moonafterrain@outlook.com>
> ---
>  sound/isa/wavefront/wavefront_synth.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/sound/isa/wavefront/wavefront_synth.c b/sound/isa/wavefront/wavefront_synth.c
> index cd5c177943aa..4a8c507eae71 100644
> --- a/sound/isa/wavefront/wavefront_synth.c
> +++ b/sound/isa/wavefront/wavefront_synth.c
> @@ -950,9 +950,9 @@ wavefront_send_sample (snd_wavefront_t *dev,
>  	if (header->size) {
>  		dev->freemem = wavefront_freemem (dev);
>  
> -		if (dev->freemem < (int)header->size) {
> +		if ((unsigned int)dev->freemem < header->size) {
>  			dev_err(dev->card->dev,
> -				"insufficient memory to load %d byte sample.\n",
> +				"insufficient memory to load %u byte sample.\n",
>  				header->size);
>  			return -ENOMEM;
>  		}
> -- 
> 2.51.1.dirty
> 

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

end of thread, other threads:[~2025-11-05  8:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-04 14:10 [PATCH] ALSA: wavefront: Fix integer overflow in sample size validation moonafterrain
2025-11-05  8:32 ` Takashi Iwai

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