Skip to content

Commit ce1558c

Browse files
kv2019itiwai
authored andcommitted
ALSA: hda/hdmi: fix incorrect locking in hdmi_pcm_close
A race exists between closing a PCM and update of ELD data. In hdmi_pcm_close(), hinfo->nid value is modified without taking spec->pcm_lock. If this happens concurrently while processing an ELD update in hdmi_pcm_setup_pin(), converter assignment may be done incorrectly. This bug was found by hitting a WARN_ON in snd_hda_spdif_ctls_assign() in a HDMI receiver connection stress test: [2739.684569] WARNING: CPU: 5 PID: 2090 at sound/pci/hda/patch_hdmi.c:1898 check_non_pcm_per_cvt+0x41/0x50 [snd_hda_codec_hdmi] ... [2739.684707] Call Trace: [2739.684720] update_eld+0x121/0x5a0 [snd_hda_codec_hdmi] [2739.684736] hdmi_present_sense+0x21e/0x3b0 [snd_hda_codec_hdmi] [2739.684750] check_presence_and_report+0x81/0xd0 [snd_hda_codec_hdmi] [2739.684842] intel_audio_codec_enable+0x122/0x190 [i915] Fixes: 42b2987 ("ALSA: hda - hdmi playback without monitor in dynamic pcm bind mode") Signed-off-by: Kai Vehmanen <[email protected]> Cc: <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent f401b2c commit ce1558c

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

sound/pci/hda/patch_hdmi.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,22 +2046,25 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
20462046
int pinctl;
20472047
int err = 0;
20482048

2049+
mutex_lock(&spec->pcm_lock);
20492050
if (hinfo->nid) {
20502051
pcm_idx = hinfo_to_pcm_index(codec, hinfo);
2051-
if (snd_BUG_ON(pcm_idx < 0))
2052-
return -EINVAL;
2052+
if (snd_BUG_ON(pcm_idx < 0)) {
2053+
err = -EINVAL;
2054+
goto unlock;
2055+
}
20532056
cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid);
2054-
if (snd_BUG_ON(cvt_idx < 0))
2055-
return -EINVAL;
2057+
if (snd_BUG_ON(cvt_idx < 0)) {
2058+
err = -EINVAL;
2059+
goto unlock;
2060+
}
20562061
per_cvt = get_cvt(spec, cvt_idx);
2057-
20582062
snd_BUG_ON(!per_cvt->assigned);
20592063
per_cvt->assigned = 0;
20602064
hinfo->nid = 0;
20612065

20622066
azx_stream(get_azx_dev(substream))->stripe = 0;
20632067

2064-
mutex_lock(&spec->pcm_lock);
20652068
snd_hda_spdif_ctls_unassign(codec, pcm_idx);
20662069
clear_bit(pcm_idx, &spec->pcm_in_use);
20672070
pin_idx = hinfo_to_pin_index(codec, hinfo);
@@ -2091,10 +2094,11 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
20912094
per_pin->setup = false;
20922095
per_pin->channels = 0;
20932096
mutex_unlock(&per_pin->lock);
2094-
unlock:
2095-
mutex_unlock(&spec->pcm_lock);
20962097
}
20972098

2099+
unlock:
2100+
mutex_unlock(&spec->pcm_lock);
2101+
20982102
return err;
20992103
}
21002104

0 commit comments

Comments
 (0)