Skip to content

Commit 084d5d4

Browse files
committed
ALSA: mixer: oss: Add card disconnect checkpoints
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/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent ac656d7 commit 084d5d4

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

sound/core/oss/mixer_oss.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,8 @@ static void snd_mixer_oss_get_volume1_vol(struct snd_mixer_oss_file *fmixer,
523523
if (numid == ID_UNKNOWN)
524524
return;
525525
guard(rwsem_read)(&card->controls_rwsem);
526+
if (card->shutdown)
527+
return;
526528
kctl = snd_ctl_find_numid(card, numid);
527529
if (!kctl)
528530
return;
@@ -557,6 +559,8 @@ static void snd_mixer_oss_get_volume1_sw(struct snd_mixer_oss_file *fmixer,
557559
if (numid == ID_UNKNOWN)
558560
return;
559561
guard(rwsem_read)(&card->controls_rwsem);
562+
if (card->shutdown)
563+
return;
560564
kctl = snd_ctl_find_numid(card, numid);
561565
if (!kctl)
562566
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;
@@ -656,6 +662,8 @@ static void snd_mixer_oss_put_volume1_sw(struct snd_mixer_oss_file *fmixer,
656662
if (numid == ID_UNKNOWN)
657663
return;
658664
guard(rwsem_read)(&card->controls_rwsem);
665+
if (card->shutdown)
666+
return;
659667
kctl = snd_ctl_find_numid(card, numid);
660668
if (!kctl)
661669
return;
@@ -796,6 +804,8 @@ static int snd_mixer_oss_get_recsrc2(struct snd_mixer_oss_file *fmixer, unsigned
796804
if (uinfo == NULL || uctl == NULL)
797805
return -ENOMEM;
798806
guard(rwsem_read)(&card->controls_rwsem);
807+
if (card->shutdown)
808+
return -ENODEV;
799809
kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
800810
if (!kctl)
801811
return -ENOENT;
@@ -839,6 +849,8 @@ static int snd_mixer_oss_put_recsrc2(struct snd_mixer_oss_file *fmixer, unsigned
839849
if (uinfo == NULL || uctl == NULL)
840850
return -ENOMEM;
841851
guard(rwsem_read)(&card->controls_rwsem);
852+
if (card->shutdown)
853+
return -ENODEV;
842854
kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
843855
if (!kctl)
844856
return -ENOENT;
@@ -885,6 +897,8 @@ static int snd_mixer_oss_build_test(struct snd_mixer_oss *mixer, struct slot *sl
885897
if (!info)
886898
return -ENOMEM;
887899
scoped_guard(rwsem_read, &card->controls_rwsem) {
900+
if (card->shutdown)
901+
return -ENODEV;
888902
kcontrol = snd_mixer_oss_test_id(mixer, name, index);
889903
if (kcontrol == NULL)
890904
return 0;
@@ -1006,6 +1020,8 @@ static int snd_mixer_oss_build_input(struct snd_mixer_oss *mixer,
10061020
if (snd_mixer_oss_build_test_all(mixer, ptr, &slot))
10071021
return 0;
10081022
guard(rwsem_read)(&mixer->card->controls_rwsem);
1023+
if (mixer->card->shutdown)
1024+
return -ENODEV;
10091025
kctl = NULL;
10101026
if (!ptr->index)
10111027
kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);

0 commit comments

Comments
 (0)