diff options
author | Jiri Pirko <jiri@resnulli.us> | 2015-01-14 12:15:30 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-01-14 16:53:57 -0500 |
commit | b0d11b42785b70e19bc6a3122eead3f7969a7589 (patch) | |
tree | 06ca980eca49523be349e19fdbd50c2e090d7f6f /drivers/net/team/team.c | |
parent | 1ba398041f5b5a15456ea20a9ba3ff80b6a4e7d1 (diff) |
team: avoid possible underflow of count_pending value for notify_peers and mcast_rejoin
This patch is fixing a race condition that may cause setting
count_pending to -1, which results in unwanted big bulk of arp messages
(in case of "notify peers").
Consider following scenario:
count_pending == 2
CPU0 CPU1
team_notify_peers_work
atomic_dec_and_test (dec count_pending to 1)
schedule_delayed_work
team_notify_peers
atomic_add (adding 1 to count_pending)
team_notify_peers_work
atomic_dec_and_test (dec count_pending to 1)
schedule_delayed_work
team_notify_peers_work
atomic_dec_and_test (dec count_pending to 0)
schedule_delayed_work
team_notify_peers_work
atomic_dec_and_test (dec count_pending to -1)
Fix this race by using atomic_dec_if_positive - that will prevent
count_pending running under 0.
Fixes: fc423ff00df3a1955441 ("team: add peer notification")
Fixes: 492b200efdd20b8fcfd ("team: add support for sending multicast rejoins")
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: Jiri Benc <jbenc@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/team/team.c')
-rw-r--r-- | drivers/net/team/team.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c index 93e224217e24..f7ff493f1e73 100644 --- a/drivers/net/team/team.c +++ b/drivers/net/team/team.c | |||
@@ -629,6 +629,7 @@ static int team_change_mode(struct team *team, const char *kind) | |||
629 | static void team_notify_peers_work(struct work_struct *work) | 629 | static void team_notify_peers_work(struct work_struct *work) |
630 | { | 630 | { |
631 | struct team *team; | 631 | struct team *team; |
632 | int val; | ||
632 | 633 | ||
633 | team = container_of(work, struct team, notify_peers.dw.work); | 634 | team = container_of(work, struct team, notify_peers.dw.work); |
634 | 635 | ||
@@ -636,9 +637,14 @@ static void team_notify_peers_work(struct work_struct *work) | |||
636 | schedule_delayed_work(&team->notify_peers.dw, 0); | 637 | schedule_delayed_work(&team->notify_peers.dw, 0); |
637 | return; | 638 | return; |
638 | } | 639 | } |
640 | val = atomic_dec_if_positive(&team->notify_peers.count_pending); | ||
641 | if (val < 0) { | ||
642 | rtnl_unlock(); | ||
643 | return; | ||
644 | } | ||
639 | call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, team->dev); | 645 | call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, team->dev); |
640 | rtnl_unlock(); | 646 | rtnl_unlock(); |
641 | if (!atomic_dec_and_test(&team->notify_peers.count_pending)) | 647 | if (val) |
642 | schedule_delayed_work(&team->notify_peers.dw, | 648 | schedule_delayed_work(&team->notify_peers.dw, |
643 | msecs_to_jiffies(team->notify_peers.interval)); | 649 | msecs_to_jiffies(team->notify_peers.interval)); |
644 | } | 650 | } |
@@ -669,6 +675,7 @@ static void team_notify_peers_fini(struct team *team) | |||
669 | static void team_mcast_rejoin_work(struct work_struct *work) | 675 | static void team_mcast_rejoin_work(struct work_struct *work) |
670 | { | 676 | { |
671 | struct team *team; | 677 | struct team *team; |
678 | int val; | ||
672 | 679 | ||
673 | team = container_of(work, struct team, mcast_rejoin.dw.work); | 680 | team = container_of(work, struct team, mcast_rejoin.dw.work); |
674 | 681 | ||
@@ -676,9 +683,14 @@ static void team_mcast_rejoin_work(struct work_struct *work) | |||
676 | schedule_delayed_work(&team->mcast_rejoin.dw, 0); | 683 | schedule_delayed_work(&team->mcast_rejoin.dw, 0); |
677 | return; | 684 | return; |
678 | } | 685 | } |
686 | val = atomic_dec_if_positive(&team->mcast_rejoin.count_pending); | ||
687 | if (val < 0) { | ||
688 | rtnl_unlock(); | ||
689 | return; | ||
690 | } | ||
679 | call_netdevice_notifiers(NETDEV_RESEND_IGMP, team->dev); | 691 | call_netdevice_notifiers(NETDEV_RESEND_IGMP, team->dev); |
680 | rtnl_unlock(); | 692 | rtnl_unlock(); |
681 | if (!atomic_dec_and_test(&team->mcast_rejoin.count_pending)) | 693 | if (val) |
682 | schedule_delayed_work(&team->mcast_rejoin.dw, | 694 | schedule_delayed_work(&team->mcast_rejoin.dw, |
683 | msecs_to_jiffies(team->mcast_rejoin.interval)); | 695 | msecs_to_jiffies(team->mcast_rejoin.interval)); |
684 | } | 696 | } |