[PATCH] staging: greybus: audio: bound sscanf() string widths to NAME_SIZE

From: TAKANO Mitsuhiro via B4 Relay

Date: Sat Nov 28 2026 - 17:29:24 EST


From: TAKANO Mitsuhiro <takano32@xxxxxxxxx>

In gbaudio_module_update() and find_gb_module(), sscanf() reads strings
using unbounded "%s" specifiers into stack buffers of size NAME_SIZE (32).
If the input string contains a token of 32 bytes or longer, sscanf()
overflows the stack buffer.

Limit the string conversion widths to 31 characters so they always fit
within NAME_SIZE including the terminating NUL byte.

Signed-off-by: TAKANO Mitsuhiro <takano32@xxxxxxxxx>
---
Verification: compile-tested on x86_64 with CONFIG_GREYBUS_AUDIO=m
(drivers/staging/greybus/audio_codec.o with W=1, 0 warnings;
drivers/staging/greybus/audio_topology.o default build, 0 warnings) and
checked with scripts/checkpatch.pl --strict. Checked against linux-next
(next-20261127) and lore.kernel.org for duplicates. Not runtime-tested on
Greybus hardware.

The change and the changelog text were produced with an AI coding
assistant (Gemini) working from the tree; I reviewed the diff and the
reasoning, and I am responsible for the submission.
---
drivers/staging/greybus/audio_codec.c | 2 +-
drivers/staging/greybus/audio_topology.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/greybus/audio_codec.c b/drivers/staging/greybus/audio_codec.c
index 9a4f6bca8..2b3d834bb 100644
--- a/drivers/staging/greybus/audio_codec.c
+++ b/drivers/staging/greybus/audio_codec.c
@@ -311,7 +311,7 @@ int gbaudio_module_update(struct gbaudio_codec_info *codec,
}

/* parse dai_id from AIF widget's stream_name */
- if (sscanf(w->sname, "%s %d %s", intf_name, &dai_id, dir) != 3) {
+ if (sscanf(w->sname, "%31s %d %31s", intf_name, &dai_id, dir) != 3) {
dev_err(codec->dev, "Error while parsing dai_id for %s\n", w->name);
return -EINVAL;
}
diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c
index 82d6339b2..a69e5e348 100644
--- a/drivers/staging/greybus/audio_topology.c
+++ b/drivers/staging/greybus/audio_topology.c
@@ -28,7 +28,7 @@ static struct gbaudio_module_info *find_gb_module(struct gbaudio_codec_info *cod
if (!name)
return NULL;

- if (sscanf(name, "%s %d", begin, &dev_id) != 2)
+ if (sscanf(name, "%31s %d", begin, &dev_id) != 2)
return NULL;

dev_dbg(codec->dev, "%s:Find module#%d\n", __func__, dev_id);

---
base-commit: f93eb7cfc4bfa5d46340f360873726e3e77f2365
change-id: 20261128-b4-greybus-audio-sscanf-bounds-3091c62b06d9

Best regards,
--
TAKANO Mitsuhiro <takano32@xxxxxxxxx>