Skip to contentSkip to conversation

kernel/module.c: use scnprintf() instead of sprintf()

PATCH Applied Chen Gang 2 participants 3 messages Aug 20, 2013 – Aug 21, 2013

lore
Share & tools
lore

Chen Gang

author
#0 lore raw

PATCH 1/1 kernel/module.c: use scnprintf() instead of sprintf()

For some strings, they are permitted to be larger than PAGE_SIZE, so need use scnprintf() instead of sprintf(), or it will cause issue.

One case is:

if a module version is crazy defined (length more than PAGE_SIZE), 'modinfo' command is still OK (print full contents),
but for "cat /sys/modules/'modname'/version", will cause issue in kernel.

---
 kernel/module.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/module.c +1 -1
index 2069158..0618e63 100644
@@ -603,7 +603,7 @@ static void setup_modinfo_##field(struct module *mod, const char *s)  \
 static ssize_t show_modinfo_##field(struct module_attribute *mattr,   \
 			struct module_kobject *mk, char *buffer)      \
 {                                                                     \
-	return sprintf(buffer, "%s\n", mk->mod->field);               \
+	return scnprintf(buffer, PAGE_SIZE, "%s\n", mk->mod->field);  \
 }                                                                     \
 static int modinfo_##field##_exists(struct module *mod)               \
 {                                                                     \
Signature · 1 line
1.7.7.6
#1 lore raw
Quoted 8 lines · Chen Gang

For some strings, they are permitted to be larger than PAGE_SIZE, so need use scnprintf() instead of sprintf(), or it will cause issue.

One case is:

if a module version is crazy defined (length more than PAGE_SIZE), 'modinfo' command is still OK (print full contents),
but for "cat /sys/modules/'modname'/version", will cause issue in kernel.

Applied!

Thanks,
Rusty.

Quoted 26 lines
---
 kernel/module.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/module.c +1 -1
index 2069158..0618e63 100644
@@ -603,7 +603,7 @@ static void setup_modinfo_##field(struct module *mod, const char *s)  \
 static ssize_t show_modinfo_##field(struct module_attribute *mattr,   \
 			struct module_kobject *mk, char *buffer)      \
 {                                                                     \
-	return sprintf(buffer, "%s\n", mk->mod->field);               \
+	return scnprintf(buffer, PAGE_SIZE, "%s\n", mk->mod->field);  \
 }                                                                     \
 static int modinfo_##field##_exists(struct module *mod)               \
 {                                                                     \
Signature · 6 lines
1.7.7.6
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
author
#2 lore raw
Quoted 5 lines · Rusty Russell
Quoted 3 lines · Chen Gang

For some strings, they are permitted to be larger than PAGE_SIZE, so need use scnprintf() instead of sprintf(), or it will cause issue.

Quoted 8 lines
Quoted 5 lines

One case is:

if a module version is crazy defined (length more than PAGE_SIZE), 'modinfo' command is still OK (print full contents),
but for "cat /sys/modules/'modname'/version", will cause issue in kernel.

Applied!

Thanks.

Quoted 31 lines

Thanks,
Rusty.

Quoted 26 lines
---
 kernel/module.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/module.c +1 -1
index 2069158..0618e63 100644
@@ -603,7 +603,7 @@ static void setup_modinfo_##field(struct module *mod, const char *s)  \
 static ssize_t show_modinfo_##field(struct module_attribute *mattr,   \
 			struct module_kobject *mk, char *buffer)      \
 {                                                                     \
-	return sprintf(buffer, "%s\n", mk->mod->field);               \
+	return scnprintf(buffer, PAGE_SIZE, "%s\n", mk->mod->field);  \
 }                                                                     \
 static int modinfo_##field##_exists(struct module *mod)               \
 {                                                                     \
Signature · 6 lines
1.7.7.6
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Signature · 1 line
Chen Gang