netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Antonio Quartulli <a@unstable.cc>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: netdev@vger.kernel.org,
	Stephen Hemminger <stephen@networkplumber.org>,
	Phil Sutter <phil@nwl.cc>
Subject: Re: [iproute2 2/2] ss: fix NULL pointer access when parsing unix sockets with oldformat
Date: Sun, 7 Jan 2018 03:51:36 +0800	[thread overview]
Message-ID: <be1bd13e-1ee8-b657-2159-71173a29e52f@unstable.cc> (raw)
In-Reply-To: <20180106202818.2160a475@elisabeth>


[-- Attachment #1.1: Type: text/plain, Size: 2160 bytes --]

Hi,

On 07/01/18 03:28, Stefano Brivio wrote:
> On Sun,  7 Jan 2018 02:31:50 +0800
> Antonio Quartulli <a@unstable.cc> wrote:
> 
>> When parsing and printing the unix sockets in unix_show(),
>> if the oldformat is detected, the peer_name member of the sockstat
>> object is left uninitialized (NULL).
> 
> Luckily, it is initialized. I'd rather say:
> 
> 	[...]
> 	object is not set (NULL).

ops, you are right! "is not set" makes more sense.

> 
>> For this reason, if a filter has been specified on the command line,
>> a strcmp() will crash when trying to access it.
>>
>> Avoid crash by checking that peer_name is not NULL before
>> passing it to strcmp().
>>
>> Cc: Stefano Brivio <sbrivio@redhat.com>
>> Cc: Stephen Hemminger <stephen@networkplumber.org>
>> Signed-off-by: Antonio Quartulli <a@unstable.cc>
> 
> Fixes: 2d0e538f3e1c ("ss: Drop list traversal from unix_stats_print()")
> 
>> [...]
>>
>> diff --git a/misc/ss.c b/misc/ss.c
>> index b35859dc..29a25070 100644
>> --- a/misc/ss.c
>> +++ b/misc/ss.c
>> @@ -3711,7 +3711,10 @@ static int unix_show(struct filter *f)
>>  			};
>>  
>>  			memcpy(st.local.data, &u->name, sizeof(u->name));
>> -			if (strcmp(u->peer_name, "*"))
>> +			/* when parsing the old format rport is set to 0 and
>> +			 * therefore peer_name remains NULL
>> +			 */
> 
> Maybe this comment is a bit redundant, but I don't have a strong
> preference either.
> 

I thought explaining "why" it could be NULL would help the casual reader
understand why we do check it.
But now that we have the check, I think it's quick to understand why we
need it.

I'd leave to whoever is going to merge the match to decide to keep or
not the comment.

>> +			if (u->peer_name && strcmp(u->peer_name, "*"))
>>  				memcpy(st.remote.data, &u->peer_name,
>>  				       sizeof(u->peer_name));
>>  			if (run_ssfilter(f->f, &st) == 0) {
> 
> FWIW:
> Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
> 


Thanks a lot, Stefano!

Should I send v2 with the commit message changed? Or can we leave this
to who will merge the change?


Regards,

-- 
Antonio Quartulli


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2018-01-06 19:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-06 18:31 [iproute2 1/2] ss: fix crash when skipping disabled header field Antonio Quartulli
2018-01-06 18:31 ` [iproute2 2/2] ss: fix NULL pointer access when parsing unix sockets with oldformat Antonio Quartulli
2018-01-06 19:28   ` Stefano Brivio
2018-01-06 19:51     ` Antonio Quartulli [this message]
2018-01-06 18:53 ` [iproute2 1/2] ss: fix crash when skipping disabled header field Stefano Brivio
2018-01-09 16:03 ` Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=be1bd13e-1ee8-b657-2159-71173a29e52f@unstable.cc \
    --to=a@unstable.cc \
    --cc=netdev@vger.kernel.org \
    --cc=phil@nwl.cc \
    --cc=sbrivio@redhat.com \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).