Skip to contentSkip to conversation

dmaengine: avoid non-constant format string

PATCH Applied Arnd Bergmann 3 participants 3 messages Jul 19, 2024 – Aug 29, 2024 dmaengine

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmaengine: avoid non-constant format string

From: Arnd Bergmann <[email protected]>

Using an arbitrary string as a printf-style format can be a security problem if that string contains % characters, as the optionalal -Wformat-security flag points out:

drivers/dma/dmaengine.c: In function '__dma_async_device_channel_register':
drivers/dma/dmaengine.c:1073:17: error: format not a string literal and no format arguments [-Werror=format-security]

 1073 |                 dev_set_name(&chan->dev->device, name);
      |                 ^~~~~~~~~~~~

Change this newly added instance to use "%s" as the format instead to pass the actual name.

Fixes 10b8e0fd3f72 ("dmaengine: add channel device name to channel registration")
---
 drivers/dma/dmaengine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/dmaengine.c +1 -1
index c380a4dda77a..c1357d7f3dc6 100644
@@ -1070,7 +1070,7 @@ static int __dma_async_device_channel_register(struct dma_device *device,
 	if (!name)
 		dev_set_name(&chan->dev->device, "dma%dchan%d", device->dev_id, chan->chan_id);
 	else
-		dev_set_name(&chan->dev->device, name);
+		dev_set_name(&chan->dev->device, "%s", name);
 	rc = device_register(&chan->dev->device);
 	if (rc)
 		goto err_out_ida;
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Using an arbitrary string as a printf-style format can be a security problem if that string contains % characters, as the optionalal -Wformat-security flag points out:

drivers/dma/dmaengine.c: In function '__dma_async_device_channel_register':
drivers/dma/dmaengine.c:1073:17: error: format not a string literal and no format arguments [-Werror=format-security]

Quoted 8 lines
 1073 |                 dev_set_name(&chan->dev->device, name);
      |                 ^~~~~~~~~~~~

Change this newly added instance to use "%s" as the format instead to pass the actual name.

Fixes 10b8e0fd3f72 ("dmaengine: add channel device name to channel registration")
Quoted 17 lines
---
 drivers/dma/dmaengine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/dmaengine.c +1 -1
index c380a4dda77a..c1357d7f3dc6 100644
@@ -1070,7 +1070,7 @@ static int __dma_async_device_channel_register(struct dma_device *device,
 	if (!name)
 		dev_set_name(&chan->dev->device, "dma%dchan%d", device->dev_id, chan->chan_id);
 	else
-		dev_set_name(&chan->dev->device, name);
+		dev_set_name(&chan->dev->device, "%s", name);
 	rc = device_register(&chan->dev->device);
 	if (rc)
 		goto err_out_ida;
maintainer Applied
#2 lore raw
In reply to Arnd Bergmann
Quoted 10 lines · Arnd Bergmann

Using an arbitrary string as a printf-style format can be a security problem if that string contains % characters, as the optionalal -Wformat-security flag points out:

drivers/dma/dmaengine.c: In function '__dma_async_device_channel_register':
drivers/dma/dmaengine.c:1073:17: error: format not a string literal and no format arguments [-Werror=format-security]

 1073 |                 dev_set_name(&chan->dev->device, name);
      |                 ^~~~~~~~~~~~

[...]

Applied, thanks!

[1/1] dmaengine: avoid non-constant format string

      commit: ae04342b5264fcf90a288a984a69ffb9e93904a7

Best regards,

Signature · 1 line
~Vinod