[lvc-project] [PATCH] ALSA: hda/via: Protection against accessing an array by a

Artemii Karasev karasev at ispras.ru
Fri Jan 13 19:35:54 MSK 2023


snd_hda_get_connections() can return a value less than zero.
In some cases, this may lead to accessing cons[] at a negative
index.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Artemii Karasev <karasev at ispras.ru>
Fixes: 6e969d9155a4 ("ALSA: hda - Set line-out pin-ctls properly when indep-HP mode changes")
---
 sound/pci/hda/patch_via.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index aea7fae2ca4b..730206db0f6d 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -819,6 +819,10 @@ static int add_secret_dac_path(struct hda_codec *codec)
 		return 0;
 	nums = snd_hda_get_connections(codec, spec->gen.mixer_nid, conn,
 				       ARRAY_SIZE(conn) - 1);
+
+	if (nums < 0)
+		return nums;
+
 	for (i = 0; i < nums; i++) {
 		if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
 			return 0;
-- 
2.25.1




More information about the lvc-project mailing list