mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ALSA: mixer: oss: Fix uninitialized index in recsrc ioctls
@ 2026-11-04  7:56 songxiebing
  2026-11-04 14:34 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: songxiebing @ 2026-11-04  7:56 UTC (permalink / raw)
  To: tiwai, perex; +Cc: linux-sound, linux-kernel, songxiebing

From: Bob Song <songxiebing@kylinos.cn>

snd_mixer_oss_get_recsrc2() returns success without setting active_index
when the current Capture Source does not match any OSS mixer slot.
snd_mixer_oss_get_recsrc() then uses that uninitialized index for
"1 << index", and snd_mixer_oss_set_recsrc() does the same while ignoring
the callback's return value.

Make get_recsrc2() return -ENOENT if no slot matches, only use the
returned index in set_recsrc() when the lookup succeeds, and initialize
the index variables as a defensive measure.

Signed-off-by: Bob Song <songxiebing@kylinos.cn>
---
 sound/core/oss/mixer_oss.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c
index c533d767c29a..6c8ca1d320ac 100644
--- a/sound/core/oss/mixer_oss.c
+++ b/sound/core/oss/mixer_oss.c
@@ -185,7 +185,7 @@ static int snd_mixer_oss_get_recsrc(struct snd_mixer_oss_file *fmixer)
 		return -EIO;
 	guard(mutex)(&mixer->reg_mutex);
 	if (mixer->put_recsrc && mixer->get_recsrc) {	/* exclusive */
-		unsigned int index;
+		unsigned int index = 0;
 		result = mixer->get_recsrc(fmixer, &index);
 		if (result < 0)
 			return result;
@@ -212,7 +212,7 @@ static int snd_mixer_oss_set_recsrc(struct snd_mixer_oss_file *fmixer, int recsr
 	struct snd_mixer_oss *mixer = fmixer->mixer;
 	struct snd_mixer_oss_slot *pslot;
 	int chn, active;
-	unsigned int index;
+	unsigned int index = 0;
 	int result = 0;
 
 	if (mixer == NULL)
@@ -222,8 +222,8 @@ static int snd_mixer_oss_set_recsrc(struct snd_mixer_oss_file *fmixer, int recsr
 		if (recsrc & ~mixer->oss_recsrc)
 			recsrc &= ~mixer->oss_recsrc;
 		mixer->put_recsrc(fmixer, ffz(~recsrc));
-		mixer->get_recsrc(fmixer, &index);
-		result = 1 << index;
+		if (mixer->get_recsrc(fmixer, &index) == 0)
+			result = 1 << index;
 	}
 	for (chn = 0; chn < 31; chn++) {
 		pslot = &mixer->slots[chn];
@@ -826,6 +826,8 @@ static int snd_mixer_oss_get_recsrc2(struct snd_mixer_oss_file *fmixer, unsigned
 			break;
 		}
 	}
+	if (idx == 32)
+		return -ENOENT;
 	return 0;
 }
 
-- 
2.25.1


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

end of thread, other threads:[~2026-11-04 14:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04  7:56 [PATCH] ALSA: mixer: oss: Fix uninitialized index in recsrc ioctls songxiebing
2026-11-04 14:34 ` 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®