Skip to content
/ linux Public

Commit e6645e6

Browse files
tiwaiSasha Levin
authored andcommitted
ALSA: mixer: oss: Add card disconnect checkpoints
[ Upstream commit 084d5d4 ] ALSA OSS mixer layer calls the kcontrol ops rather individually, and pending calls might be not always caught at disconnecting the device. For avoiding the potential UAF scenarios, add sanity checks of the card disconnection at each entry point of OSS mixer accesses. The rwsem is taken just before that check, hence the rest context should be covered by that properly. Link: https://patch.msgid.link/20260209121212.171430-1-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 572e427 commit e6645e6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

sound/core/oss/mixer_oss.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,8 @@ static void snd_mixer_oss_get_volume1_vol(struct snd_mixer_oss_file *fmixer,
525525
if (numid == ID_UNKNOWN)
526526
return;
527527
guard(rwsem_read)(&card->controls_rwsem);
528+
if (card->shutdown)
529+
return;
528530
kctl = snd_ctl_find_numid(card, numid);
529531
if (!kctl)
530532
return;
@@ -558,6 +560,8 @@ static void snd_mixer_oss_get_volume1_sw(struct snd_mixer_oss_file *fmixer,
558560
if (numid == ID_UNKNOWN)
559561
return;
560562
guard(rwsem_read)(&card->controls_rwsem);
563+
if (card->shutdown)
564+
return;
561565
kctl = snd_ctl_find_numid(card, numid);
562566
if (!kctl)
563567
return;
@@ -618,6 +622,8 @@ static void snd_mixer_oss_put_volume1_vol(struct snd_mixer_oss_file *fmixer,
618622
if (numid == ID_UNKNOWN)
619623
return;
620624
guard(rwsem_read)(&card->controls_rwsem);
625+
if (card->shutdown)
626+
return;
621627
kctl = snd_ctl_find_numid(card, numid);
622628
if (!kctl)
623629
return;
@@ -655,6 +661,8 @@ static void snd_mixer_oss_put_volume1_sw(struct snd_mixer_oss_file *fmixer,
655661
if (numid == ID_UNKNOWN)
656662
return;
657663
guard(rwsem_read)(&card->controls_rwsem);
664+
if (card->shutdown)
665+
return;
658666
kctl = snd_ctl_find_numid(card, numid);
659667
if (!kctl)
660668
return;
@@ -792,6 +800,8 @@ static int snd_mixer_oss_get_recsrc2(struct snd_mixer_oss_file *fmixer, unsigned
792800
if (uinfo == NULL || uctl == NULL)
793801
return -ENOMEM;
794802
guard(rwsem_read)(&card->controls_rwsem);
803+
if (card->shutdown)
804+
return -ENODEV;
795805
kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
796806
if (!kctl)
797807
return -ENOENT;
@@ -835,6 +845,8 @@ static int snd_mixer_oss_put_recsrc2(struct snd_mixer_oss_file *fmixer, unsigned
835845
if (uinfo == NULL || uctl == NULL)
836846
return -ENOMEM;
837847
guard(rwsem_read)(&card->controls_rwsem);
848+
if (card->shutdown)
849+
return -ENODEV;
838850
kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
839851
if (!kctl)
840852
return -ENOENT;
@@ -878,6 +890,8 @@ static int snd_mixer_oss_build_test(struct snd_mixer_oss *mixer, struct slot *sl
878890
int err;
879891

880892
scoped_guard(rwsem_read, &card->controls_rwsem) {
893+
if (card->shutdown)
894+
return -ENODEV;
881895
kcontrol = snd_mixer_oss_test_id(mixer, name, index);
882896
if (kcontrol == NULL)
883897
return 0;
@@ -1002,6 +1016,8 @@ static int snd_mixer_oss_build_input(struct snd_mixer_oss *mixer,
10021016
if (snd_mixer_oss_build_test_all(mixer, ptr, &slot))
10031017
return 0;
10041018
guard(rwsem_read)(&mixer->card->controls_rwsem);
1019+
if (mixer->card->shutdown)
1020+
return -ENODEV;
10051021
kctl = NULL;
10061022
if (!ptr->index)
10071023
kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);

0 commit comments

Comments
 (0)