mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] staging: greybus: audio: bound sscanf() string widths to NAME_SIZE
@ 2026-11-28 22:29 TAKANO Mitsuhiro via B4 Relay
  2026-11-29 19:10 ` TAKANO Mitsuhiro
  0 siblings, 1 reply; 2+ messages in thread
From: TAKANO Mitsuhiro via B4 Relay @ 2026-11-28 22:29 UTC (permalink / raw)
  To: Vaibhav Agarwal, Mark Greer, Johan Hovold, Alex Elder,
	Greg Kroah-Hartman
  Cc: greybus-dev, linux-staging, linux-kernel, TAKANO Mitsuhiro

From: TAKANO Mitsuhiro <takano32@gmail.com>

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@gmail.com>
---
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@gmail.com>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-29 19:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-28 22:29 [PATCH] staging: greybus: audio: bound sscanf() string widths to NAME_SIZE TAKANO Mitsuhiro via B4 Relay
2026-11-29 19:10 ` TAKANO Mitsuhiro

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®