Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Mark Brown <broonie@kernel.org>
Cc: Hans de Goede <hdegoede@redhat.com>, linux-sound@vger.kernel.org
Subject: [PATCH 1/4] ASoC: Intel: bytcht_es8316: Avoid OOB array read from the map name
Date: Tue, 15 Apr 2025 10:31:37 +0200	[thread overview]
Message-ID: <20250415083144.6588-2-tiwai@suse.de> (raw)
In-Reply-To: <20250415083144.6588-1-tiwai@suse.de>

Since the quirk bits can be passed arbitrarily via a module option, it
may lead to the OOB access over the map name string array.
Fix it by conditionally reading the array, instead.

Fixes: 249d2fc9e55c ("ASoC: Intel: bytcht_es8316: Set card long_name based on quirks")
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/soc/intel/boards/bytcht_es8316.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/sound/soc/intel/boards/bytcht_es8316.c b/sound/soc/intel/boards/bytcht_es8316.c
index 62594e7966ab..808142250ca1 100644
--- a/sound/soc/intel/boards/bytcht_es8316.c
+++ b/sound/soc/intel/boards/bytcht_es8316.c
@@ -518,10 +518,15 @@ static int byt_cht_es8316_get_quirks_from_dsm(struct byt_cht_es8316_private *pri
 	return 0;
 }
 
+static const char *mic_name(int n)
+{
+	static const char * const mic_names[] = { "in1", "in2" };
+	return n < ARRAY_SIZE(mic_names) ? mic_names[n] : "none";
+}
+
 static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	static const char * const mic_name[] = { "in1", "in2" };
 	struct snd_soc_acpi_mach *mach = dev_get_platdata(dev);
 	struct property_entry props[MAX_NO_PROPS] = {};
 	struct byt_cht_es8316_private *priv;
@@ -648,12 +653,12 @@ static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)
 	snprintf(components_string, sizeof(components_string),
 		 "cfg-spk:%s cfg-mic:%s",
 		 (quirk & BYT_CHT_ES8316_MONO_SPEAKER) ? "1" : "2",
-		 mic_name[BYT_CHT_ES8316_MAP(quirk)]);
+		 mic_name(BYT_CHT_ES8316_MAP(quirk)));
 	byt_cht_es8316_card.components = components_string;
 #if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
 	snprintf(long_name, sizeof(long_name), "bytcht-es8316-%s-spk-%s-mic",
 		 (quirk & BYT_CHT_ES8316_MONO_SPEAKER) ? "mono" : "stereo",
-		 mic_name[BYT_CHT_ES8316_MAP(quirk)]);
+		 mic_name(BYT_CHT_ES8316_MAP(quirk)));
 	byt_cht_es8316_card.long_name = long_name;
 #endif
 
-- 
2.49.0


  reply	other threads:[~2025-04-15  8:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-15  8:31 [PATCH 0/4] ASoC: Intel: byt*: Avoid OOB array read from the map name Takashi Iwai
2025-04-15  8:31 ` Takashi Iwai [this message]
2025-04-15  8:31 ` [PATCH 2/4] ASoC: Intel: bytcr_rt5640: " Takashi Iwai
2025-04-15  8:31 ` [PATCH 3/4] ASoC: Intel: bytcr_rt5651: " Takashi Iwai
2025-04-15  8:31 ` [PATCH 4/4] ASoC: Intel: bytcr_wm5102: " Takashi Iwai
2025-04-15  9:12 ` [PATCH 0/4] ASoC: Intel: byt*: " Hans de Goede
2025-04-23 11:47   ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250415083144.6588-2-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=broonie@kernel.org \
    --cc=hdegoede@redhat.com \
    --cc=linux-sound@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox