[PATCH 1/2] ALSA: seq: oss: Fix data-race for max_midi_devs access
Gabriel Ryan
gabe at cs.columbia.edu
Tue Aug 23 15:50:21 CEST 2022
We have tested this patch and confirm it eliminates the race we observed on
max_mididev.
Best,
Gabe
On Tue, Aug 23, 2022 at 3:27 AM Takashi Iwai <tiwai at suse.de> wrote:
> ALSA OSS sequencer refers to a global variable max_midi_devs at
> creating a new port, storing it to its own field. Meanwhile this
> variable may be changed by other sequencer events at
> snd_seq_oss_midi_check_exit_port() in parallel, which may cause a data
> race.
>
> OTOH, this data race itself is almost harmless, as the access to the
> MIDI device is done via get_mdev() and it's protected with a refcount,
> hence its presence is guaranteed.
>
> Though, it's sill better to address the data-race from the code sanity
> POV, and this patch adds the proper spinlock for the protection.
>
> Reported-by: Abhishek Shah <abhishek.shah at columbia.edu>
> Cc: <stable at vger.kernel.org>
> Link:
> https://urldefense.proofpoint.com/v2/url?u=https-3A__lore.kernel.org_r_CAEHB2493pZRXs863w58QWnUTtv3HHfg85aYhLn5HJHCwxqtHQg-40mail.gmail.com&d=DwIDAg&c=009klHSCxuh5AI1vNQzSO0KGjl4nbi2Q0M1QLJX9BeE&r=EyAJYRJu01oaAhhVVY3o8zKgZvacDAXd_PNRtaqACCo&m=CxIkVQqIvngOHaCRT98C_jGfJo6SNC38iwxKsCn-3yU1vAYynFqC_nB4PAgPegMm&s=B8XPQtfIHmyV0Z-NAEtd5FG1Indh15kFF_yJWOMLnz4&e=
>
> Signed-off-by: Takashi Iwai <tiwai at suse.de>
> ---
> sound/core/seq/oss/seq_oss_midi.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/sound/core/seq/oss/seq_oss_midi.c
> b/sound/core/seq/oss/seq_oss_midi.c
> index 1e3bf086f867..07efb38f58ac 100644
> --- a/sound/core/seq/oss/seq_oss_midi.c
> +++ b/sound/core/seq/oss/seq_oss_midi.c
> @@ -270,7 +270,9 @@ snd_seq_oss_midi_clear_all(void)
> void
> snd_seq_oss_midi_setup(struct seq_oss_devinfo *dp)
> {
> + spin_lock_irq(®ister_lock);
> dp->max_mididev = max_midi_devs;
> + spin_unlock_irq(®ister_lock);
> }
>
> /*
> --
> 2.35.3
>
>
More information about the Alsa-devel
mailing list