Skip to contentSkip to conversation

staging: greybus: audio_codec: fix stack overflow in stream name parsing

PATCH In review Yudi Yang 2 participants 5 messages Sep 1 – Oct 1

Subsystems (4)
lore
Share & tools
lore

Yudi Yang

author
#0 lore raw

PATCH 1/1 staging: greybus: audio_codec: fix stack overflow in stream name parsing

intf_name and dir are 32-byte buffers. Parsing a module-provided AIF stream name with unbounded %s conversions can cause buffer-overwrites. Limit each conversion to 31 characters.

Fixes 60e7327d54b2 ("greybus: audio: Find data connection based on id")
---
 drivers/staging/greybus/audio_codec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/audio_codec.c +1 -1
index 6daa4e706792..c3fefe1414f9 100644
@@ -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;
 	}
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 10 lines · Yudi Yang

intf_name and dir are 32-byte buffers. Parsing a module-provided AIF stream name with unbounded %s conversions can cause buffer-overwrites. Limit each conversion to 31 characters.

Fixes 60e7327d54b2 ("greybus: audio: Find data connection based on id")
---
 drivers/staging/greybus/audio_codec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

How was this found and tested?

thanks,

greg k-h

author
#2 lore raw

I found this with an internal program-analysis tool that I cannot disclose yet, then manually verified the finding. intf_name and dir are 32-byte arrays, while the unbounded %s conversions allow tokens from w->sname longer than 31 characters to overflow them. Using %31s limits each conversion to 31 characters.

I do not have Greybus hardware, so testing was limited to building the affected object and running checkpatch.pl

Yudi

Quoted 18 lines · Greg KH
Quoted 10 lines · Yudi Yang

intf_name and dir are 32-byte buffers. Parsing a module-provided AIF stream name with unbounded %s conversions can cause buffer-overwrites. Limit each conversion to 31 characters.

Fixes 60e7327d54b2 ("greybus: audio: Find data connection based on id")
---
 drivers/staging/greybus/audio_codec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

How was this found and tested?

thanks,

greg k-h

maintainer
#3 lore raw
Quoted 5 lines · Yudi Yang

I found this with an internal program-analysis tool that I cannot disclose yet, then manually verified the finding. intf_name and dir are 32-byte arrays, while the unbounded %s conversions allow tokens from w->sname longer than 31 characters to overflow them. Using %31s limits each conversion to 31 characters.

Please read our documentation which describes how you need to identify when you use tools like this.

Quoted 2 lines

I do not have Greybus hardware, so testing was limited to building the affected object and running checkpatch.pl

That's not really testing the code :(

Please resubmit based on the documentation requirements.

thanks,

greg k-h

maintainer
#4 lore raw
In reply to Yudi Yang
Quoted 3 lines · Yudi Yang

intf_name and dir are 32-byte buffers. Parsing a module-provided AIF stream name with unbounded %s conversions can cause buffer-overwrites. Limit each conversion to 31 characters.

How was this issue found?

thanks,

greg k-h