ALSA: hda/hdmi: clamp num_cvts against cvt_nids[] in hdmi_read_pin_conn
Subsystems (2)
PATCH 1/1 ALSA: hda/hdmi: clamp num_cvts against cvt_nids[] in hdmi_read_pin_conn
hdmi_add_cvt() stores each converter's NID into the fixed-size spec->cvt_nids[] array (used only by the Intel Haswell pin-connection fixup), but only when spec->num_cvts is still within ARRAY_SIZE(cvt_nids); the num_cvts counter itself is incremented unconditionally regardless of whether the store happened. A codec that reports more converters than cvt_nids[] can hold therefore ends up with num_cvts > ARRAY_SIZE(cvt_nids).
hdmi_read_pin_conn(), on the intel_hsw_fixup path, copies num_cvts elements from cvt_nids[] with memcpy(), so once num_cvts exceeds the array size this reads past cvt_nids[] and writes the resulting garbage NIDs into per_pin->mux_nids[].
Clamp the copy length to the actual size of cvt_nids[] instead of trusting num_cvts, which is also used unbounded as the size of the separate, dynamically-sized spec->cvts array and must not be truncated at the source.
--- sound/hda/codecs/hdmi/hdmi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
sound/hda/codecs/hdmi/hdmi.c +2 -1
@@ -983,7 +983,8 @@ static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)snd_hda_set_dev_select (codec, pin_nid, dev_id);if (spec->intel_hsw_fixup) { - conns = spec->num_cvts; +/* spec->cvt_nids[] only has ARRAY_SIZE(spec->cvt_nids) slots */ + conns =min_t (int, spec->num_cvts,ARRAY_SIZE (spec->cvt_nids));memcpy (per_pin->mux_nids, spec->cvt_nids,sizeof (hda_nid_t) * conns); }else {
Signature · 1 line
2.56.0
Takashi Iwai
AppliedQuoted 14 lines · Peter Ujfalusi
hdmi_add_cvt()stores each converter's NID into the fixed-size spec->cvt_nids[] array (used only by the Intel Haswell pin-connection fixup), but only whenspec->num_cvtsis still withinARRAY_SIZE(cvt_nids); thenum_cvtscounter itself is incremented unconditionally regardless of whether the store happened. A codec that reports more converters than cvt_nids[] can hold therefore ends up withnum_cvts>ARRAY_SIZE(cvt_nids).
hdmi_read_pin_conn(), on theintel_hsw_fixuppath, copiesnum_cvtselements from cvt_nids[] withmemcpy(), so oncenum_cvtsexceeds the array size this reads past cvt_nids[] and writes the resulting garbage NIDs into per_pin->mux_nids[].
Quoted 8 lines
Clamp the copy length to the actual size of cvt_nids[] instead of trusting
num_cvts, which is also used unbounded as the size of the separate, dynamically-sizedspec->cvtsarray and must not be truncated at the source.Fixes bce0d2a80e42 ("ALSA: hda - Allow unlimited pins and converters in patch_hdmi.c")Signed-off-by Peter Ujfalusi <[email protected]>
Applied to for-next branch. Thanks.
Takashi