arch: blackfin: kernel: sprintf(), need avoid NUL for '%s'
PATCH 1/1 arch: blackfin: kernel: sprintf(), need avoid NUL for '%s'
When it is kernel symbol, the 'modname' will be NUL, and the 'symname' contents the valid name.
So for sprintf(), need avoid NUL for '%s'.
--- arch/blackfin/kernel/trace.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/blackfin/kernel/trace.c +1 -1
@@ -51,7 +51,7 @@ void decode_address(char *buf, unsigned long address)if (!modname) modname = delim ="" ;sprintf (buf,"{ %s%s%s%s + 0x%lx }" , - delim, modname, delim, symname, + delim, modname ? :"kernel" , delim, symname, (unsigned long )offset);return ; }
Signature · 1 line
1.7.7.6
PATCH 1/1 arch: blackfin: kernel: memory overflow, 'namebuf' length need be more than 256
The 'name' length in decode_address() may be 255, after call d_path() successfully.
So for decode_address(), the input 'buf' need be more than 256, or may memory overflow.
For simply thinking of, use 'namebuf[512]' instead of 'namebuf[150]' which will pass to decode_address() as input 'buf'.
Also better use macro instead of hard code number when processing symbols work.
--- arch/blackfin/kernel/trace.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
arch/blackfin/kernel/trace.c +2 -2
@@ -37,7 +37,7 @@ void decode_address(char *buf, unsigned long address)const char *symname;char *modname;char *delim =":" ; -char namebuf[128 ]; +char namebuf[KSYM_NAME_LEN ];#endif buf +=sprintf (buf,"<0x%08lx> " , address);
@@ -845,7 +845,7 @@ void dump_bfin_mem(struct pt_regs *fp)void show_regs (struct pt_regs *fp) { -char buf[150 ]; +char buf[512 ];struct irqaction *action;unsigned int i;unsigned long flags =0 ;
Signature · 1 line
1.7.7.6
Re: [PATCH] arch: blackfin: kernel: memory overflow, 'namebuf' length need be more than 256
Quoted 32 lines · Chen Gang
The 'name' length in
decode_address()may be 255, after calld_path()successfully.So for
decode_address(), the input 'buf' need be more than 256, or may memory overflow.For simply thinking of, use 'namebuf[512]' instead of 'namebuf[150]' which will pass to
decode_address()as input 'buf'.Also better use macro instead of hard code number when processing symbols work.
Signed-off-by Chen Gang <[email protected]>--- arch/blackfin/kernel/trace.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)arch/blackfin/kernel/trace.c +1
-1@@ -37,7 +37,7 @@ void decode_address(char *buf, unsigned long address)const char *symname;char *modname;char *delim =":" ; -char namebuf[128 ]; +char namebuf[KSYM_NAME_LEN ];#endif buf +=sprintf (buf,"<0x%08lx> " , address);
arch/blackfin/kernel/trace.c void dump_bfin_mem(struct pt_regs *fp) · line 848
Quoted 5 lines
arch/blackfin/kernel/trace.c +1
-1@@ -845,7 +845,7 @@ void dump_bfin_mem(struct pt_regs *fp)void show_regs (struct pt_regs *fp) { -char buf[150 ]; +char buf[512 ];
This will increase stack usage a lot. And this function calls decode_address(), which allocates another buffer on the stack.
However, as this is in debug code which is (never?) called concurrently, both buffers can be made static?
arch/blackfin/kernel/trace.c void dump_bfin_mem(struct pt_regs *fp) · line 851
Quoted 3 lines
arch/blackfin/kernel/trace.c +0
-0struct irqaction *action;unsigned int i;unsigned long flags =0 ;
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Re: [PATCH] arch: blackfin: kernel: memory overflow, 'namebuf' length need be more than 256
Quoted 7 lines · Geert Uytterhoeven
Quoted 4 lines
void
show_regs(struct pt_regs *fp)Quoted 3 lines
{
arch/blackfin/kernel/trace.c +1
-1-char buf[150 ]; +char buf[512 ];This will increase stack usage a lot. And this function calls
decode_address(), which allocates another buffer on the stack.
Can it have a risk to cause the related stack used up ? (excuse me, I don't know the system or thread stack size of blackfin).
If so, we really need save some byes (e.g. buf[300] ...), at least. But I'm not sure whether it still has the risk too.
Quoted 3 lines
However, as this is in debug code which is (never?) called concurrently, both buffers can be made static?
trap_c() may call show_regs(), and can multiple traps occur at the same time ?
It seems it can (but I am not quite sure): for trap_c() only use stack variables, and "cpu = raw_smp_processor_id()".
Thanks.
Signature · 3 lines
Chen Gang Asianux Corporation
i think you mean NULL instead of NUL
that said, the kernel is smart enough to replace NULL with "(null)", so i don't see much point in this patch
-mike
Quoted 32 lines · Chen Gang
When it is kernel symbol, the 'modname' will be NUL, and the 'symname' contents the valid name.
So for
sprintf(), need avoid NUL for '%s'.Signed-off-by Chen Gang <[email protected]>--- arch/blackfin/kernel/trace.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)arch/blackfin/kernel/trace.c +1
-2@@ -51,7 +51,7 @@ void decode_address(char *buf, unsigned long address)if (!modname) modname = delim ="" ;sprintf (buf,"{ %s%s%s%s + 0x%lx }" , - delim, modname, delim, symname, + delim, modname ? :"kernel" , delim, symname, (unsigned long )offset);return ; } --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/
Quoted 4 lines · Mike Frysinger
i think you mean NULL instead of NUL
that said, the kernel is smart enough to replace NULL with "(null)", so i don't see much point in this patch
Oh, really it is, it is my fault (originally, I did not know about it).
Thanks.
Signature · 3 lines
Chen Gang Asianux Corporation