Skip to contentSkip to conversation

bdi: fix -Wformat-security

PATCH In review Nick Desaulniers 2 participants 2 messages Oct 23, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bdi: fix -Wformat-security

mm/backing-dev.c:810:57: warning: format string is not a string literal (potentially insecure) [-Wformat-security]

dev = device_create(bdi_class, NULL, MKDEV(0, 0), bdi, bdi->dev_name);
                                                       ^~~~~~~~~~~~~

---
Example patch showing off kernel development from a newly created twitch stream! Check it out at: https://twitch.tv/ndesaulniers.

 mm/backing-dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/backing-dev.c +1 -1
index 408d5051d05b..5755578d671d 100644
@@ -807,7 +807,7 @@ int bdi_register_va(struct backing_dev_info *bdi, const char *fmt, va_list args)
 		return 0;
 
 	vsnprintf(bdi->dev_name, sizeof(bdi->dev_name), fmt, args);
-	dev = device_create(bdi_class, NULL, MKDEV(0, 0), bdi, bdi->dev_name);
+	dev = device_create(bdi_class, NULL, MKDEV(0, 0), bdi, "%s", bdi->dev_name);
 	if (IS_ERR(dev))
 		return PTR_ERR(dev);
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 3 lines · Nick Desaulniers

mm/backing-dev.c:810:57: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
dev = device_create(bdi_class, NULL, MKDEV(0, 0), bdi, bdi->dev_name);

The callers never pass format strings here. That being said the fix is probably ok anyway, modulo the obvious style issue.

mm/backing-dev.c int bdi_register_va(struct backing_dev_info *bdi, const char *fmt, va_list args) · line 810

Quoted 10 lines
mm/backing-dev.c +1 -1
index 408d5051d05b..5755578d671d 100644
@@ -807,7 +807,7 @@ int bdi_register_va(struct backing_dev_info *bdi, const char *fmt, va_list args)
 		return 0;
 
 	vsnprintf(bdi->dev_name, sizeof(bdi->dev_name), fmt, args);
-	dev = device_create(bdi_class, NULL, MKDEV(0, 0), bdi, bdi->dev_name);
+	dev = device_create(bdi_class, NULL, MKDEV(0, 0), bdi, "%s", bdi->dev_name);

Please don't introduce any over 80 char lines.