The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] vsprintf: Neaten %pK kptr_restrict, save a bit of code space
@ 2011-01-13 20:21 Joe Perches
  2011-01-19 22:50 ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Joe Perches @ 2011-01-13 20:21 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Dan Rosenberg, linux-kernel

If kptr restrictions are on, just set the passed pointer to NULL.

$ size lib/vsprintf.o.*
   text	   data	    bss	    dec	    hex	filename
   8247	      4	      2	   8253	   203d	lib/vsprintf.o.new
   8282	      4	      2	   8288	   2060	lib/vsprintf.o.old

Signed-off-by: Joe Perches <joe@perches.com>

---

 lib/vsprintf.c |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index d3023df..070d134 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1047,16 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 			if (spec.field_width == -1)
 				spec.field_width = 2 * sizeof(void *);
 			return string(buf, end, "pK-error", spec);
-		} else if ((kptr_restrict == 0) ||
-			 (kptr_restrict == 1 &&
-			  has_capability_noaudit(current, CAP_SYSLOG)))
-			break;
-
-		if (spec.field_width == -1) {
-			spec.field_width = 2 * sizeof(void *);
-			spec.flags |= ZEROPAD;
 		}
-		return number(buf, end, 0, spec);
+		if (!((kptr_restrict == 0) ||
+		      (kptr_restrict == 1 &&
+		       has_capability_noaudit(current, CAP_SYSLOG))))
+			ptr = NULL;
+		break;
 	}
 	spec.flags |= SMALL;
 	if (spec.field_width == -1) {



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] vsprintf: Neaten %pK kptr_restrict, save a bit of code space
  2011-01-13 20:21 [PATCH] vsprintf: Neaten %pK kptr_restrict, save a bit of code space Joe Perches
@ 2011-01-19 22:50 ` Andrew Morton
  2011-01-19 23:11   ` Joe Perches
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2011-01-19 22:50 UTC (permalink / raw)
  To: Joe Perches; +Cc: Dan Rosenberg, linux-kernel

On Thu, 13 Jan 2011 12:21:12 -0800
Joe Perches <joe@perches.com> wrote:

> If kptr restrictions are on, just set the passed pointer to NULL.
> 
> $ size lib/vsprintf.o.*
>    text	   data	    bss	    dec	    hex	filename
>    8247	      4	      2	   8253	   203d	lib/vsprintf.o.new
>    8282	      4	      2	   8288	   2060	lib/vsprintf.o.old
> 
> Signed-off-by: Joe Perches <joe@perches.com>
> 
> ---
> 
>  lib/vsprintf.c |   14 +++++---------
>  1 files changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index d3023df..070d134 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -1047,16 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
>  			if (spec.field_width == -1)
>  				spec.field_width = 2 * sizeof(void *);
>  			return string(buf, end, "pK-error", spec);
> -		} else if ((kptr_restrict == 0) ||
> -			 (kptr_restrict == 1 &&
> -			  has_capability_noaudit(current, CAP_SYSLOG)))
> -			break;
> -
> -		if (spec.field_width == -1) {
> -			spec.field_width = 2 * sizeof(void *);
> -			spec.flags |= ZEROPAD;
>  		}
> -		return number(buf, end, 0, spec);
> +		if (!((kptr_restrict == 0) ||
> +		      (kptr_restrict == 1 &&
> +		       has_capability_noaudit(current, CAP_SYSLOG))))
> +			ptr = NULL;
> +		break;
>  	}
>  	spec.flags |= SMALL;
>  	if (spec.field_width == -1) {

This hurts my brain.   Does it work?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] vsprintf: Neaten %pK kptr_restrict, save a bit of code space
  2011-01-19 22:50 ` Andrew Morton
@ 2011-01-19 23:11   ` Joe Perches
  2011-01-19 23:16     ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Joe Perches @ 2011-01-19 23:11 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Dan Rosenberg, linux-kernel

On Wed, 2011-01-19 at 14:50 -0800, Andrew Morton wrote:
> On Thu, 13 Jan 2011 12:21:12 -0800
> Joe Perches <joe@perches.com> wrote:
> > If kptr restrictions are on, just set the passed pointer to NULL.
> > diff --git a/lib/vsprintf.c b/lib/vsprintf.c
[]
> > +		if (!((kptr_restrict == 0) ||
> > +		      (kptr_restrict == 1 &&
> > +		       has_capability_noaudit(current, CAP_SYSLOG))))
> > +			ptr = NULL;
> > +		break;
> This hurts my brain.   Does it work?

Some say mentally challenging puzzles help deter/delay
onset of cognitive decline/Alzheimer's.  See: www.dakim.com

A mentally less challenging perhaps cleaner form is:

		if (kptr_restrict == 0)
			break;
		if (kptr_restrict == 1 &&
		    has_capability_noaudit(current, CAP_SYSLOG))
			break;
		ptr = NULL;
		break;

Your choice. ;)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] vsprintf: Neaten %pK kptr_restrict, save a bit of code space
  2011-01-19 23:11   ` Joe Perches
@ 2011-01-19 23:16     ` Andrew Morton
  2011-01-19 23:32       ` Joe Perches
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2011-01-19 23:16 UTC (permalink / raw)
  To: Joe Perches; +Cc: Dan Rosenberg, linux-kernel

On Wed, 19 Jan 2011 15:11:02 -0800
Joe Perches <joe@perches.com> wrote:

> On Wed, 2011-01-19 at 14:50 -0800, Andrew Morton wrote:
> > On Thu, 13 Jan 2011 12:21:12 -0800
> > Joe Perches <joe@perches.com> wrote:
> > > If kptr restrictions are on, just set the passed pointer to NULL.
> > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> []
> > > +		if (!((kptr_restrict == 0) ||
> > > +		      (kptr_restrict == 1 &&
> > > +		       has_capability_noaudit(current, CAP_SYSLOG))))
> > > +			ptr = NULL;
> > > +		break;
> > This hurts my brain.   Does it work?
> 
> Some say mentally challenging puzzles help deter/delay
> onset of cognitive decline/Alzheimer's.  See: www.dakim.com
> 
> A mentally less challenging perhaps cleaner form is:
> 
> 		if (kptr_restrict == 0)
> 			break;
> 		if (kptr_restrict == 1 &&
> 		    has_capability_noaudit(current, CAP_SYSLOG))
> 			break;
> 		ptr = NULL;
> 		break;
> 
> Your choice. ;)

That wasn't the bit which hurt.

You still haven't told me if it works.  How thoroughly was it tested?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] vsprintf: Neaten %pK kptr_restrict, save a bit of code space
  2011-01-19 23:16     ` Andrew Morton
@ 2011-01-19 23:32       ` Joe Perches
  0 siblings, 0 replies; 5+ messages in thread
From: Joe Perches @ 2011-01-19 23:32 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Dan Rosenberg, linux-kernel

On Wed, 2011-01-19 at 15:16 -0800, Andrew Morton wrote:
> On Wed, 19 Jan 2011 15:11:02 -0800
> Joe Perches <joe@perches.com> wrote:
> > On Wed, 2011-01-19 at 14:50 -0800, Andrew Morton wrote:
> > > On Thu, 13 Jan 2011 12:21:12 -0800
> > > Joe Perches <joe@perches.com> wrote:
> > > > If kptr restrictions are on, just set the passed pointer to NULL.
> > > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> > []
> > > > +		if (!((kptr_restrict == 0) ||
> > > > +		      (kptr_restrict == 1 &&
> > > > +		       has_capability_noaudit(current, CAP_SYSLOG))))
> > > > +			ptr = NULL;
> > > > +		break;
> > > This hurts my brain.   Does it work?
> > Some say mentally challenging puzzles help deter/delay
> > onset of cognitive decline/Alzheimer's.  See: www.dakim.com
> That wasn't the bit which hurt.

Sure.

> You still haven't told me if it works.  How thoroughly was it tested?

Very lightly (x86 only).

It's a logic only change.

cheers, Joe


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-01-19 23:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-13 20:21 [PATCH] vsprintf: Neaten %pK kptr_restrict, save a bit of code space Joe Perches
2011-01-19 22:50 ` Andrew Morton
2011-01-19 23:11   ` Joe Perches
2011-01-19 23:16     ` Andrew Morton
2011-01-19 23:32       ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox