From: Hangbin Liu <liuhangbin@gmail.com>
To: Michal Kubecek <mkubecek@suse.cz>
Cc: Phil Sutter <phil@nwl.cc>,
netdev@vger.kernel.org,
Stephen Hemminger <stephen@networkplumber.org>
Subject: Re: [PATCH iproute2 1/2] lib/libnetlink: re malloc buff if size is not enough
Date: Wed, 13 Sep 2017 17:26:58 +0800 [thread overview]
Message-ID: <20170913092657.GK5465@leo.usersys.redhat.com> (raw)
In-Reply-To: <20170912090926.j7vwhq6a57c5d6wx@unicorn.suse.cz>
Hi Michal,
Thanks a lot for all your explains. Phil has helped update the patch to support
return a newly allocated buffer. I will post it soon.
Thanks
Hangbin
On Tue, Sep 12, 2017 at 11:09:26AM +0200, Michal Kubecek wrote:
> >
> > I checked again and arpd indeed isn't a problem. It doesn't seem to call
> > any of the two functions (directly or indirectly) and while it's linked
> > with "-lpthread", it's not really multithreaded.
> >
> > But my concern was rather about other potential users of libnetlink
> > (i.e. those which are not part of iproute2). I must admit, though, that
> > I'm not sure if libnetlink code is reentrant as of now. (And people are
> > discouraged from using it in its own manual page.)
> >
> > That being said, I still like Phil's idea for a different reason. While
> > investigating the issue with "ip link show dev eth ..." which led me to
> > commit 6599162b958e ("iplink: check for message truncation in
> > iplink_get()"), I quickly peeked at some other callers of rtnl_talk()
> > and I'm afraid there may be others which wouldn't handle truncated
> > message correctly. I assume the maxlen argument was always chosen to be
> > sufficient for any expected messages but as the example of iplink_get()
> > shows, messages returned by kernel my grow over time.
> >
> > That's why I like the idea of __rtnl_talk() returning a pointer to newly
> > allocated buffer (of sufficient size) rather than copying the response
> > into a buffer provided by caller and potentially truncating it.
>
> I'm sorry, I managed to forget that your patch 2 does already address
> this problem. But the fact that any caller must keep in mind that he
> must not call the same function again until the previous response is no
> longer needed still feels like a trap. It's something you need to keep
> in mind (where "you" in fact means any future contributor) and it's
> easy to forget. That's why I prefer the reentrant functions like
> strerror_r() or localtime_r() even in code which is not intended to be
> multithreaded. Getting an object which is "mine" to do with whatever
> I want until I no longer need it feels like a cleaner interface to me.
>
> Michal Kubecek
>
next prev parent reply other threads:[~2017-09-13 9:27 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-08 10:14 [PATCH iproute2 0/2] malloc correct buff at run time Hangbin Liu
2017-09-08 10:14 ` [PATCH iproute2 1/2] lib/libnetlink: re malloc buff if size is not enough Hangbin Liu
2017-09-08 11:02 ` Phil Sutter
2017-09-08 12:32 ` Michal Kubecek
2017-09-08 14:01 ` Hangbin Liu
2017-09-08 14:51 ` Phil Sutter
2017-09-11 7:19 ` Hangbin Liu
2017-09-12 8:47 ` Michal Kubecek
2017-09-12 9:09 ` Michal Kubecek
2017-09-13 9:26 ` Hangbin Liu [this message]
2017-09-08 10:14 ` [PATCH iproute2 2/2] lib/libnetlink: update rtnl_talk to support malloc buff at run time Hangbin Liu
2017-09-08 11:06 ` Phil Sutter
2017-09-08 13:26 ` Hangbin Liu
2017-09-08 12:03 ` [PATCH iproute2 0/2] malloc correct " Michal Kubecek
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=20170913092657.GK5465@leo.usersys.redhat.com \
--to=liuhangbin@gmail.com \
--cc=mkubecek@suse.cz \
--cc=netdev@vger.kernel.org \
--cc=phil@nwl.cc \
--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).