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 4/4] ASoC: Intel: bytcr_wm5102: Avoid OOB array read from the map name
Date: Tue, 15 Apr 2025 10:31:40 +0200 [thread overview]
Message-ID: <20250415083144.6588-5-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: c556d202bef1 ("ASoC: Intel: bytcr_wm5102: Add BYT_WM5102_OUT_MAP quirk")
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/soc/intel/boards/bytcr_wm5102.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/sound/soc/intel/boards/bytcr_wm5102.c b/sound/soc/intel/boards/bytcr_wm5102.c
index a6dfbcfdf74e..15a7302a1753 100644
--- a/sound/soc/intel/boards/bytcr_wm5102.c
+++ b/sound/soc/intel/boards/bytcr_wm5102.c
@@ -514,11 +514,26 @@ static struct snd_soc_card byt_wm5102_card = {
static char byt_wm5102_components[64]; /* = "cfg-spk:* cfg-int-mic:* cfg-hs-mic:* ..." */
+static const char *out_map_name(int n)
+{
+ static const char * const map_names[] = { "spk", "hpout2" };
+ return n < ARRAY_SIZE(map_names) ? map_names[n] : "none";
+}
+
+static const char *intmic_map_name(int n)
+{
+ static const char * const map_names[] = { "in3l", "in1l" };
+ return n < ARRAY_SIZE(map_names) ? map_names[n] : "none";
+}
+
+static const char *hsmic_map_name(int n)
+{
+ static const char * const map_names[] = { "in1l", "in2l" };
+ return n < ARRAY_SIZE(map_names) ? map_names[n] : "none";
+}
+
static int snd_byt_wm5102_mc_probe(struct platform_device *pdev)
{
- static const char * const out_map_name[] = { "spk", "hpout2" };
- static const char * const intmic_map_name[] = { "in3l", "in1l" };
- static const char * const hsmic_map_name[] = { "in1l", "in2l" };
char codec_name[SND_ACPI_I2C_ID_LEN];
struct device *dev = &pdev->dev;
struct byt_wm5102_private *priv;
@@ -594,9 +609,9 @@ static int snd_byt_wm5102_mc_probe(struct platform_device *pdev)
snprintf(byt_wm5102_components, sizeof(byt_wm5102_components),
"cfg-spk:%s cfg-intmic:%s cfg-hsmic:%s",
- out_map_name[FIELD_GET(BYT_WM5102_OUT_MAP, quirk)],
- intmic_map_name[FIELD_GET(BYT_WM5102_IN_MAP, quirk)],
- hsmic_map_name[FIELD_GET(BYT_WM5102_IN_MAP, quirk)]);
+ out_map_name(FIELD_GET(BYT_WM5102_OUT_MAP, quirk)),
+ intmic_map_name(FIELD_GET(BYT_WM5102_IN_MAP, quirk)),
+ hsmic_map_name(FIELD_GET(BYT_WM5102_IN_MAP, quirk)));
byt_wm5102_card.components = byt_wm5102_components;
/* find index of codec dai */
--
2.49.0
next prev parent reply other threads:[~2025-04-15 8:32 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 ` [PATCH 1/4] ASoC: Intel: bytcht_es8316: " Takashi Iwai
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 ` Takashi Iwai [this message]
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-5-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.