Skip to contentSkip to conversation

ALSA: pcm: use new array-copying-wrapper

PATCH In review yangchenyuan 2 participants 3 messages Jan 27, 2025 – Jan 28, 2025 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: pcm: use new array-copying-wrapper

From: Chenyuan Yang <[email protected]>

This is found by our static analysis tool.

pcm_native.c utilizes memdup_user() to copy an array from userspace.

There is a new wrapper, specifically designed for copying arrays. Use this one instead.

This is similar to the
commit 3e91a38de1dc ("fbdev: viafb: use new array-copying-wrapper").

Fixes 67616feda99e ("ALSA: pcm: Unify ioctl functions for playback and capture streams")
---
 sound/core/pcm_native.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/pcm_native.c +1 -1
index 8a3384342e8d..6c2b6a62d9d2 100644
@@ -3245,7 +3245,7 @@ static int snd_pcm_xfern_frames_ioctl(struct snd_pcm_substream *substream,
 	if (copy_from_user(&xfern, _xfern, sizeof(xfern)))
 		return -EFAULT;
 
-	bufs = memdup_user(xfern.bufs, sizeof(void *) * runtime->channels);
+	bufs = memdup_array_user(xfern.bufs, runtime->channels, sizeof(void *));
 	if (IS_ERR(bufs))
 		return PTR_ERR(bufs);
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Signature · 1 line
2.34.1
#1 lore raw
Quoted 7 lines · yangchenyuan

From: Chenyuan Yang <[email protected]>

This is found by our static analysis tool.

pcm_native.c utilizes memdup_user() to copy an array from userspace.

Quoted 7 lines

There is a new wrapper, specifically designed for copying arrays. Use this one instead.

This is similar to the
commit 3e91a38de1dc ("fbdev: viafb: use new array-copying-wrapper").

Fixes 67616feda99e ("ALSA: pcm: Unify ioctl functions for playback and capture streams")

This use of Fixes tag is misleading: the original code is correct, per se, and the original commit was 4.14, where it had no no memdup_array_user() available (introduced since 6.7).

So I applied with the drop of Fixes tag.

thanks,

Takashi

#2 lore raw

Hi Takashi,

It looks great to me! Thanks so much for your help!

Best,
Chenyuan

Quoted 28 lines · Takashi Iwai
Quoted 7 lines · yangchenyuan

From: Chenyuan Yang <[email protected]>

This is found by our static analysis tool.

pcm_native.c utilizes memdup_user() to copy an array from userspace.

Quoted 7 lines

There is a new wrapper, specifically designed for copying arrays. Use this one instead.

This is similar to the
commit 3e91a38de1dc ("fbdev: viafb: use new array-copying-wrapper").

Fixes 67616feda99e ("ALSA: pcm: Unify ioctl functions for playback and capture streams")

This use of Fixes tag is misleading: the original code is correct, per se, and the original commit was 4.14, where it had no no memdup_array_user() available (introduced since 6.7).

So I applied with the drop of Fixes tag.

thanks,

Takashi