From: Vadim Kochan <vadim4j@gmail.com>
To: "Rustad, Mark D" <mark.d.rustad@intel.com>
Cc: Vadim Kochan <vadim4j@gmail.com>, Marc Dietrich <marvin24@gmx.de>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: "ss -p" segfaults
Date: Thu, 16 Jul 2015 01:22:38 +0300 [thread overview]
Message-ID: <20150715222238.GA13019@angus-think.lan> (raw)
In-Reply-To: <20150715185751.GA19820@angus-think.lan>
On Wed, Jul 15, 2015 at 09:57:51PM +0300, Vadim Kochan wrote:
> On Wed, Jul 15, 2015 at 06:52:49PM +0000, Rustad, Mark D wrote:
> > > On Jul 15, 2015, at 9:49 AM, Rustad, Mark D <mark.d.rustad@intel.com> wrote:
> > >
> > >> On Jul 15, 2015, at 8:12 AM, Vadim Kochan <vadim4j@gmail.com> wrote:
> > >> Would you please check this fix ?
> > >>
> > >> diff --git a/misc/ss.c b/misc/ss.c
> > >> index 03f92fa..3a826e4 100644
> > >> --- a/misc/ss.c
> > >> +++ b/misc/ss.c
> > >> @@ -683,8 +683,8 @@ static inline void sock_addr_set_str(inet_prefix *prefix, char **ptr)
> > >>
> > >> static inline char *sock_addr_get_str(const inet_prefix *prefix)
> > >> {
> > >> - char *tmp ;
> > >> - memcpy(&tmp, prefix->data, sizeof(char *));
> > >> + char *tmp;
> > >> + memcpy(&tmp, &prefix->data[0], sizeof(char *));
> > >> return tmp;
> > >> }
> > >
> > > That surely is not a fix! The destination of the memcpy is the address of an uninitialized stack variable! Both versions are equally bad.
> >
> > I probably over-reacted, but using memcpy to access a pointer in this way is just ugly. For one thing, it circumvents any sanity-checking that the compiler can do. And changing the prefix->data to &prefix->data[0] should be exactly the same thing and therefore should not fix anything. Anyway, never mind that.
> >
> > Looking at more of the code, it looks to me like the the string pointer in data can sometimes point to a literal string instead of allocated memory when proc is in use. Free would not be happy with that. Look at the use of variable peer in function unix_stats_print.
> >
> Yes that right, I am already looking on this ...
> > --
> > Mark Rustad, Networking Division, Intel Corporation
> >
I did partially revert of the buggy commit and it does not crash, but I will do
more testing, and after will send the patch and will try to prepare some
test scripts for ss.
The crash appears only if to dump processes info from /proc, which might
be caused that netlink stats returned error, probably by wrong request
(not supported attribute or flag ?).
next prev parent reply other threads:[~2015-07-15 22:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-15 14:09 "ss -p" segfaults Marc Dietrich
2015-07-15 15:02 ` Vadim Kochan
2015-07-15 15:12 ` Vadim Kochan
2015-07-15 16:49 ` Rustad, Mark D
2015-07-15 18:52 ` Rustad, Mark D
2015-07-15 18:57 ` Vadim Kochan
2015-07-15 22:22 ` Vadim Kochan [this message]
2015-07-16 6:37 ` Marc Dietrich
[not found] <55AC9E8C.7040200@openmailbox.org>
2015-07-20 17:31 ` j.ps
2015-07-20 18:14 ` Andreas Schwab
-- strict thread matches above, loose matches on Subject: below --
2015-07-21 9:50 Segmentation fault in iproute2 ss -p (versions 4.0.0, 4.1.0 and 4.1.1) j.ps
2015-07-21 9:54 ` "ss -p" segfaults j.ps
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=20150715222238.GA13019@angus-think.lan \
--to=vadim4j@gmail.com \
--cc=mark.d.rustad@intel.com \
--cc=marvin24@gmx.de \
--cc=netdev@vger.kernel.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).