[PATCH 3/8] ALSA: hda: Fix potential UAF for gating jack
From: Takashi Iwai
Date: Tue Oct 06 2026 - 09:44:09 EST
snd_hda_jack_set_gating_jack() assigns gated and gating variables from
the succeeding calls of snd_hda_jack_tbl_get(). This works normally,
but the second call might kick off the reallocation of the jack table,
hence the first pointer might become invalid, which leads to a UAF.
For avoiding that pitfall, this patch changes the code to two phases:
the first to only create two entries, and the second phase to get the
pointers from the table, so that no relocation can happen any longer.
Fixes: 0619ba8c17b1 ("ALSA: hda - Allow jack state to depend on another jack")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Signed-off-by: Takashi Iwai <tiwai@xxxxxxx>
---
sound/hda/common/jack.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/sound/hda/common/jack.c b/sound/hda/common/jack.c
index 1d6b0f0e6f27..c3efab3b5bfe 100644
--- a/sound/hda/common/jack.c
+++ b/sound/hda/common/jack.c
@@ -389,12 +389,15 @@ EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable);
int snd_hda_jack_set_gating_jack(struct hda_codec *codec, hda_nid_t gated_nid,
hda_nid_t gating_nid)
{
- struct hda_jack_tbl *gated = snd_hda_jack_tbl_new(codec, gated_nid, 0);
- struct hda_jack_tbl *gating =
- snd_hda_jack_tbl_new(codec, gating_nid, 0);
+ struct hda_jack_tbl *gated, *gating;
WARN_ON(codec->dp_mst);
+ if (!snd_hda_jack_tbl_new(codec, gated_nid, 0) ||
+ !snd_hda_jack_tbl_new(codec, gating_nid, 0))
+ return -ENOMEM;
+ gated = snd_hda_jack_tbl_get_mst(codec, gated_nid, 0);
+ gating = snd_hda_jack_tbl_get_mst(codec, gating_nid, 0);
if (!gated || !gating)
return -EINVAL;
--
2.55.0