Re: [RFC 5/6] lib: vsprintf: Add "%paP", "%padP" options

2017-05-18 Thread Greg KH
On Tue, May 16, 2017 at 04:41:04PM +0200, Petr Mladek wrote:
> On Fri 2017-05-05 21:07:47, Greg KH wrote:
> > From: Chris Fries 
> > 
> > Add %paP and %padP for physical address that need to always be shown
> > regardless of kptr restrictions.
> > 
> > Cc: William Roberts 
> > Cc: Dave Weinstein 
> > Signed-off-by: Chris Fries 
> > Signed-off-by: Greg Kroah-Hartman 
> > ---
> >  Documentation/printk-formats.txt | 10 ++
> >  lib/vsprintf.c   | 12 +---
> >  2 files changed, 15 insertions(+), 7 deletions(-)
> 
> This patch should update also the section about
> kptr_restrict in Documentation/sysctl/kernel.txt.
> It should mention that the trailing P allows to see
> pointers also for %pa, and %p[rR] formats when
> the level is 4.

Ah, good point, will do!

greg k-h


Re: [RFC 5/6] lib: vsprintf: Add "%paP", "%padP" options

2017-05-18 Thread Greg KH
On Tue, May 16, 2017 at 04:41:04PM +0200, Petr Mladek wrote:
> On Fri 2017-05-05 21:07:47, Greg KH wrote:
> > From: Chris Fries 
> > 
> > Add %paP and %padP for physical address that need to always be shown
> > regardless of kptr restrictions.
> > 
> > Cc: William Roberts 
> > Cc: Dave Weinstein 
> > Signed-off-by: Chris Fries 
> > Signed-off-by: Greg Kroah-Hartman 
> > ---
> >  Documentation/printk-formats.txt | 10 ++
> >  lib/vsprintf.c   | 12 +---
> >  2 files changed, 15 insertions(+), 7 deletions(-)
> 
> This patch should update also the section about
> kptr_restrict in Documentation/sysctl/kernel.txt.
> It should mention that the trailing P allows to see
> pointers also for %pa, and %p[rR] formats when
> the level is 4.

Ah, good point, will do!

greg k-h


Re: [RFC 5/6] lib: vsprintf: Add "%paP", "%padP" options

2017-05-16 Thread Petr Mladek
On Fri 2017-05-05 21:07:47, Greg KH wrote:
> From: Chris Fries 
> 
> Add %paP and %padP for physical address that need to always be shown
> regardless of kptr restrictions.
> 
> Cc: William Roberts 
> Cc: Dave Weinstein 
> Signed-off-by: Chris Fries 
> Signed-off-by: Greg Kroah-Hartman 
> ---
>  Documentation/printk-formats.txt | 10 ++
>  lib/vsprintf.c   | 12 +---
>  2 files changed, 15 insertions(+), 7 deletions(-)

This patch should update also the section about
kptr_restrict in Documentation/sysctl/kernel.txt.
It should mention that the trailing P allows to see
pointers also for %pa, and %p[rR] formats when
the level is 4.

Best Regards,
Petr


Re: [RFC 5/6] lib: vsprintf: Add "%paP", "%padP" options

2017-05-16 Thread Petr Mladek
On Fri 2017-05-05 21:07:47, Greg KH wrote:
> From: Chris Fries 
> 
> Add %paP and %padP for physical address that need to always be shown
> regardless of kptr restrictions.
> 
> Cc: William Roberts 
> Cc: Dave Weinstein 
> Signed-off-by: Chris Fries 
> Signed-off-by: Greg Kroah-Hartman 
> ---
>  Documentation/printk-formats.txt | 10 ++
>  lib/vsprintf.c   | 12 +---
>  2 files changed, 15 insertions(+), 7 deletions(-)

This patch should update also the section about
kptr_restrict in Documentation/sysctl/kernel.txt.
It should mention that the trailing P allows to see
pointers also for %pa, and %p[rR] formats when
the level is 4.

Best Regards,
Petr


Re: [RFC 5/6] lib: vsprintf: Add "%paP", "%padP" options

2017-05-05 Thread Greg KH
On Fri, May 05, 2017 at 09:42:40PM -0700, Joe Perches wrote:
> On Fri, 2017-05-05 at 21:07 -0700, Greg KH wrote:
> > From: Chris Fries 
> > 
> > Add %paP and %padP for physical address that need to always be shown
> > regardless of kptr restrictions.
> 
> The commit message could be improved.

Good point, I'll work on that, thanks.

> I had to look at the actual code to see if %papP was supported.
> 
> > diff --git a/Documentation/printk-formats.txt 
> > b/Documentation/printk-formats.txt
> []
> > @@ -82,18 +82,20 @@ Struct Resources:
> >  
> >  Physical addresses types phys_addr_t:
> >  
> > -   %pa[p]  0x01234567 or 0x0123456789abcdef
> > +   %pa[p][P] 0x01234567 or 0x0123456789abcdef
> 
> Well, that's good.
> 
> > diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> []
> > @@ -1394,23 +1394,29 @@ static noinline_for_stack
> >  char *address_val(char *buf, char *end, const void *addr, const char *fmt)
> >  {
> > unsigned long long num;
> > +   int cleanse = kptr_restrict_cleanse_addresses();
> 
> bool

I'll change this, thanks.

greg k-h


Re: [RFC 5/6] lib: vsprintf: Add "%paP", "%padP" options

2017-05-05 Thread Greg KH
On Fri, May 05, 2017 at 09:42:40PM -0700, Joe Perches wrote:
> On Fri, 2017-05-05 at 21:07 -0700, Greg KH wrote:
> > From: Chris Fries 
> > 
> > Add %paP and %padP for physical address that need to always be shown
> > regardless of kptr restrictions.
> 
> The commit message could be improved.

Good point, I'll work on that, thanks.

> I had to look at the actual code to see if %papP was supported.
> 
> > diff --git a/Documentation/printk-formats.txt 
> > b/Documentation/printk-formats.txt
> []
> > @@ -82,18 +82,20 @@ Struct Resources:
> >  
> >  Physical addresses types phys_addr_t:
> >  
> > -   %pa[p]  0x01234567 or 0x0123456789abcdef
> > +   %pa[p][P] 0x01234567 or 0x0123456789abcdef
> 
> Well, that's good.
> 
> > diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> []
> > @@ -1394,23 +1394,29 @@ static noinline_for_stack
> >  char *address_val(char *buf, char *end, const void *addr, const char *fmt)
> >  {
> > unsigned long long num;
> > +   int cleanse = kptr_restrict_cleanse_addresses();
> 
> bool

I'll change this, thanks.

greg k-h


Re: [RFC 5/6] lib: vsprintf: Add "%paP", "%padP" options

2017-05-05 Thread Joe Perches
On Fri, 2017-05-05 at 21:07 -0700, Greg KH wrote:
> From: Chris Fries 
> 
> Add %paP and %padP for physical address that need to always be shown
> regardless of kptr restrictions.

The commit message could be improved.

I had to look at the actual code to see if %papP was supported.

> diff --git a/Documentation/printk-formats.txt 
> b/Documentation/printk-formats.txt
[]
> @@ -82,18 +82,20 @@ Struct Resources:
>  
>  Physical addresses types phys_addr_t:
>  
> - %pa[p]  0x01234567 or 0x0123456789abcdef
> + %pa[p][P] 0x01234567 or 0x0123456789abcdef

Well, that's good.

> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
[]
> @@ -1394,23 +1394,29 @@ static noinline_for_stack
>  char *address_val(char *buf, char *end, const void *addr, const char *fmt)
>  {
>   unsigned long long num;
> + int cleanse = kptr_restrict_cleanse_addresses();

bool



Re: [RFC 5/6] lib: vsprintf: Add "%paP", "%padP" options

2017-05-05 Thread Joe Perches
On Fri, 2017-05-05 at 21:07 -0700, Greg KH wrote:
> From: Chris Fries 
> 
> Add %paP and %padP for physical address that need to always be shown
> regardless of kptr restrictions.

The commit message could be improved.

I had to look at the actual code to see if %papP was supported.

> diff --git a/Documentation/printk-formats.txt 
> b/Documentation/printk-formats.txt
[]
> @@ -82,18 +82,20 @@ Struct Resources:
>  
>  Physical addresses types phys_addr_t:
>  
> - %pa[p]  0x01234567 or 0x0123456789abcdef
> + %pa[p][P] 0x01234567 or 0x0123456789abcdef

Well, that's good.

> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
[]
> @@ -1394,23 +1394,29 @@ static noinline_for_stack
>  char *address_val(char *buf, char *end, const void *addr, const char *fmt)
>  {
>   unsigned long long num;
> + int cleanse = kptr_restrict_cleanse_addresses();

bool



[RFC 5/6] lib: vsprintf: Add "%paP", "%padP" options

2017-05-05 Thread Greg KH
From: Chris Fries 

Add %paP and %padP for physical address that need to always be shown
regardless of kptr restrictions.

Cc: William Roberts 
Cc: Dave Weinstein 
Signed-off-by: Chris Fries 
Signed-off-by: Greg Kroah-Hartman 
---
 Documentation/printk-formats.txt | 10 ++
 lib/vsprintf.c   | 12 +---
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt
index 8994c65aa3b0..7ee51269096f 100644
--- a/Documentation/printk-formats.txt
+++ b/Documentation/printk-formats.txt
@@ -82,18 +82,20 @@ Struct Resources:
 
 Physical addresses types phys_addr_t:
 
-   %pa[p]  0x01234567 or 0x0123456789abcdef
+   %pa[p][P] 0x01234567 or 0x0123456789abcdef
 
For printing a phys_addr_t type (and its derivatives, such as
resource_size_t) which can vary based on build options, regardless of
-   the width of the CPU data path. Passed by reference.
+   the width of the CPU data path. Passed by reference.  Use the trailing
+   'P' if it needs to be always shown.
 
 DMA addresses types dma_addr_t:
 
-   %pad0x01234567 or 0x0123456789abcdef
+   %pad[P] 0x01234567 or 0x0123456789abcdef
 
For printing a dma_addr_t type which can vary based on build options,
-   regardless of the width of the CPU data path. Passed by reference.
+   regardless of the width of the CPU data path. Passed by reference. Use
+   the trailing 'P' if it needs to be always shown.
 
 Raw buffer as an escaped string:
 
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 404d477d4bd2..37f9d615e622 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1394,23 +1394,29 @@ static noinline_for_stack
 char *address_val(char *buf, char *end, const void *addr, const char *fmt)
 {
unsigned long long num;
+   int cleanse = kptr_restrict_cleanse_addresses();
+   int decleanse_idx = 1;
int size;
 
switch (fmt[1]) {
case 'd':
num = *(const dma_addr_t *)addr;
size = sizeof(dma_addr_t);
+   decleanse_idx = 2;
break;
case 'p':
+   decleanse_idx = 2;
+   /* fall thru */
default:
num = *(const phys_addr_t *)addr;
size = sizeof(phys_addr_t);
break;
}
 
-   return special_hex_number(buf, end,
- kptr_restrict_cleanse_addresses() ? 0UL : num,
- size);
+   /* 'P' on the tail means don't restrict the pointer. */
+   cleanse = cleanse && (fmt[decleanse_idx] != 'P');
+
+   return special_hex_number(buf, end, cleanse ? 0UL : num, size);
 }
 
 static noinline_for_stack
-- 
2.12.2



[RFC 5/6] lib: vsprintf: Add "%paP", "%padP" options

2017-05-05 Thread Greg KH
From: Chris Fries 

Add %paP and %padP for physical address that need to always be shown
regardless of kptr restrictions.

Cc: William Roberts 
Cc: Dave Weinstein 
Signed-off-by: Chris Fries 
Signed-off-by: Greg Kroah-Hartman 
---
 Documentation/printk-formats.txt | 10 ++
 lib/vsprintf.c   | 12 +---
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt
index 8994c65aa3b0..7ee51269096f 100644
--- a/Documentation/printk-formats.txt
+++ b/Documentation/printk-formats.txt
@@ -82,18 +82,20 @@ Struct Resources:
 
 Physical addresses types phys_addr_t:
 
-   %pa[p]  0x01234567 or 0x0123456789abcdef
+   %pa[p][P] 0x01234567 or 0x0123456789abcdef
 
For printing a phys_addr_t type (and its derivatives, such as
resource_size_t) which can vary based on build options, regardless of
-   the width of the CPU data path. Passed by reference.
+   the width of the CPU data path. Passed by reference.  Use the trailing
+   'P' if it needs to be always shown.
 
 DMA addresses types dma_addr_t:
 
-   %pad0x01234567 or 0x0123456789abcdef
+   %pad[P] 0x01234567 or 0x0123456789abcdef
 
For printing a dma_addr_t type which can vary based on build options,
-   regardless of the width of the CPU data path. Passed by reference.
+   regardless of the width of the CPU data path. Passed by reference. Use
+   the trailing 'P' if it needs to be always shown.
 
 Raw buffer as an escaped string:
 
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 404d477d4bd2..37f9d615e622 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1394,23 +1394,29 @@ static noinline_for_stack
 char *address_val(char *buf, char *end, const void *addr, const char *fmt)
 {
unsigned long long num;
+   int cleanse = kptr_restrict_cleanse_addresses();
+   int decleanse_idx = 1;
int size;
 
switch (fmt[1]) {
case 'd':
num = *(const dma_addr_t *)addr;
size = sizeof(dma_addr_t);
+   decleanse_idx = 2;
break;
case 'p':
+   decleanse_idx = 2;
+   /* fall thru */
default:
num = *(const phys_addr_t *)addr;
size = sizeof(phys_addr_t);
break;
}
 
-   return special_hex_number(buf, end,
- kptr_restrict_cleanse_addresses() ? 0UL : num,
- size);
+   /* 'P' on the tail means don't restrict the pointer. */
+   cleanse = cleanse && (fmt[decleanse_idx] != 'P');
+
+   return special_hex_number(buf, end, cleanse ? 0UL : num, size);
 }
 
 static noinline_for_stack
-- 
2.12.2