* [PATCH] kernel/module.c: use scnprintf() instead of sprintf()
@ 2013-08-20 3:13 Chen Gang
2013-08-20 6:04 ` Rusty Russell
0 siblings, 1 reply; 3+ messages in thread
From: Chen Gang @ 2013-08-20 3:13 UTC (permalink / raw)
To: Rusty Russell; +Cc: linux-kernel@vger.kernel.org
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>
---
kernel/module.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/kernel/module.c b/kernel/module.c
index 2069158..0618e63 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -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) \
{ \
--
1.7.7.6
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] kernel/module.c: use scnprintf() instead of sprintf()
2013-08-20 3:13 [PATCH] kernel/module.c: use scnprintf() instead of sprintf() Chen Gang
@ 2013-08-20 6:04 ` Rusty Russell
2013-08-21 2:03 ` Chen Gang
0 siblings, 1 reply; 3+ messages in thread
From: Rusty Russell @ 2013-08-20 6:04 UTC (permalink / raw)
To: Chen Gang; +Cc: linux-kernel@vger.kernel.org
Chen Gang <gang.chen@asianux.com> writes:
> 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.
>
> Signed-off-by: Chen Gang <gang.chen@asianux.com>
> ---
> kernel/module.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/kernel/module.c b/kernel/module.c
> index 2069158..0618e63 100644
> --- a/kernel/module.c
> +++ b/kernel/module.c
> @@ -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) \
> { \
> --
> 1.7.7.6
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kernel/module.c: use scnprintf() instead of sprintf()
2013-08-20 6:04 ` Rusty Russell
@ 2013-08-21 2:03 ` Chen Gang
0 siblings, 0 replies; 3+ messages in thread
From: Chen Gang @ 2013-08-21 2:03 UTC (permalink / raw)
To: Rusty Russell; +Cc: linux-kernel@vger.kernel.org
On 08/20/2013 02:04 PM, Rusty Russell wrote:
> Chen Gang <gang.chen@asianux.com> writes:
>
>> 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.
> Thanks,
> Rusty.
>
>>
>> Signed-off-by: Chen Gang <gang.chen@asianux.com>
>> ---
>> kernel/module.c | 2 +-
>> 1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/kernel/module.c b/kernel/module.c
>> index 2069158..0618e63 100644
>> --- a/kernel/module.c
>> +++ b/kernel/module.c
>> @@ -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) \
>> { \
>> --
>> 1.7.7.6
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at http://www.tux.org/lkml/
>
>
--
Chen Gang
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-08-21 2:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-20 3:13 [PATCH] kernel/module.c: use scnprintf() instead of sprintf() Chen Gang
2013-08-20 6:04 ` Rusty Russell
2013-08-21 2:03 ` Chen Gang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox