net: ipv4: fix circular-list infinite loop
Subsystems (4)
cover net: ipv4: fix circular-list infinite loop
Tariq and Ran reported a regression caused by net-next commit 2638eb8b50cf ("net: ipv4: provide __rcu annotation for ifa_list").
This happens when net.ipv4.conf.$dev.promote_secondaries sysctl is enabled -- we can arrange for ifa->next to point at ifa, so next process that tries to walk the list loops forever.
Fix this and extend rtnetlink.sh with a small test case for this.
Florian Westphal (2):
net: ipv4: fix infinite loop on secondary addr promotion
selftests: rtnetlink: add small test case with 'promote_secondaries' enabled
net/ipv4/devinet.c | 3 ++- tools/testing/selftests/net/rtnetlink.sh | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-)
PATCH 1/2 net: ipv4: fix infinite loop on secondary addr promotion
secondary address promotion causes infinite loop -- it arranges for ifa->ifa_next to point back to itself.
Problem is that 'prev_prom' and 'last_prim' might point at the same entry, so 'last_sec' pointer must be obtained after prev_prom->next update.
--- net/ipv4/devinet.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/devinet.c +2 -1
@@ -428,8 +428,9 @@ static void __inet_del_ifa(struct in_device *in_dev,if (prev_prom) {struct in_ifaddr *last_sec; - last_sec =rtnl_dereference (last_prim->ifa_next);rcu_assign_pointer (prev_prom->ifa_next, next_sec); + + last_sec =rtnl_dereference (last_prim->ifa_next);rcu_assign_pointer (promote->ifa_next, last_sec);rcu_assign_pointer (last_prim->ifa_next, promote); }
Signature · 1 line
2.21.0
PATCH 2/2 selftests: rtnetlink: add small test case with 'promote_secondaries' enabled
In reply to Florian WestphalThis exercises the 'promote_secondaries' code path.
Without previous fix, this triggers infinite loop/soft lockup:
ifconfig process spinning at 100%, never to return.
--- tools/testing/selftests/net/rtnetlink.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
tools/testing/selftests/net/rtnetlink.sh +20 -0
@@ -269,6 +269,25 @@ kci_test_addrlft() echo "PASS: preferred_lft addresses have expired" } +kci_test_promote_secondaries() +{ + promote=$(sysctl -n net.ipv4.conf.$devdummy.promote_secondaries) + + sysctl -q net.ipv4.conf.$devdummy.promote_secondaries=1 + + for i in $(seq 2 254);do + IP="10.23.11.$i" + ip -f inet addr add $IP/16 brd + dev "$devdummy" + ifconfig "$devdummy" $IP netmask 255.255.0.0 + done + + ip addr flush dev "$devdummy" + + [ $promote -eq 0 ] && sysctl -q net.ipv4.conf.$devdummy.promote_secondaries=0 + + echo "PASS: promote_secondaries complete" +} + kci_test_addrlabel() { ret=0
@@ -1161,6 +1180,7 @@ kci_test_rtnl() kci_test_polrouting kci_test_route_get kci_test_addrlft + kci_test_promote_secondaries kci_test_tc kci_test_gre kci_test_gretap
Signature · 1 line
2.21.0
David Miller
maintainerFrom: Florian Westphal <[email protected]>
Date: Thu, 27 Jun 2019 14:03:31 +0200
Quoted 8 lines
Tariq and Ran reported a regression caused by net-next commit
2638eb8b50cf("net: ipv4: provide__rcuannotation forifa_list").This happens when net.ipv4.conf.$dev.promote_secondaries sysctl is enabled -- we can arrange for
ifa->nextto point at ifa, so next process that tries to walk the list loops forever.Fix this and extend
rtnetlink.shwith a small test case for this.
Series applied, thanks Florian.
Quoted 6 lines · David Miller
From: Florian Westphal <[email protected]>
Date: Thu, 27 Jun 2019 14:03:31 +0200Quoted 3 lines
Tariq and Ran reported a regression caused by net-next commit
2638eb8b50cf("net: ipv4: provide__rcuannotation forifa_list").
Quoted 8 lines
Quoted 5 lines
This happens when net.ipv4.conf.$dev.promote_secondaries sysctl is enabled -- we can arrange for
ifa->nextto point at ifa, so next process that tries to walk the list loops forever.Fix this and extend
rtnetlink.shwith a small test case for this.Series applied, thanks Florian.
Thanks Florian!
Ran, please test and update.
Tariq
Quoted 25 lines
-----Original Message-----
From: Tariq Toukan
Sent: Sunday, June 30, 2019 10:57
To: David Miller <[email protected]>; [email protected]
Cc: [email protected]; Ran Rozenstein <[email protected]>; Tariq Toukan <[email protected]>
Subject: Re: [PATCH net-next 0/2] net: ipv4: fix circular-list infinite loopQuoted 12 lines · David Miller
From: Florian Westphal <[email protected]>
Date: Thu, 27 Jun 2019 14:03:31 +0200Quoted 8 lines
Tariq and Ran reported a regression caused by net-next commit
2638eb8b50cf("net: ipv4: provide__rcuannotation forifa_list").This happens when net.ipv4.conf.$dev.promote_secondaries sysctl is enabled -- we can arrange for
ifa->nextto point at ifa, so next process that tries to walk the list loops forever.Fix this and extend
rtnetlink.shwith a small test case for this.
Quoted 8 lines
Quoted 2 lines
Series applied, thanks Florian.
Thanks Florian!
Ran, please test and update.
Tariq
Thanks Florian.
Didn't reproduce tonight with the fixes.
Ran.
Quoted 30 lines · Ran Rozenstein
Quoted 30 lines
-----Original Message-----
From: Tariq Toukan
Sent: Sunday, June 30, 2019 10:57
To: David Miller <[email protected]>; [email protected]
Cc: [email protected]; Ran Rozenstein <[email protected]>; Tariq Toukan <[email protected]>
Subject: Re: [PATCH net-next 0/2] net: ipv4: fix circular-list infinite loopQuoted 6 lines · David Miller
From: Florian Westphal <[email protected]>
Date: Thu, 27 Jun 2019 14:03:31 +0200Quoted 3 lines
Tariq and Ran reported a regression caused by net-next commit
2638eb8b50cf("net: ipv4: provide__rcuannotation forifa_list").Quoted 8 lines
Quoted 5 lines
This happens when net.ipv4.conf.$dev.promote_secondaries sysctl is enabled -- we can arrange for
ifa->nextto point at ifa, so next process that tries to walk the list loops forever.Fix this and extend
rtnetlink.shwith a small test case for this.Series applied, thanks Florian.
Thanks Florian!
Quoted 9 lines
Quoted 3 lines
Ran, please test and update.
Tariq
Thanks Florian.
Didn't reproduce tonight with the fixes.Ran.
Sounds good!
Thanks,
Tariq