Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ALSA: hda: intel: Validate master count before creating link mask
@ 2026-12-05 14:31 Sreeraj S Kurup
  2026-12-05 14:46 ` sashiko-bot
  2026-12-05 15:18 ` [PATCH v2] " Sreeraj S Kurup
  0 siblings, 2 replies; 3+ 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 related	[flat|nested] 3+ messages in thread

* Re: [PATCH] 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 14:46 ` sashiko-bot
  2026-12-05 15:18 ` [PATCH v2] " Sreeraj S Kurup
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-05 14:46 UTC (permalink / raw)
  To: Sreeraj S Kurup; +Cc: linux-sound

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] ALSA: hda: intel: missing Fixes tag for commit 71dce222d586
- [Low] ALSA: hda: duplicate count validation in
  sdw_intel_scan_controller()
--

commit cfa6b3eb11ed3c7a1ef0fa0f46fa5c38d14757af
Author: Sreeraj S Kurup <sreekuttan2156239@gmail.com>

> ALSA: hda: intel: Validate master count before creating link mask
>
> 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>

[Severity: Low]
This fixes a bug introduced when GENMASK(count - 1, 0) was added ahead of
the existing count checks.  Should this include:

  Fixes: 71dce222d586 ("ALSA/hda: intel-sdw-acpi: add support for sdw-manager-list property read")

> diff --git a/sound/hda/core/intel-sdw-acpi.c b/sound/hda/core/intel-sdw-acpi.c
> index d3511135f7d39..4d6bfc5e25dec 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;

[Severity: Low]
Could GENMASK(count - 1, 0) be deferred past the existing count checks right
below the if/else block instead of duplicating them here?

Validating !count here with dev_err() escalates a zero mipi-sdw-master-count
from dev_warn() to an error, unlike mipi-sdw-manager-list, even though
callers like snd_intel_dsp_driver_probe() treat no SoundWire links as a
normal fallback.  The new message also drops SDW_INTEL_MAX_LINKS on overflow.

Initializing list = 0 and computing GENMASK(count - 1, 0) after the shared
checks avoids duplicating the validation and preserves the existing log
levels and messages.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205143113.2888-1-sreekuttan2156239@gmail.com?part=1

^ permalink raw reply	[flat|nested] 3+ 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 14:46 ` sashiko-bot
@ 2026-12-05 15:18 ` Sreeraj S Kurup
  1 sibling, 0 replies; 3+ 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 related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-05 15:19 UTC | newest]

Thread overview: 3+ 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 14:46 ` sashiko-bot
2026-12-05 15:18 ` [PATCH v2] " 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