Skip to contentSkip to conversation

vsprintf: Neaten %pK kptr_restrict, save a bit of code space

PATCH In review Joe Perches 2 participants 5 messages Jan 13, 2011 – Jan 19, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vsprintf: Neaten %pK kptr_restrict, save a bit of code space

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

---

 lib/vsprintf.c |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)
lib/vsprintf.c +5 -9
index d3023df..070d134 100644
@@ -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) {
maintainer
#1 lore raw
Quoted 30 lines · On Thu, 13 Jan 2011 12:21:12 -0800 Joe Perches <[email protected]> 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

---

 lib/vsprintf.c |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)
lib/vsprintf.c +0 -8
index d3023df..070d134 100644
@@ -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;

lib/vsprintf.c char *pointer(const char *fmt, char *buf, char *end, void *ptr, · line 1058

Quoted 10 lines
lib/vsprintf.c +5 -1
 		}
-		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?

#2 lore raw
Quoted 4 lines · Andrew Morton

lib/vsprintf.c

Quoted 2 lines · On Thu, 13 Jan 2011 12:21:12 -0800 Joe Perches <[email protected]> wrote:

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

lib/vsprintf.c +0 -0

[]

Quoted 6 lines

lib/vsprintf.c char *pointer(const char *fmt, char *buf, char *end, void *ptr, · line 1055

Quoted 5 lines
lib/vsprintf.c +5 -0
+		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. ;)

maintainer
#3 lore raw
Quoted 26 lines · On Wed, 19 Jan 2011 15:11:02 -0800 Joe Perches <[email protected]> wrote:
Quoted 4 lines · Andrew Morton

lib/vsprintf.c

Quoted 2 lines · On Thu, 13 Jan 2011 12:21:12 -0800 Joe Perches <[email protected]> wrote:

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

lib/vsprintf.c +0 -0

[]

Quoted 6 lines

lib/vsprintf.c char *pointer(const char *fmt, char *buf, char *end, void *ptr, · line 1055

Quoted 5 lines
lib/vsprintf.c +5 -0
+		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;
Quoted 1 line

Your choice. ;)

That wasn't the bit which hurt.

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

#4 lore raw
Quoted 14 lines · Andrew Morton
Quoted 12 lines · On Wed, 19 Jan 2011 15:11:02 -0800 Joe Perches <[email protected]> wrote:
Quoted 4 lines · Andrew Morton

lib/vsprintf.c

Quoted 2 lines · On Thu, 13 Jan 2011 12:21:12 -0800 Joe Perches <[email protected]> wrote:

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

lib/vsprintf.c +0 -0

[]

Quoted 6 lines

lib/vsprintf.c char *pointer(const char *fmt, char *buf, char *end, void *ptr, · line 1055

Quoted 5 lines
lib/vsprintf.c +5 -0
+		if (!((kptr_restrict == 0) ||
+		      (kptr_restrict == 1 &&
+		       has_capability_noaudit(current, CAP_SYSLOG))))
+			ptr = NULL;
+		break;

This hurts my brain. Does it work?

Quoted 3 lines
Quoted 2 lines

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.

Quoted 1 line

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