Skip to content

Commit cc56ded

Browse files
Chen Gangrustyrussell
authored andcommitted
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. Signed-off-by: Chen Gang <gang.chen@asianux.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 5265fc6 commit cc56ded

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎kernel/module.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ static void setup_modinfo_##field(struct module *mod, const char *s) \
604604
static ssize_t show_modinfo_##field(struct module_attribute *mattr, \
605605
struct module_kobject *mk, char *buffer) \
606606
{ \
607-
return sprintf(buffer, "%s\n", mk->mod->field); \
607+
return scnprintf(buffer, PAGE_SIZE, "%s\n", mk->mod->field); \
608608
} \
609609
static int modinfo_##field##_exists(struct module *mod) \
610610
{ \

0 commit comments

Comments
 (0)