kernel/cpu: fix: use scnprintf or sprintf.
PATCH 1/1 kernel/cpu: fix: use scnprintf or sprintf.
The snprintf() function returns the number of characters which would have been printed if there were enough space, but the scnprintf() returns the number of characters which were actually printed. If the buffer is not large enough, then using snprintf() would result in a read overflow and an information leak.
--- kernel/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/cpu.c +1 -1
@@ -2345,7 +2345,7 @@ static ssize_t show_cpuhp_states(struct device *dev, {const char *state = smt_states[cpu_smt_control]; -return snprintf (buf,PAGE_SIZE -2 ,"%s\n" , state); +return scnprintf (buf,PAGE_SIZE -2 ,"%s\n" , state); } static ssize_t
Signature · 1 line
1.8.3.1
Hi Yang
'or sprintf' in the subject line doesn't make much sense for what's done in this patch. Perhaps you meant "Use scnprintf instead of snprintf"?
Quoted 8 lines · YANG LI
The
snprintf()function returns the number of characters which would have been printed if there were enough space, but thescnprintf()returns the number of characters which were actually printed. If the buffer is not large enough, then usingsnprintf()would result in a read overflow and an information leak.Signed-off-by YANG LI <[email protected]>Reported-by Abaci <[email protected]>
Two different yet very similar email addresses, it seems both are you? The Reported-by is unnecessary.
Quoted 9 lines
--- kernel/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/cpu.c +0
-0
kernel/cpu.c static ssize_t show_cpuhp_states(struct device *dev, · line 2348
Quoted 5 lines
kernel/cpu.c +1
-1@@ -2345,7 +2345,7 @@ static ssize_t show_cpuhp_states(struct device *dev, {const char *state = smt_states[cpu_smt_control]; -return snprintf (buf,PAGE_SIZE -2 ,"%s\n" , state); +return scnprintf (buf,PAGE_SIZE -2 ,"%s\n" , state);
show_cpuhp_states() doesn't have snprintf() in Linus' master. Which tree is this based on?
I can see two snprintf() in cpu.c, show_smt_active/control().
Mind resend to fix them both?
Thanks
--
Qais Yousef