Skip to content

Commit ff7e06a

Browse files
committed
ALSA: pcm: oss: Fix regression by buffer overflow fix (again)
[ This is essentially the same fix as commit ae769d3, but it's adapted to the latest code for 5.7; hence it contains no Fixes or other tags for avoid backport confusion -- tiwai ] The recent fix for the OOB access in PCM OSS plugins (commit f2ecf90: "ALSA: pcm: oss: Avoid plugin buffer overflow") caused a regression on OSS applications. The patch introduced the size check in client and slave size calculations to limit to each plugin's buffer size, but I overlooked that some code paths call those without allocating the buffer but just for estimation. This patch fixes the bug by skipping the size check for those code paths while keeping checking in the actual transfer calls. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent dbdd24e commit ff7e06a

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

sound/core/oss/pcm_plugin.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ int snd_pcm_plugin_free(struct snd_pcm_plugin *plugin)
197197
}
198198

199199
static snd_pcm_sframes_t calc_dst_frames(struct snd_pcm_substream *plug,
200-
snd_pcm_sframes_t frames)
200+
snd_pcm_sframes_t frames,
201+
bool check_size)
201202
{
202203
struct snd_pcm_plugin *plugin, *plugin_next;
203204

@@ -209,21 +210,22 @@ static snd_pcm_sframes_t calc_dst_frames(struct snd_pcm_substream *plug,
209210
if (frames < 0)
210211
return frames;
211212
}
212-
if (frames > plugin->buf_frames)
213+
if (check_size && frames > plugin->buf_frames)
213214
frames = plugin->buf_frames;
214215
plugin = plugin_next;
215216
}
216217
return frames;
217218
}
218219

219220
static snd_pcm_sframes_t calc_src_frames(struct snd_pcm_substream *plug,
220-
snd_pcm_sframes_t frames)
221+
snd_pcm_sframes_t frames,
222+
bool check_size)
221223
{
222224
struct snd_pcm_plugin *plugin, *plugin_prev;
223225

224226
plugin = snd_pcm_plug_last(plug);
225227
while (plugin && frames > 0) {
226-
if (frames > plugin->buf_frames)
228+
if (check_size && frames > plugin->buf_frames)
227229
frames = plugin->buf_frames;
228230
plugin_prev = plugin->prev;
229231
if (plugin->src_frames) {
@@ -242,9 +244,9 @@ snd_pcm_sframes_t snd_pcm_plug_client_size(struct snd_pcm_substream *plug, snd_p
242244
return -ENXIO;
243245
switch (snd_pcm_plug_stream(plug)) {
244246
case SNDRV_PCM_STREAM_PLAYBACK:
245-
return calc_src_frames(plug, drv_frames);
247+
return calc_src_frames(plug, drv_frames, false);
246248
case SNDRV_PCM_STREAM_CAPTURE:
247-
return calc_dst_frames(plug, drv_frames);
249+
return calc_dst_frames(plug, drv_frames, false);
248250
default:
249251
snd_BUG();
250252
return -EINVAL;
@@ -257,9 +259,9 @@ snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *plug, snd_pc
257259
return -ENXIO;
258260
switch (snd_pcm_plug_stream(plug)) {
259261
case SNDRV_PCM_STREAM_PLAYBACK:
260-
return calc_dst_frames(plug, clt_frames);
262+
return calc_dst_frames(plug, clt_frames, false);
261263
case SNDRV_PCM_STREAM_CAPTURE:
262-
return calc_src_frames(plug, clt_frames);
264+
return calc_src_frames(plug, clt_frames, false);
263265
default:
264266
snd_BUG();
265267
return -EINVAL;
@@ -622,7 +624,7 @@ snd_pcm_sframes_t snd_pcm_plug_write_transfer(struct snd_pcm_substream *plug, st
622624
src_channels = dst_channels;
623625
plugin = next;
624626
}
625-
return snd_pcm_plug_client_size(plug, frames);
627+
return calc_src_frames(plug, frames, true);
626628
}
627629

628630
snd_pcm_sframes_t snd_pcm_plug_read_transfer(struct snd_pcm_substream *plug, struct snd_pcm_plugin_channel *dst_channels_final, snd_pcm_uframes_t size)
@@ -632,7 +634,7 @@ snd_pcm_sframes_t snd_pcm_plug_read_transfer(struct snd_pcm_substream *plug, str
632634
snd_pcm_sframes_t frames = size;
633635
int err;
634636

635-
frames = snd_pcm_plug_slave_size(plug, frames);
637+
frames = calc_src_frames(plug, frames, true);
636638
if (frames < 0)
637639
return frames;
638640

0 commit comments

Comments
 (0)