All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iproute2: ss: escape all null bytes in abstract unix domain socket
@ 2016-10-29 19:20 Isaac Boukris
  2016-10-29 19:20 ` [PATCH] unix: " Isaac Boukris
  2016-11-12  7:17 ` [PATCH] iproute2: ss: " Stephen Hemminger
  0 siblings, 2 replies; 9+ messages in thread
From: Isaac Boukris @ 2016-10-29 19:20 UTC (permalink / raw)
  To: stephen, davem, netdev, linux-kernel; +Cc: Isaac Boukris

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 <iboukris@gmail.com>
---
 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

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

* [PATCH] unix: escape all null bytes in abstract unix domain socket
  2016-10-29 19:20 [PATCH] iproute2: ss: escape all null bytes in abstract unix domain socket Isaac Boukris
@ 2016-10-29 19:20 ` Isaac Boukris
  2016-10-31 19:31   ` David Miller
  2016-11-12  7:17 ` [PATCH] iproute2: ss: " Stephen Hemminger
  1 sibling, 1 reply; 9+ messages in thread
From: Isaac Boukris @ 2016-10-29 19:20 UTC (permalink / raw)
  To: stephen, davem, netdev, linux-kernel; +Cc: Isaac Boukris

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 <iboukris@gmail.com>
---
 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

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

* Re: [PATCH] unix: escape all null bytes in abstract unix domain socket
  2016-10-29 19:20 ` [PATCH] unix: " Isaac Boukris
@ 2016-10-31 19:31   ` David Miller
  2016-11-01  0:56     ` Isaac Boukris
  0 siblings, 1 reply; 9+ messages in thread
From: David Miller @ 2016-10-31 19:31 UTC (permalink / raw)
  To: iboukris; +Cc: stephen, netdev, linux-kernel

From: Isaac Boukris <iboukris@gmail.com>
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 <iboukris@gmail.com>
 ...
> @@ -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.

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

* Re: [PATCH] unix: escape all null bytes in abstract unix domain socket
  2016-10-31 19:31   ` David Miller
@ 2016-11-01  0:56     ` Isaac Boukris
  0 siblings, 0 replies; 9+ messages in thread
From: Isaac Boukris @ 2016-11-01  0:56 UTC (permalink / raw)
  To: David Miller; +Cc: Stephen Hemminger, netdev, linux-kernel

Hi David, thanks for looking at it.

On Mon, Oct 31, 2016 at 9:31 PM, David Miller <davem@davemloft.net> wrote:
> From: Isaac Boukris <iboukris@gmail.com>
> 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 <iboukris@gmail.com>
>  ...
>> @@ -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.

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

* Re: [PATCH] iproute2: ss: escape all null bytes in abstract unix domain socket
  2016-10-29 19:20 [PATCH] iproute2: ss: escape all null bytes in abstract unix domain socket Isaac Boukris
  2016-10-29 19:20 ` [PATCH] unix: " Isaac Boukris
@ 2016-11-12  7:17 ` Stephen Hemminger
  2016-12-02 18:59   ` Eric Dumazet
  1 sibling, 1 reply; 9+ messages in thread
From: Stephen Hemminger @ 2016-11-12  7:17 UTC (permalink / raw)
  To: Isaac Boukris; +Cc: davem, netdev, linux-kernel

On Sat, 29 Oct 2016 22:20:19 +0300
Isaac Boukris <iboukris@gmail.com> 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 <iboukris@gmail.com>

Applied

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

* Re: [PATCH] iproute2: ss: escape all null bytes in abstract unix domain socket
  2016-11-12  7:17 ` [PATCH] iproute2: ss: " Stephen Hemminger
@ 2016-12-02 18:59   ` Eric Dumazet
  2016-12-02 23:18     ` Stephen Hemminger
  0 siblings, 1 reply; 9+ messages in thread
From: Eric Dumazet @ 2016-12-02 18:59 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Isaac Boukris, davem, netdev, linux-kernel

On Sat, 2016-11-12 at 10:17 +0300, Stephen Hemminger wrote:
> On Sat, 29 Oct 2016 22:20:19 +0300
> Isaac Boukris <iboukris@gmail.com> 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 <iboukris@gmail.com>
> 
> 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

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

* Re: [PATCH] iproute2: ss: escape all null bytes in abstract unix domain socket
  2016-12-02 18:59   ` Eric Dumazet
@ 2016-12-02 23:18     ` Stephen Hemminger
  2016-12-02 23:24       ` Eric Dumazet
  0 siblings, 1 reply; 9+ messages in thread
From: Stephen Hemminger @ 2016-12-02 23:18 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: Isaac Boukris, davem, netdev, linux-kernel

On Fri, 02 Dec 2016 10:59:56 -0800
Eric Dumazet <eric.dumazet@gmail.com> wrote:

> On Sat, 2016-11-12 at 10:17 +0300, Stephen Hemminger wrote:
> > On Sat, 29 Oct 2016 22:20:19 +0300
> > Isaac Boukris <iboukris@gmail.com> 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 <iboukris@gmail.com>  
> > 
> > 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

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

* Re: [PATCH] iproute2: ss: escape all null bytes in abstract unix domain socket
  2016-12-02 23:18     ` Stephen Hemminger
@ 2016-12-02 23:24       ` Eric Dumazet
  2016-12-05  5:38         ` Isaac Boukris
  0 siblings, 1 reply; 9+ messages in thread
From: Eric Dumazet @ 2016-12-02 23:24 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Isaac Boukris, davem, netdev

On Fri, 2016-12-02 at 15:18 -0800, Stephen Hemminger wrote:
>                                     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

Right, thanks !

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

* Re: [PATCH] iproute2: ss: escape all null bytes in abstract unix domain socket
  2016-12-02 23:24       ` Eric Dumazet
@ 2016-12-05  5:38         ` Isaac Boukris
  0 siblings, 0 replies; 9+ messages in thread
From: Isaac Boukris @ 2016-12-05  5:38 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: Stephen Hemminger, David Miller, netdev

On Sat, Dec 3, 2016 at 1:24 AM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> On Fri, 2016-12-02 at 15:18 -0800, Stephen Hemminger wrote:
>>                                     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
>
> Right, thanks !


Thanks for notifying me. Sorry for the bug and thanks for the fix!

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

end of thread, other threads:[~2016-12-05  5:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-29 19:20 [PATCH] iproute2: ss: escape all null bytes in abstract unix domain socket Isaac Boukris
2016-10-29 19:20 ` [PATCH] unix: " Isaac Boukris
2016-10-31 19:31   ` David Miller
2016-11-01  0:56     ` Isaac Boukris
2016-11-12  7:17 ` [PATCH] iproute2: ss: " Stephen Hemminger
2016-12-02 18:59   ` Eric Dumazet
2016-12-02 23:18     ` Stephen Hemminger
2016-12-02 23:24       ` Eric Dumazet
2016-12-05  5:38         ` Isaac Boukris

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.