Re: [PATCH v2 7/9] lib/vsprintf: Replace space with '_' before crng is ready
On Fri 2018-02-16 23:07:09, Andy Shevchenko wrote: > From: Shunyong Yang> > Before crng is ready, output of "%p" composes of "(ptrval)" and > left padding spaces for alignment as no random address can be > generated. This seems a little strange when default string width > is larger than strlen("(ptrval)"). > > For example, when irq domain names are built with "%p", the nodes > under /sys/kernel/debug/irq/domains like this on AArch64 system, > > [root@y irq]# ls domains/ > default irqchip@(ptrval)-2 > irqchip@(ptrval)-4 \_SB_.TCS0.QIC1 \_SB_.TCS0.QIC3 > irqchip@(ptrval) irqchip@(ptrval)-3 > \_SB_.TCS0.QIC0 \_SB_.TCS0.QIC2 > > The name "irqchip@(ptrval)-2" is not so readable in console > output. > > This patch replaces space with readable "_" when output needs padding. > Following is the output after applying the patch, > > [root@y domains]# ls > default irqchip@(ptrval)-2 > irqchip@(ptrval)-4 \_SB_.TCS0.QIC1 \_SB_.TCS0.QIC3 > irqchip@(ptrval) irqchip@(ptrval)-3 \_SB_.TCS0.QIC0 > \_SB_.TCS0.QIC2 > > There is same problem in some subsystem's dmesg output. Moreover, > someone may call "%p" in a similar case. In addition, the timing of > crng initialization done may vary on different system. So, the change > is made in vsprintf.c. > > Cc: Joey Zheng > Suggested-by: Rasmus Villemoes > Signed-off-by: Shunyong Yang > Signed-off-by: Andy Shevchenko Reviewed-by: Petr Mladek I have pushed it into printk.git, branch for-4.18-vsprintf-cleanup. Best Regards, Petr
Re: [PATCH v2 7/9] lib/vsprintf: Replace space with '_' before crng is ready
On Fri 2018-02-16 23:07:09, Andy Shevchenko wrote: > From: Shunyong Yang > > Before crng is ready, output of "%p" composes of "(ptrval)" and > left padding spaces for alignment as no random address can be > generated. This seems a little strange when default string width > is larger than strlen("(ptrval)"). > > For example, when irq domain names are built with "%p", the nodes > under /sys/kernel/debug/irq/domains like this on AArch64 system, > > [root@y irq]# ls domains/ > default irqchip@(ptrval)-2 > irqchip@(ptrval)-4 \_SB_.TCS0.QIC1 \_SB_.TCS0.QIC3 > irqchip@(ptrval) irqchip@(ptrval)-3 > \_SB_.TCS0.QIC0 \_SB_.TCS0.QIC2 > > The name "irqchip@(ptrval)-2" is not so readable in console > output. > > This patch replaces space with readable "_" when output needs padding. > Following is the output after applying the patch, > > [root@y domains]# ls > default irqchip@(ptrval)-2 > irqchip@(ptrval)-4 \_SB_.TCS0.QIC1 \_SB_.TCS0.QIC3 > irqchip@(ptrval) irqchip@(ptrval)-3 \_SB_.TCS0.QIC0 > \_SB_.TCS0.QIC2 > > There is same problem in some subsystem's dmesg output. Moreover, > someone may call "%p" in a similar case. In addition, the timing of > crng initialization done may vary on different system. So, the change > is made in vsprintf.c. > > Cc: Joey Zheng > Suggested-by: Rasmus Villemoes > Signed-off-by: Shunyong Yang > Signed-off-by: Andy Shevchenko Reviewed-by: Petr Mladek I have pushed it into printk.git, branch for-4.18-vsprintf-cleanup. Best Regards, Petr
Re: [此邮件可能存在风险] [PATCH v2 7/9] lib/vsprintf: Replace space with '_' before crng is ready
Hi, Andy, Many thanks for the change. I am on Chinese New Year travel and slow response. :-) Thanks. Shunyong. On Fri, 2018-02-16 at 23:07 +0200, Andy Shevchenko wrote: > From: Shunyong Yang> > Before crng is ready, output of "%p" composes of "(ptrval)" and > left padding spaces for alignment as no random address can be > generated. This seems a little strange when default string width > is larger than strlen("(ptrval)"). > > For example, when irq domain names are built with "%p", the nodes > under /sys/kernel/debug/irq/domains like this on AArch64 system, > > [root@y irq]# ls domains/ > default irqchip@(ptrval)-2 > irqchip@(ptrval)-4 \_SB_.TCS0.QIC1 \_SB_.TCS0.QIC3 > irqchip@(ptrval) irqchip@(ptrval)-3 > \_SB_.TCS0.QIC0 \_SB_.TCS0.QIC2 > > The name "irqchip@(ptrval)-2" is not so readable in console > output. > > This patch replaces space with readable "_" when output needs > padding. > Following is the output after applying the patch, > > [root@y domains]# ls > default irqchip@(ptrval)-2 > irqchip@(ptrval)-4 \_SB_.TCS0.QIC1 \_SB_.TCS0.QIC3 > irqchip@(ptrval) irqchip@(ptrval)-3 \_SB_.TCS0.QIC0 > \_SB_.TCS0.QIC2 > > There is same problem in some subsystem's dmesg output. Moreover, > someone may call "%p" in a similar case. In addition, the timing of > crng initialization done may vary on different system. So, the change > is made in vsprintf.c. > > Cc: Joey Zheng > Suggested-by: Rasmus Villemoes > Signed-off-by: Shunyong Yang > Signed-off-by: Andy Shevchenko > --- > lib/vsprintf.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index 9004bbb3d84d..97be2d07297a 100644 > --- a/lib/vsprintf.c > +++ b/lib/vsprintf.c > @@ -1681,12 +1681,13 @@ early_initcall(initialize_ptr_random); > /* Maps a pointer to a 32 bit unique identifier. */ > static char *ptr_to_id(char *buf, char *end, void *ptr, struct > printf_spec spec) > { > + const char *str = sizeof(ptr) == 8 ? "(ptrval)" : > "(ptrval)"; > unsigned long hashval; > > if (unlikely(!have_filled_random_ptr_key)) { > spec.field_width = 2 * sizeof(ptr); > /* string length must be less than default_width */ > - return string(buf, end, "(ptrval)", spec); > + return string(buf, end, str, spec); > } > > #ifdef CONFIG_64BIT
Re: [此邮件可能存在风险] [PATCH v2 7/9] lib/vsprintf: Replace space with '_' before crng is ready
Hi, Andy, Many thanks for the change. I am on Chinese New Year travel and slow response. :-) Thanks. Shunyong. On Fri, 2018-02-16 at 23:07 +0200, Andy Shevchenko wrote: > From: Shunyong Yang > > Before crng is ready, output of "%p" composes of "(ptrval)" and > left padding spaces for alignment as no random address can be > generated. This seems a little strange when default string width > is larger than strlen("(ptrval)"). > > For example, when irq domain names are built with "%p", the nodes > under /sys/kernel/debug/irq/domains like this on AArch64 system, > > [root@y irq]# ls domains/ > default irqchip@(ptrval)-2 > irqchip@(ptrval)-4 \_SB_.TCS0.QIC1 \_SB_.TCS0.QIC3 > irqchip@(ptrval) irqchip@(ptrval)-3 > \_SB_.TCS0.QIC0 \_SB_.TCS0.QIC2 > > The name "irqchip@(ptrval)-2" is not so readable in console > output. > > This patch replaces space with readable "_" when output needs > padding. > Following is the output after applying the patch, > > [root@y domains]# ls > default irqchip@(ptrval)-2 > irqchip@(ptrval)-4 \_SB_.TCS0.QIC1 \_SB_.TCS0.QIC3 > irqchip@(ptrval) irqchip@(ptrval)-3 \_SB_.TCS0.QIC0 > \_SB_.TCS0.QIC2 > > There is same problem in some subsystem's dmesg output. Moreover, > someone may call "%p" in a similar case. In addition, the timing of > crng initialization done may vary on different system. So, the change > is made in vsprintf.c. > > Cc: Joey Zheng > Suggested-by: Rasmus Villemoes > Signed-off-by: Shunyong Yang > Signed-off-by: Andy Shevchenko > --- > lib/vsprintf.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index 9004bbb3d84d..97be2d07297a 100644 > --- a/lib/vsprintf.c > +++ b/lib/vsprintf.c > @@ -1681,12 +1681,13 @@ early_initcall(initialize_ptr_random); > /* Maps a pointer to a 32 bit unique identifier. */ > static char *ptr_to_id(char *buf, char *end, void *ptr, struct > printf_spec spec) > { > + const char *str = sizeof(ptr) == 8 ? "(ptrval)" : > "(ptrval)"; > unsigned long hashval; > > if (unlikely(!have_filled_random_ptr_key)) { > spec.field_width = 2 * sizeof(ptr); > /* string length must be less than default_width */ > - return string(buf, end, "(ptrval)", spec); > + return string(buf, end, str, spec); > } > > #ifdef CONFIG_64BIT
[PATCH v2 7/9] lib/vsprintf: Replace space with '_' before crng is ready
From: Shunyong YangBefore crng is ready, output of "%p" composes of "(ptrval)" and left padding spaces for alignment as no random address can be generated. This seems a little strange when default string width is larger than strlen("(ptrval)"). For example, when irq domain names are built with "%p", the nodes under /sys/kernel/debug/irq/domains like this on AArch64 system, [root@y irq]# ls domains/ default irqchip@(ptrval)-2 irqchip@(ptrval)-4 \_SB_.TCS0.QIC1 \_SB_.TCS0.QIC3 irqchip@(ptrval) irqchip@(ptrval)-3 \_SB_.TCS0.QIC0 \_SB_.TCS0.QIC2 The name "irqchip@(ptrval)-2" is not so readable in console output. This patch replaces space with readable "_" when output needs padding. Following is the output after applying the patch, [root@y domains]# ls default irqchip@(ptrval)-2 irqchip@(ptrval)-4 \_SB_.TCS0.QIC1 \_SB_.TCS0.QIC3 irqchip@(ptrval) irqchip@(ptrval)-3 \_SB_.TCS0.QIC0 \_SB_.TCS0.QIC2 There is same problem in some subsystem's dmesg output. Moreover, someone may call "%p" in a similar case. In addition, the timing of crng initialization done may vary on different system. So, the change is made in vsprintf.c. Cc: Joey Zheng Suggested-by: Rasmus Villemoes Signed-off-by: Shunyong Yang Signed-off-by: Andy Shevchenko --- lib/vsprintf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 9004bbb3d84d..97be2d07297a 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1681,12 +1681,13 @@ early_initcall(initialize_ptr_random); /* Maps a pointer to a 32 bit unique identifier. */ static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec) { + const char *str = sizeof(ptr) == 8 ? "(ptrval)" : "(ptrval)"; unsigned long hashval; if (unlikely(!have_filled_random_ptr_key)) { spec.field_width = 2 * sizeof(ptr); /* string length must be less than default_width */ - return string(buf, end, "(ptrval)", spec); + return string(buf, end, str, spec); } #ifdef CONFIG_64BIT -- 2.15.1
[PATCH v2 7/9] lib/vsprintf: Replace space with '_' before crng is ready
From: Shunyong Yang Before crng is ready, output of "%p" composes of "(ptrval)" and left padding spaces for alignment as no random address can be generated. This seems a little strange when default string width is larger than strlen("(ptrval)"). For example, when irq domain names are built with "%p", the nodes under /sys/kernel/debug/irq/domains like this on AArch64 system, [root@y irq]# ls domains/ default irqchip@(ptrval)-2 irqchip@(ptrval)-4 \_SB_.TCS0.QIC1 \_SB_.TCS0.QIC3 irqchip@(ptrval) irqchip@(ptrval)-3 \_SB_.TCS0.QIC0 \_SB_.TCS0.QIC2 The name "irqchip@(ptrval)-2" is not so readable in console output. This patch replaces space with readable "_" when output needs padding. Following is the output after applying the patch, [root@y domains]# ls default irqchip@(ptrval)-2 irqchip@(ptrval)-4 \_SB_.TCS0.QIC1 \_SB_.TCS0.QIC3 irqchip@(ptrval) irqchip@(ptrval)-3 \_SB_.TCS0.QIC0 \_SB_.TCS0.QIC2 There is same problem in some subsystem's dmesg output. Moreover, someone may call "%p" in a similar case. In addition, the timing of crng initialization done may vary on different system. So, the change is made in vsprintf.c. Cc: Joey Zheng Suggested-by: Rasmus Villemoes Signed-off-by: Shunyong Yang Signed-off-by: Andy Shevchenko --- lib/vsprintf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 9004bbb3d84d..97be2d07297a 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1681,12 +1681,13 @@ early_initcall(initialize_ptr_random); /* Maps a pointer to a 32 bit unique identifier. */ static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec) { + const char *str = sizeof(ptr) == 8 ? "(ptrval)" : "(ptrval)"; unsigned long hashval; if (unlikely(!have_filled_random_ptr_key)) { spec.field_width = 2 * sizeof(ptr); /* string length must be less than default_width */ - return string(buf, end, "(ptrval)", spec); + return string(buf, end, str, spec); } #ifdef CONFIG_64BIT -- 2.15.1