From: "Timo Teräs" <timo.teras@iki.fi>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH] ipv4: synchronize bind() with RTM_NEWADDR notifications
Date: Thu, 21 Oct 2010 13:41:37 +0300 [thread overview]
Message-ID: <4CC018E1.3000906@iki.fi> (raw)
In-Reply-To: <1287656753.6871.46.camel@edumazet-laptop>
On 10/21/2010 01:25 PM, Eric Dumazet wrote:
> Le jeudi 21 octobre 2010 à 13:12 +0300, Timo Teräs a écrit :
>> Otherwise we have race condition to user land:
>> 1. process A changes IP address
>> 2. kernel sends RTM_NEWADDR
>> 3. process B gets notification
>> 4. process B tries to bind() to new IP but that fails with
>> EADDRNOTAVAIL because FIB is not yet updated and inet_addr_type() in
>> inet_bind() does not recognize the IP as local
>> 5. kernel calls inetaddr_chain notifiers which updates FIB
>>
>> IPv6 side seems to handle the notifications properly: bind()
>> immediately after RTM_NEWADDR succeeds as expected. This is because
>> ipv6_chk_addr() uses inet6_addr_lst which is updated before address
>> notification.
>>
>> Signed-off-by: Timo Teräs <timo.teras@iki.fi>
>> ---
>> net/ipv4/af_inet.c | 9 +++++++++
>> net/ipv6/af_inet6.c | 4 +++-
>> 2 files changed, 12 insertions(+), 1 deletions(-)
>>
>> diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
>> index 6a1100c..21200e4 100644
>> --- a/net/ipv4/af_inet.c
>> +++ b/net/ipv4/af_inet.c
>> @@ -466,6 +466,15 @@ int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
>> if (addr_len < sizeof(struct sockaddr_in))
>> goto out;
>>
>> + /* Acquire rtnl_lock to synchronize with possible simultaneous
>> + * IP-address changes. This is needed because when RTM_NEWADDR
>> + * is sent the new IP is not yet in FIB, but alas inet_addr_type
>> + * checks the address type using FIB. Acquiring rtnl lock once
>> + * makse sure that any address for which RTM_NEWADDR was sent
>> + * earlier exists also in FIB. */
>> + rtnl_lock();
>> + rtnl_unlock();
>
> You must be kidding ?
>
> Really, this is a hot path...
Is inet_bind() called from non-userland context? If yes, then this is a
bad idea. Otherwise I don't think it's that hot path...
The other idea of doing notifier calls before RTM_NEWADDR sending is
worse because it changes ordering of userland visible netlink notifications.
This looked like the easiest way out. If this is unacceptable, I guess
we are left with changing inet_addr_type() to not use FIB.
Or is there better ideas?
next prev parent reply other threads:[~2010-10-21 10:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-21 10:12 [PATCH] ipv4: synchronize bind() with RTM_NEWADDR notifications Timo Teräs
2010-10-21 10:25 ` Eric Dumazet
2010-10-21 10:41 ` Timo Teräs [this message]
2010-10-21 10:50 ` David Miller
2010-10-21 10:58 ` Timo Teräs
2010-10-21 11:03 ` David Miller
2010-10-21 11:29 ` Timo Teräs
2010-10-21 11:34 ` David Miller
2010-10-21 11:57 ` Timo Teräs
2010-10-21 13:06 ` [PATCH v2] " Timo Teräs
2010-10-21 14:10 ` Eric Dumazet
2010-10-21 19:01 ` Timo Teräs
2010-10-21 11:12 ` [PATCH] " Eric Dumazet
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=4CC018E1.3000906@iki.fi \
--to=timo.teras@iki.fi \
--cc=eric.dumazet@gmail.com \
--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).