[PATCH] iproute2: ss: escape all null bytes in abstract unix domain socket

Subsystems: the rest

STALE3568d

9 messages, 4 authors, 2016-12-05 · open the first message on its own page

[PATCH] iproute2: ss: escape all null bytes in abstract unix domain socket

From: Isaac Boukris <hidden>
Date: 2016-10-29 19:22:18

Abstract unix domain socket may embed null characters,
these should be translated to '@' when printed by ss the
same way the null prefix is currently being translated.

Signed-off-by: Isaac Boukris <redacted>
---
 misc/ss.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/misc/ss.c b/misc/ss.c
index dd77b81..0e28998 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -2895,7 +2895,9 @@ static int unix_show_sock(const struct sockaddr_nl *addr, struct nlmsghdr *nlh,
 		memcpy(name, RTA_DATA(tb[UNIX_DIAG_NAME]), len);
 		name[len] = '\0';
 		if (name[0] == '\0')
-			name[0] = '@';
+			for (int i = 0; i < len; i++)
+				if (name[i] == '\0')
+					name[i] = '@';
 		stat.name = &name[0];
 		memcpy(stat.local.data, &stat.name, sizeof(stat.name));
 	}
-- 
2.7.4

[PATCH] unix: escape all null bytes in abstract unix domain socket

From: Isaac Boukris <hidden>
Date: 2016-10-29 19:22:26

Abstract unix domain socket may embed null characters,
these should be translated to '@' when printed out to
proc the same way the null prefix is currently being
translated.

This helps for tools such as netstat, lsof and the proc
based implementation in ss to show all the significant
bytes of the name (instead of getting cut at the first
null occurrence).

Signed-off-by: Isaac Boukris <redacted>
---
 net/unix/af_unix.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 145082e..9250b03 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2805,14 +2805,19 @@ static int unix_seq_show(struct seq_file *seq, void *v)
 
 			i = 0;
 			len = u->addr->len - sizeof(short);
-			if (!UNIX_ABSTRACT(s))
+			if (!UNIX_ABSTRACT(s)) {
 				len--;
-			else {
+				for ( ; i < len; i++)
+					seq_putc(seq,
+						 u->addr->name->sun_path[i]);
+			} else {
 				seq_putc(seq, '@');
 				i++;
+				for ( ; i < len; i++)
+					seq_putc(seq,
+						 u->addr->name->sun_path[i] ?:
+						 '@');
 			}
-			for ( ; i < len; i++)
-				seq_putc(seq, u->addr->name->sun_path[i]);
 		}
 		unix_state_unlock(s);
 		seq_putc(seq, '\n');
-- 
2.7.4

Re: [PATCH] unix: escape all null bytes in abstract unix domain socket

From: David Miller <davem@davemloft.net>
Date: 2016-10-31 19:31:24

From: Isaac Boukris <redacted>
Date: Sat, 29 Oct 2016 22:20:20 +0300
Abstract unix domain socket may embed null characters,
these should be translated to '@' when printed out to
proc the same way the null prefix is currently being
translated.

This helps for tools such as netstat, lsof and the proc
based implementation in ss to show all the significant
bytes of the name (instead of getting cut at the first
null occurrence).

Signed-off-by: Isaac Boukris <redacted>
 ...
quoted hunk
@@ -2805,14 +2805,19 @@ static int unix_seq_show(struct seq_file *seq, void *v)
 
 			i = 0;
 			len = u->addr->len - sizeof(short);
-			if (!UNIX_ABSTRACT(s))
+			if (!UNIX_ABSTRACT(s)) {
 				len--;
-			else {
+				for ( ; i < len; i++)
+					seq_putc(seq,
+						 u->addr->name->sun_path[i]);
+			} else {
 				seq_putc(seq, '@');
 				i++;
+				for ( ; i < len; i++)
+					seq_putc(seq,
+						 u->addr->name->sun_path[i] ?:
+						 '@');
 			}
-			for ( ; i < len; i++)
-				seq_putc(seq, u->addr->name->sun_path[i]);
I think this patch is simpler if you just do the "@" translation
unconditionally, if it'll never trigger for the !UNIX_ABSTRACT case
that is perfectly fine.

Re: [PATCH] unix: escape all null bytes in abstract unix domain socket

From: Isaac Boukris <hidden>
Date: 2016-11-01 00:57:06

Hi David, thanks for looking at it.

On Mon, Oct 31, 2016 at 9:31 PM, David Miller [off-list ref] wrote:
From: Isaac Boukris <redacted>
Date: Sat, 29 Oct 2016 22:20:20 +0300
quoted
Abstract unix domain socket may embed null characters,
these should be translated to '@' when printed out to
proc the same way the null prefix is currently being
translated.

This helps for tools such as netstat, lsof and the proc
based implementation in ss to show all the significant
bytes of the name (instead of getting cut at the first
null occurrence).

Signed-off-by: Isaac Boukris <redacted>
 ...
quoted
@@ -2805,14 +2805,19 @@ static int unix_seq_show(struct seq_file *seq, void *v)

                      i = 0;
                      len = u->addr->len - sizeof(short);
-                     if (!UNIX_ABSTRACT(s))
+                     if (!UNIX_ABSTRACT(s)) {
                              len--;
-                     else {
+                             for ( ; i < len; i++)
+                                     seq_putc(seq,
+                                              u->addr->name->sun_path[i]);
+                     } else {
                              seq_putc(seq, '@');
                              i++;
+                             for ( ; i < len; i++)
+                                     seq_putc(seq,
+                                              u->addr->name->sun_path[i] ?:
+                                              '@');
                      }
-                     for ( ; i < len; i++)
-                             seq_putc(seq, u->addr->name->sun_path[i]);
I think this patch is simpler if you just do the "@" translation
unconditionally, if it'll never trigger for the !UNIX_ABSTRACT case
that is perfectly fine.
I've sent an updated patch.
Logically now, the 'else' block just above could be removed, but it
isn't obvious from the code that 'sun_path[0] == 0' so I left it as
is.

Re: [PATCH] iproute2: ss: escape all null bytes in abstract unix domain socket

From: Stephen Hemminger <stephen@networkplumber.org>
Date: 2016-11-12 07:17:35

On Sat, 29 Oct 2016 22:20:19 +0300
Isaac Boukris [off-list ref] wrote:
Abstract unix domain socket may embed null characters,
these should be translated to '@' when printed by ss the
same way the null prefix is currently being translated.

Signed-off-by: Isaac Boukris <redacted>
Applied

Re: [PATCH] iproute2: ss: escape all null bytes in abstract unix domain socket

From: Eric Dumazet <hidden>
Date: 2016-12-02 19:01:00

On Sat, 2016-11-12 at 10:17 +0300, Stephen Hemminger wrote:
On Sat, 29 Oct 2016 22:20:19 +0300
Isaac Boukris [off-list ref] wrote:
quoted
Abstract unix domain socket may embed null characters,
these should be translated to '@' when printed by ss the
same way the null prefix is currently being translated.

Signed-off-by: Isaac Boukris <redacted>
Applied
Probably not a good idea to have :

                       for (int i = 0; i < len; i++)
                               if (name[i] == '\0')
                                       name[i] = '@';

ss.c: In function 'unix_show_sock':
ss.c:3128:4: error: 'for' loop initial declarations are only allowed in C99 mode
ss.c:3128:4: note: use option -std=c99 or -std=gnu99 to compile your code
make[1]: *** [ss.o] Error 1

Re: [PATCH] iproute2: ss: escape all null bytes in abstract unix domain socket

From: Stephen Hemminger <stephen@networkplumber.org>
Date: 2016-12-02 23:19:14

On Fri, 02 Dec 2016 10:59:56 -0800
Eric Dumazet [off-list ref] wrote:
On Sat, 2016-11-12 at 10:17 +0300, Stephen Hemminger wrote:
quoted
On Sat, 29 Oct 2016 22:20:19 +0300
Isaac Boukris [off-list ref] wrote:
  
quoted
Abstract unix domain socket may embed null characters,
these should be translated to '@' when printed by ss the
same way the null prefix is currently being translated.

Signed-off-by: Isaac Boukris <redacted>  
Applied  
Probably not a good idea to have :

                       for (int i = 0; i < len; i++)
                               if (name[i] == '\0')
                                       name[i] = '@';

ss.c: In function 'unix_show_sock':
ss.c:3128:4: error: 'for' loop initial declarations are only allowed in C99 mode
ss.c:3128:4: note: use option -std=c99 or -std=gnu99 to compile your code
make[1]: *** [ss.o] Error 1

Thanks, fixed by patch from Simon

Re: [PATCH] iproute2: ss: escape all null bytes in abstract unix domain socket

From: Eric Dumazet <hidden>
Date: 2016-12-02 23:26:33

On Fri, 2016-12-02 at 15:18 -0800, Stephen Hemminger wrote:
                                    name[i] = '@';
quoted
ss.c: In function 'unix_show_sock':
ss.c:3128:4: error: 'for' loop initial declarations are only allowed in C99 mode
ss.c:3128:4: note: use option -std=c99 or -std=gnu99 to compile your code
make[1]: *** [ss.o] Error 1

Thanks, fixed by patch from Simon
Right, thanks !

Re: [PATCH] iproute2: ss: escape all null bytes in abstract unix domain socket

From: Isaac Boukris <hidden>
Date: 2016-12-05 05:38:28

On Sat, Dec 3, 2016 at 1:24 AM, Eric Dumazet [off-list ref] wrote:
On Fri, 2016-12-02 at 15:18 -0800, Stephen Hemminger wrote:
quoted
                                    name[i] = '@';
quoted
ss.c: In function 'unix_show_sock':
ss.c:3128:4: error: 'for' loop initial declarations are only allowed in C99 mode
ss.c:3128:4: note: use option -std=c99 or -std=gnu99 to compile your code
make[1]: *** [ss.o] Error 1

Thanks, fixed by patch from Simon
Right, thanks !

Thanks for notifying me. Sorry for the bug and thanks for the fix!
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help