* [PATCH] ALSA: hda: intel: Validate master count before creating link mask
@ 2026-12-05 14:31 Sreeraj S Kurup
2026-12-05 15:18 ` [PATCH v2] " Sreeraj S Kurup
0 siblings, 1 reply; 4+ messages in thread
From: Sreeraj S Kurup @ 2026-12-05 14:31 UTC (permalink / raw)
To: tiwai, perex; +Cc: linux-sound, linux-kernel, Sreeraj S Kurup
The driver uses GENMASK(count - 1, 0) to create the link
mask from the mipi-sdw-master-count ACPI property.
However, the count is checked only after GENMASK() is called.
If firmware reports a count of zero, the unsigned subtraction
count - 1 underflows. If the count exceeds
SDW_INTEL_MAX_LINKS, an invalid link mask may be generated.
Validate that the count is non-zero and does not exceed
SDW_INTEL_MAX_LINKS before creating the link mask.
Return -EINVAL if the count is invalid.
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
sound/hda/core/intel-sdw-acpi.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/sound/hda/core/intel-sdw-acpi.c b/sound/hda/core/intel-sdw-acpi.c
index d3511135f7d3..4d6bfc5e25de 100644
--- a/sound/hda/core/intel-sdw-acpi.c
+++ b/sound/hda/core/intel-sdw-acpi.c
@@ -90,6 +90,13 @@ sdw_intel_scan_controller(struct sdw_intel_acpi_info *info)
ret);
return ret;
}
+
+ /* Check count before constructing the link mask */
+ if (!count || count > SDW_INTEL_MAX_LINKS) {
+ dev_err(&adev->dev, "Invalid link count: %u\n",
+ count);
+ return -EINVAL;
+ }
list = GENMASK(count - 1, 0);
} else {
list = tmp;
--
2.55.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] ALSA: hda: intel: Validate master count before creating link mask
2026-12-05 14:31 [PATCH] ALSA: hda: intel: Validate master count before creating link mask Sreeraj S Kurup
@ 2026-12-05 15:18 ` Sreeraj S Kurup
2026-12-06 11:09 ` Takashi Iwai
0 siblings, 1 reply; 4+ messages in thread
From: Sreeraj S Kurup @ 2026-12-05 15:18 UTC (permalink / raw)
To: sreekuttan2156239, perex, tiwai; +Cc: linux-kernel, linux-sound
The driver uses GENMASK(count - 1, 0) to create the link
mask from the mipi-sdw-master-count ACPI property.
However, the link mask is created before validating the
master count. If firmware reports a count of zero, the
unsigned subtraction count - 1 underflows. If the count
exceeds SDW_INTEL_MAX_LINKS, an invalid link mask may
be generated.
Move link mask creation after the existing count checks
to ensure the count is valid before calling GENMASK().
Fixes: 71dce222d586 ("ALSA/hda: intel-sdw-acpi: add support for sdw-manager-list property read")
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
v2:
- Move GENMASK() after the existing master count validation.
- Avoid duplicate count checks and preserve existing error
handling.
- Add Fixes trailer.
sound/hda/core/intel-sdw-acpi.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/sound/hda/core/intel-sdw-acpi.c b/sound/hda/core/intel-sdw-acpi.c
index d3511135f7d3..c38e956d4643 100644
--- a/sound/hda/core/intel-sdw-acpi.c
+++ b/sound/hda/core/intel-sdw-acpi.c
@@ -62,6 +62,7 @@ sdw_intel_scan_controller(struct sdw_intel_acpi_info *info)
u32 count;
u32 tmp;
int ret;
+ bool use_master_count = false;
if (!adev)
return -EINVAL;
@@ -90,7 +91,8 @@ sdw_intel_scan_controller(struct sdw_intel_acpi_info *info)
ret);
return ret;
}
- list = GENMASK(count - 1, 0);
+ use_master_count = true;
+
} else {
list = tmp;
count = hweight32(list);
@@ -98,7 +100,7 @@ sdw_intel_scan_controller(struct sdw_intel_acpi_info *info)
/* Check count is within bounds */
if (count > SDW_INTEL_MAX_LINKS) {
- dev_err(&adev->dev, "Link count %d exceeds max %d\n",
+ dev_err(&adev->dev, "Link count %u exceeds max %d\n",
count, SDW_INTEL_MAX_LINKS);
return -EINVAL;
}
@@ -107,7 +109,11 @@ sdw_intel_scan_controller(struct sdw_intel_acpi_info *info)
dev_warn(&adev->dev, "No SoundWire links detected\n");
return -EINVAL;
}
- dev_dbg(&adev->dev, "ACPI reports %d SDW Link devices\n", count);
+
+ if (use_master_count)
+ list = GENMASK(count - 1, 0);
+
+ dev_dbg(&adev->dev, "ACPI reports %u SDW Link devices\n", count);
info->count = count;
info->link_mask = 0;
--
2.55.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ALSA: hda: intel: Validate master count before creating link mask
2026-12-05 15:18 ` [PATCH v2] " Sreeraj S Kurup
@ 2026-12-06 11:09 ` Takashi Iwai
2026-12-06 13:06 ` Sreeraj S Kurup
0 siblings, 1 reply; 4+ messages in thread
From: Takashi Iwai @ 2026-12-06 11:09 UTC (permalink / raw)
To: Sreeraj S Kurup; +Cc: perex, tiwai, linux-kernel, linux-sound
On Sat, 05 Dec 2026 16:18:40 +0100,
Sreeraj S Kurup wrote:
>
> The driver uses GENMASK(count - 1, 0) to create the link
> mask from the mipi-sdw-master-count ACPI property.
>
> However, the link mask is created before validating the
> master count. If firmware reports a count of zero, the
> unsigned subtraction count - 1 underflows. If the count
> exceeds SDW_INTEL_MAX_LINKS, an invalid link mask may
> be generated.
>
> Move link mask creation after the existing count checks
> to ensure the count is valid before calling GENMASK().
>
> Fixes: 71dce222d586 ("ALSA/hda: intel-sdw-acpi: add support for sdw-manager-list property read")
> Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
Applied to for-next branch. Thanks.
Takashi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ALSA: hda: intel: Validate master count before creating link mask
2026-12-06 11:09 ` Takashi Iwai
@ 2026-12-06 13:06 ` Sreeraj S Kurup
0 siblings, 0 replies; 4+ messages in thread
From: Sreeraj S Kurup @ 2026-12-06 13:06 UTC (permalink / raw)
To: tiwai; +Cc: linux-kernel, linux-sound, perex, sreekuttan2156239
Hi,
Thanks for applying the patch!
Best regards,
Sreeraj
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-06 13:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-05 14:31 [PATCH] ALSA: hda: intel: Validate master count before creating link mask Sreeraj S Kurup
2026-12-05 15:18 ` [PATCH v2] " Sreeraj S Kurup
2026-12-06 11:09 ` Takashi Iwai
2026-12-06 13:06 ` Sreeraj S Kurup
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®