Skip to content

Commit 4cc8d65

Browse files
committed
ALSA: pcm: oss: Avoid potential buffer overflows
syzkaller reported an invalid access in PCM OSS read, and this seems to be an overflow of the internal buffer allocated for a plugin. Since the rate plugin adjusts its transfer size dynamically, the calculation for the chained plugin might be bigger than the given buffer size in some extreme cases, which lead to such an buffer overflow as caught by KASAN. Fix it by limiting the max transfer size properly by checking against the destination size in each plugin transfer callback. Reported-by: [email protected] Cc: <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 643a2cc commit 4cc8d65

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

sound/core/oss/linear.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ static snd_pcm_sframes_t linear_transfer(struct snd_pcm_plugin *plugin,
107107
}
108108
}
109109
#endif
110+
if (frames > dst_channels[0].frames)
111+
frames = dst_channels[0].frames;
110112
convert(plugin, src_channels, dst_channels, frames);
111113
return frames;
112114
}

sound/core/oss/mulaw.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ static snd_pcm_sframes_t mulaw_transfer(struct snd_pcm_plugin *plugin,
269269
}
270270
}
271271
#endif
272+
if (frames > dst_channels[0].frames)
273+
frames = dst_channels[0].frames;
272274
data = (struct mulaw_priv *)plugin->extra_data;
273275
data->func(plugin, src_channels, dst_channels, frames);
274276
return frames;

sound/core/oss/route.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ static snd_pcm_sframes_t route_transfer(struct snd_pcm_plugin *plugin,
5757
return -ENXIO;
5858
if (frames == 0)
5959
return 0;
60+
if (frames > dst_channels[0].frames)
61+
frames = dst_channels[0].frames;
6062

6163
nsrcs = plugin->src_format.channels;
6264
ndsts = plugin->dst_format.channels;

0 commit comments

Comments
 (0)