Skip to contentSkip to conversation

mm/damon/sysfs-schemes: avoid Wformat-security warning

PATCH In review Arnd Bergmann 2 participants 3 messages Mar 10, 2025

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

PATCH 1/1 mm/damon/sysfs-schemes: avoid Wformat-security warning

From: Arnd Bergmann <[email protected]>

This warning is for potentially user-defined format strings:

mm/damon/sysfs-schemes.c:1664:4: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
1664 | name);

Change this to use "%s" as the format and the name as the argument.

Fixes 92bc039dd72e ("mm/damon/sysfs-schemes: let damon_sysfs_scheme_set_filters() be used for different named directories")
---
 mm/damon/sysfs-schemes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/damon/sysfs-schemes.c +1 -1
index 50e6907515e6..23ac98dd6451 100644
@@ -1661,7 +1661,7 @@ static int damon_sysfs_scheme_set_filters(struct damon_sysfs_scheme *scheme,
 		return -ENOMEM;
 	err = kobject_init_and_add(&filters->kobj,
 			&damon_sysfs_scheme_filters_ktype, &scheme->kobj,
-			name);
+			"%s", name);
 	if (err)
 		kobject_put(&filters->kobj);
 	else
Signature · 1 line
2.39.5
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · On Mon, 10 Mar 2025 14:51:37 +0100 Arnd Bergmann <[email protected]> wrote:

From: Arnd Bergmann <[email protected]>

This warning is for potentially user-defined format strings:

mm/damon/sysfs-schemes.c:1664:4: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
1664 | name);

Change this to use "%s" as the format and the name as the argument.

Thank you for this patch!

Quoted 3 lines
Fixes 92bc039dd72e ("mm/damon/sysfs-schemes: let damon_sysfs_scheme_set_filters() be used for different named directories")

Thanks,
SJ

Quoted 19 lines
---
 mm/damon/sysfs-schemes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/damon/sysfs-schemes.c +1 -1
index 50e6907515e6..23ac98dd6451 100644
@@ -1661,7 +1661,7 @@ static int damon_sysfs_scheme_set_filters(struct damon_sysfs_scheme *scheme,
 		return -ENOMEM;
 	err = kobject_init_and_add(&filters->kobj,
 			&damon_sysfs_scheme_filters_ktype, &scheme->kobj,
-			name);
+			"%s", name);
 	if (err)
 		kobject_put(&filters->kobj);
 	else
Signature · 1 line
2.39.5
maintainer
#2 lore raw
Quoted 4 lines · On Mon, 10 Mar 2025 09:17:58 -0700 SeongJae Park <[email protected]> wrote:
Quoted 2 lines · On Mon, 10 Mar 2025 14:51:37 +0100 Arnd Bergmann <[email protected]> wrote:

From: Arnd Bergmann <[email protected]>

Quoted 8 lines
Quoted 6 lines

This warning is for potentially user-defined format strings:

mm/damon/sysfs-schemes.c:1664:4: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
1664 | name);

Change this to use "%s" as the format and the name as the argument.

Thank you for this patch!

I also found there is another similar issue and sent another patch[1] for that. Thank you again for sharing the issue.

[1] https://lore.kernel.org/[email protected]

Thanks,
SJ

[...]