* [PATCH] arch: blackfin: kernel: sprintf(), need avoid NUL for '%s'
@ 2013-05-29 9:43 ` Chen Gang
0 siblings, 0 replies; 12+ messages in thread
From: Chen Gang @ 2013-05-29 9:43 UTC (permalink / raw)
To: Mike Frysinger, anton.vorontsov, Richard Kuo, jesper.nilsson
Cc: Andrew Morton, David Miller, uclinux-dist-devel, linux-kernel,
Linux-Arch
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 <gang.chen@asianux.com>
---
arch/blackfin/kernel/trace.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/arch/blackfin/kernel/trace.c b/arch/blackfin/kernel/trace.c
index c36efa0..11f98bb 100644
--- a/arch/blackfin/kernel/trace.c
+++ b/arch/blackfin/kernel/trace.c
@@ -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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH] arch: blackfin: kernel: sprintf(), need avoid NUL for '%s'
@ 2013-05-29 9:43 ` Chen Gang
0 siblings, 0 replies; 12+ messages in thread
From: Chen Gang @ 2013-05-29 9:43 UTC (permalink / raw)
To: Mike Frysinger, anton.vorontsov, Richard Kuo, jesper.nilsson
Cc: Andrew Morton, David Miller, uclinux-dist-devel, linux-kernel,
Linux-Arch
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 <gang.chen@asianux.com>
---
arch/blackfin/kernel/trace.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/arch/blackfin/kernel/trace.c b/arch/blackfin/kernel/trace.c
index c36efa0..11f98bb 100644
--- a/arch/blackfin/kernel/trace.c
+++ b/arch/blackfin/kernel/trace.c
@@ -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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH] arch: blackfin: kernel: memory overflow, 'namebuf' length need be more than 256
2013-05-29 9:43 ` Chen Gang
@ 2013-05-29 10:07 ` Chen Gang
-1 siblings, 0 replies; 12+ messages in thread
From: Chen Gang @ 2013-05-29 10:07 UTC (permalink / raw)
To: Mike Frysinger, anton.vorontsov, Richard Kuo, jesper.nilsson
Cc: Andrew Morton, David Miller, uclinux-dist-devel, linux-kernel,
Linux-Arch
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.
Signed-off-by: Chen Gang <gang.chen@asianux.com>
---
arch/blackfin/kernel/trace.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/blackfin/kernel/trace.c b/arch/blackfin/kernel/trace.c
index c36efa0..4fecd3e 100644
--- a/arch/blackfin/kernel/trace.c
+++ b/arch/blackfin/kernel/trace.c
@@ -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;
--
1.7.7.6
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH] arch: blackfin: kernel: memory overflow, 'namebuf' length need be more than 256
@ 2013-05-29 10:07 ` Chen Gang
0 siblings, 0 replies; 12+ messages in thread
From: Chen Gang @ 2013-05-29 10:07 UTC (permalink / raw)
To: Mike Frysinger, anton.vorontsov, Richard Kuo, jesper.nilsson
Cc: Andrew Morton, David Miller, uclinux-dist-devel, linux-kernel,
Linux-Arch
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.
Signed-off-by: Chen Gang <gang.chen@asianux.com>
---
arch/blackfin/kernel/trace.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/blackfin/kernel/trace.c b/arch/blackfin/kernel/trace.c
index c36efa0..4fecd3e 100644
--- a/arch/blackfin/kernel/trace.c
+++ b/arch/blackfin/kernel/trace.c
@@ -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;
--
1.7.7.6
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH] arch: blackfin: kernel: memory overflow, 'namebuf' length need be more than 256
2013-05-29 10:07 ` Chen Gang
@ 2013-05-29 11:30 ` Geert Uytterhoeven
-1 siblings, 0 replies; 12+ messages in thread
From: Geert Uytterhoeven @ 2013-05-29 11:30 UTC (permalink / raw)
To: Chen Gang
Cc: Mike Frysinger, Anton Vorontsov, Richard Kuo, Jesper Nilsson,
Andrew Morton, David Miller, uclinux-dist-devel, linux-kernel,
Linux-Arch
On Wed, May 29, 2013 at 12:07 PM, Chen Gang <gang.chen@asianux.com> wrote:
> 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.
>
>
> Signed-off-by: Chen Gang <gang.chen@asianux.com>
> ---
> arch/blackfin/kernel/trace.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/blackfin/kernel/trace.c b/arch/blackfin/kernel/trace.c
> index c36efa0..4fecd3e 100644
> --- a/arch/blackfin/kernel/trace.c
> +++ b/arch/blackfin/kernel/trace.c
> @@ -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];
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?
> struct irqaction *action;
> unsigned int i;
> unsigned long flags = 0;
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] arch: blackfin: kernel: memory overflow, 'namebuf' length need be more than 256
@ 2013-05-29 11:30 ` Geert Uytterhoeven
0 siblings, 0 replies; 12+ messages in thread
From: Geert Uytterhoeven @ 2013-05-29 11:30 UTC (permalink / raw)
To: Chen Gang
Cc: Mike Frysinger, Anton Vorontsov, Richard Kuo, Jesper Nilsson,
Andrew Morton, David Miller, uclinux-dist-devel, linux-kernel,
Linux-Arch
On Wed, May 29, 2013 at 12:07 PM, Chen Gang <gang.chen@asianux.com> wrote:
> 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.
>
>
> Signed-off-by: Chen Gang <gang.chen@asianux.com>
> ---
> arch/blackfin/kernel/trace.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/blackfin/kernel/trace.c b/arch/blackfin/kernel/trace.c
> index c36efa0..4fecd3e 100644
> --- a/arch/blackfin/kernel/trace.c
> +++ b/arch/blackfin/kernel/trace.c
> @@ -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];
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?
> struct irqaction *action;
> unsigned int i;
> unsigned long flags = 0;
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] arch: blackfin: kernel: memory overflow, 'namebuf' length need be more than 256
2013-05-29 11:30 ` Geert Uytterhoeven
@ 2013-05-29 12:06 ` Chen Gang
-1 siblings, 0 replies; 12+ messages in thread
From: Chen Gang @ 2013-05-29 12:06 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Chen Gang, Mike Frysinger, Anton Vorontsov, Richard Kuo,
Jesper Nilsson, Andrew Morton, David Miller, uclinux-dist-devel,
linux-kernel, Linux-Arch
On 05/29/2013 07:30 PM, Geert Uytterhoeven wrote:
>> 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.
>
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.
> 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.
--
Chen Gang
Asianux Corporation
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] arch: blackfin: kernel: memory overflow, 'namebuf' length need be more than 256
@ 2013-05-29 12:06 ` Chen Gang
0 siblings, 0 replies; 12+ messages in thread
From: Chen Gang @ 2013-05-29 12:06 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Chen Gang, Mike Frysinger, Anton Vorontsov, Richard Kuo,
Jesper Nilsson, Andrew Morton, David Miller, uclinux-dist-devel,
linux-kernel, Linux-Arch
On 05/29/2013 07:30 PM, Geert Uytterhoeven wrote:
>> 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.
>
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.
> 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.
--
Chen Gang
Asianux Corporation
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] arch: blackfin: kernel: sprintf(), need avoid NUL for '%s'
2013-05-29 9:43 ` Chen Gang
@ 2013-06-16 3:02 ` Mike Frysinger
-1 siblings, 0 replies; 12+ messages in thread
From: Mike Frysinger @ 2013-06-16 3:02 UTC (permalink / raw)
To: Chen Gang
Cc: anton.vorontsov, Richard Kuo, Jesper Nilsson, Andrew Morton,
David Miller, uclinux-dist-devel, linux-kernel, Linux-Arch
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
On Wed, May 29, 2013 at 5:43 AM, Chen Gang <gang.chen@asianux.com> wrote:
>
> 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 <gang.chen@asianux.com>
> ---
> arch/blackfin/kernel/trace.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/arch/blackfin/kernel/trace.c b/arch/blackfin/kernel/trace.c
> index c36efa0..11f98bb 100644
> --- a/arch/blackfin/kernel/trace.c
> +++ b/arch/blackfin/kernel/trace.c
> @@ -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 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] 12+ messages in thread
* Re: [PATCH] arch: blackfin: kernel: sprintf(), need avoid NUL for '%s'
@ 2013-06-16 3:02 ` Mike Frysinger
0 siblings, 0 replies; 12+ messages in thread
From: Mike Frysinger @ 2013-06-16 3:02 UTC (permalink / raw)
To: Chen Gang
Cc: anton.vorontsov, Richard Kuo, Jesper Nilsson, Andrew Morton,
David Miller, uclinux-dist-devel, linux-kernel, Linux-Arch
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
On Wed, May 29, 2013 at 5:43 AM, Chen Gang <gang.chen@asianux.com> wrote:
>
> 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 <gang.chen@asianux.com>
> ---
> arch/blackfin/kernel/trace.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/arch/blackfin/kernel/trace.c b/arch/blackfin/kernel/trace.c
> index c36efa0..11f98bb 100644
> --- a/arch/blackfin/kernel/trace.c
> +++ b/arch/blackfin/kernel/trace.c
> @@ -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 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] 12+ messages in thread
* Re: [PATCH] arch: blackfin: kernel: sprintf(), need avoid NUL for '%s'
2013-06-16 3:02 ` Mike Frysinger
@ 2013-06-17 1:13 ` Chen Gang
-1 siblings, 0 replies; 12+ messages in thread
From: Chen Gang @ 2013-06-17 1:13 UTC (permalink / raw)
To: Mike Frysinger
Cc: anton.vorontsov, Richard Kuo, Jesper Nilsson, Andrew Morton,
David Miller, uclinux-dist-devel, linux-kernel, Linux-Arch
On 06/16/2013 11:02 AM, Mike Frysinger wrote:
> 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.
--
Chen Gang
Asianux Corporation
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] arch: blackfin: kernel: sprintf(), need avoid NUL for '%s'
@ 2013-06-17 1:13 ` Chen Gang
0 siblings, 0 replies; 12+ messages in thread
From: Chen Gang @ 2013-06-17 1:13 UTC (permalink / raw)
To: Mike Frysinger
Cc: anton.vorontsov, Richard Kuo, Jesper Nilsson, Andrew Morton,
David Miller, uclinux-dist-devel, linux-kernel, Linux-Arch
On 06/16/2013 11:02 AM, Mike Frysinger wrote:
> 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.
--
Chen Gang
Asianux Corporation
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2013-06-17 1:14 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-29 9:43 [PATCH] arch: blackfin: kernel: sprintf(), need avoid NUL for '%s' Chen Gang
2013-05-29 9:43 ` Chen Gang
2013-05-29 10:07 ` [PATCH] arch: blackfin: kernel: memory overflow, 'namebuf' length need be more than 256 Chen Gang
2013-05-29 10:07 ` Chen Gang
2013-05-29 11:30 ` Geert Uytterhoeven
2013-05-29 11:30 ` Geert Uytterhoeven
2013-05-29 12:06 ` Chen Gang
2013-05-29 12:06 ` Chen Gang
2013-06-16 3:02 ` [PATCH] arch: blackfin: kernel: sprintf(), need avoid NUL for '%s' Mike Frysinger
2013-06-16 3:02 ` Mike Frysinger
2013-06-17 1:13 ` Chen Gang
2013-06-17 1:13 ` Chen Gang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.