linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bdi: fix -Wformat-security
@ 2020-10-23  6:57 Nick Desaulniers
  2020-10-23  7:15 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Nick Desaulniers @ 2020-10-23  6:57 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Christoph Hellwig, Nick Desaulniers, linux-mm, linux-kernel

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);
                                                       ^~~~~~~~~~~~~

Signed-off-by: Nick Desaulniers <nick.desaulniers@gmail.com>
---
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(-)

diff --git a/mm/backing-dev.c b/mm/backing-dev.c
index 408d5051d05b..5755578d671d 100644
--- a/mm/backing-dev.c
+++ b/mm/backing-dev.c
@@ -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);
 
-- 
2.25.1



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

* Re: [PATCH] bdi: fix -Wformat-security
  2020-10-23  6:57 [PATCH] bdi: fix -Wformat-security Nick Desaulniers
@ 2020-10-23  7:15 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2020-10-23  7:15 UTC (permalink / raw)
  To: Nick Desaulniers; +Cc: Andrew Morton, Christoph Hellwig, linux-mm, linux-kernel

On Thu, Oct 22, 2020 at 11:57:54PM -0700, Nick Desaulniers wrote:
> 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.

> diff --git a/mm/backing-dev.c b/mm/backing-dev.c
> index 408d5051d05b..5755578d671d 100644
> --- a/mm/backing-dev.c
> +++ b/mm/backing-dev.c
> @@ -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.


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

end of thread, other threads:[~2020-10-23  7:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-23  6:57 [PATCH] bdi: fix -Wformat-security Nick Desaulniers
2020-10-23  7:15 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).