mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Skorodumov <skorodumov.dmitry@huawei.com>
To: Paolo Abeni <pabeni@redhat.com>, <netdev@vger.kernel.org>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	Xiao Liang <shaw.leon@gmail.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Julian Vetter <julian@outer-limits.org>,
	Ido Schimmel <idosch@nvidia.com>,
	Guillaume Nault <gnault@redhat.com>,
	Eric Dumazet <edumazet@google.com>,
	Stanislav Fomichev <sdf@fomichev.me>,
	Etienne Champetier <champetier.etienne@gmail.com>,
	<linux-kernel@vger.kernel.org>
Cc: <andrey.bokhanko@huawei.com>, Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH net-next 07/12] ipvlan: Don't allow children to use IPs of main
Date: Thu, 27 Nov 2025 14:42:00 +0300	[thread overview]
Message-ID: <d67662fc-cdd1-4f48-87b6-40da838fea32@huawei.com> (raw)
In-Reply-To: <12d4a794-24f4-4201-8671-38851edb7942@redhat.com>


On 25.11.2025 17:26, Paolo Abeni wrote:
> On 11/20/25 6:49 PM, Dmitry Skorodumov wrote:
>> Remember all ip-addresses on main iface and check
>> in ipvlan_addr_busy() that addr is not used on main.
> Why?
>
> Why using in_dev_for_each_ifa_rcu()/in6_dev->addr_list is not good enough?
>
> Note that IP addtion on the main interface can race with
> ipvlan_addr_busy() even with the code you are proposing.
>
Hm.. I don't see lt:


the ipvlan_port_add_addr_event(addr) does { ipvlan_port_add_addr(addr); ipvlan_port_del_addr_ipvlans(addr); }

ipvlan_port_add_addr(addr) { lock(addrs_lock); list_add(addr); unlock(addrs_lock);}

ipvlan_port_del_addr_ipvlans(addr) { lock(addrs_lock); for_each_ipvlan ipvlan_del_addr(ipvlan, addr); unlock(addrs_lock);}


ipvlan_macnat_addr_learn(addr); { lock(addrs_lock); if !ipvlan_addr_busy(): ipvlan_remember(addr); unlock(addrs_lock); }


There is a small window when addr can be remembered on ipvlan. But with the next step in ipvlan_port_add_addr_event(), it will be cleaned up with ipvlan_port_del_addr_ipvlans()

The idea is "it is ok to allow few packets to pass the protection, but don't allow this address be white-listed for forever"

===

I tried first in_dev_for_each_ifa_rcu(), instead of remembering on main iface, but it's not easy to invent synchronization mechanic for this..

if in ipvlan_macnat_addr_learn() we Start -> (1) iterated through in_dev_for_each_ifa_rcu(); found that address is not used and (2) remembered it on ipvlan -> (3) End

there is no way how ipvlan_port_add_addr() can ensure without locks: we can be in the [1-2] stage in addr_learn. And if we try to call ipvlan_del_addr() - again,  we can be in the [1-2] stage in addr_learn


may be we could

in ipvlan_macnat_addr_learn() 

Start -> (1) iterated through in_dev_for_each_ifa_rcu(); found that address is not used and (2) remembered it on ipvlan -> (3) reiterate again through in_dev_for_each_ifa_rcu() -> End

but I think the code becomes overcomplicated with this

Dmitry


  reply	other threads:[~2025-11-27 11:42 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20251120174949.3827500-1-skorodumov.dmitry@huawei.com>
2025-11-20 17:49 ` [PATCH net-next 01/12] ipvlan: Support MACNAT mode Dmitry Skorodumov
2025-11-25 12:58   ` Paolo Abeni
2025-11-27  8:13     ` Dmitry Skorodumov
2025-11-27  8:24       ` Paolo Abeni
2025-11-20 17:49 ` [PATCH net-next 02/12] ipvlan: macnat: Handle rx mcast-ip and unicast eth Dmitry Skorodumov
2025-11-20 17:49 ` [PATCH net-next 03/12] ipvlan: Forget all IP when device goes down Dmitry Skorodumov
2025-11-20 17:49 ` [PATCH net-next 04/12] ipvlan: Support IPv6 in macnat mode Dmitry Skorodumov
2025-11-20 17:49 ` [PATCH net-next 05/12] ipvlan: Make the addrs_lock be per port Dmitry Skorodumov
2025-11-25 14:16   ` Paolo Abeni
2025-11-20 17:49 ` [PATCH net-next 06/12] ipvlan: Take addr_lock in ipvlan_open() Dmitry Skorodumov
2025-11-25 14:17   ` Paolo Abeni
2025-11-20 17:49 ` [PATCH net-next 07/12] ipvlan: Don't allow children to use IPs of main Dmitry Skorodumov
2025-11-25 14:26   ` Paolo Abeni
2025-11-27 11:42     ` Dmitry Skorodumov [this message]
2025-11-20 17:49 ` [PATCH net-next 08/12] ipvlan: const-specifier for functions that use iaddr Dmitry Skorodumov
2025-11-20 17:49 ` [PATCH net-next 09/12] ipvlan: Common code from v6/v4 validator_event Dmitry Skorodumov
2025-11-20 17:49 ` [PATCH net-next 10/12] ipvlan: common code to handle ipv6/ipv4 address events Dmitry Skorodumov
2025-11-20 17:49 ` [PATCH net-next 11/12] ipvlan: Ignore PACKET_LOOPBACK in handle_mode_l2() Dmitry Skorodumov
2025-11-25 14:30   ` Paolo Abeni
2025-12-02 10:08     ` Dmitry Skorodumov
2025-11-20 17:49 ` [PATCH net-next 12/12] selftests: net: selftest for ipvlan-macnat mode Dmitry Skorodumov
2025-11-25 14:40   ` Paolo Abeni

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=d67662fc-cdd1-4f48-87b6-40da838fea32@huawei.com \
    --to=skorodumov.dmitry@huawei.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrey.bokhanko@huawei.com \
    --cc=champetier.etienne@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gnault@redhat.com \
    --cc=idosch@nvidia.com \
    --cc=julian@outer-limits.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=shaw.leon@gmail.com \
    /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

all inboxes | Powered by JetHome®