[PATCH] ALSA: hda: Validate codec address before executing verb

From: Sreeraj S Kurup

Date: Sat Dec 05 2026 - 05:18:27 EST


snd_hdac_bus_exec_verb_unlocked() receives a codec address
that is later passed to the response handling operation.

An invalid codec address can lead to an out-of-bounds array
access in the response handling path.

Add a check using snd_BUG_ON() and return -EINVAL when the
address is greater than or equal to HDA_MAX_CODECS.

This protects verb execution from invalid addresses passed
by existing callers as well as future callers, including
paths that use custom get_response operations.

Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@xxxxxxxxx>
---
sound/hda/core/bus.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/sound/hda/core/bus.c b/sound/hda/core/bus.c
index 02462bd035e7..e37426d551ad 100644
--- a/sound/hda/core/bus.c
+++ b/sound/hda/core/bus.c
@@ -9,6 +9,7 @@
#include <linux/module.h>
#include <linux/export.h>
#include <sound/hdaudio.h>
+#include <sound/core.h>
#include "local.h"
#include "trace.h"

@@ -107,6 +108,9 @@ int snd_hdac_bus_exec_verb_unlocked(struct hdac_bus *bus, unsigned int addr,
unsigned int tmp;
int err;

+ if (snd_BUG_ON(addr >= HDA_MAX_CODECS))
+ return -EINVAL;
+
if (cmd == ~0)
return -EINVAL;

--
2.55.0