Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
team: avoid possible underflow of count_pending value for notify_peer…
Browse files Browse the repository at this point in the history
…s and mcast_rejoin

[ Upstream commit b0d11b4 ]

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: fc423ff ("team: add peer notification")
Fixes: 492b200  ("team: add support for sending multicast rejoins")
Signed-off-by: Jiri Pirko <[email protected]>
Signed-off-by: Jiri Benc <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
jpirko authored and gregkh committed Jan 27, 2015
1 parent ff9df48 commit 58f2f9c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions drivers/net/team/team.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,16 +629,22 @@ static int team_change_mode(struct team *team, const char *kind)
static void team_notify_peers_work(struct work_struct *work)
{
struct team *team;
int val;

team = container_of(work, struct team, notify_peers.dw.work);

if (!rtnl_trylock()) {
schedule_delayed_work(&team->notify_peers.dw, 0);
return;
}
val = atomic_dec_if_positive(&team->notify_peers.count_pending);
if (val < 0) {
rtnl_unlock();
return;
}
call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, team->dev);
rtnl_unlock();
if (!atomic_dec_and_test(&team->notify_peers.count_pending))
if (val)
schedule_delayed_work(&team->notify_peers.dw,
msecs_to_jiffies(team->notify_peers.interval));
}
Expand Down Expand Up @@ -669,16 +675,22 @@ static void team_notify_peers_fini(struct team *team)
static void team_mcast_rejoin_work(struct work_struct *work)
{
struct team *team;
int val;

team = container_of(work, struct team, mcast_rejoin.dw.work);

if (!rtnl_trylock()) {
schedule_delayed_work(&team->mcast_rejoin.dw, 0);
return;
}
val = atomic_dec_if_positive(&team->mcast_rejoin.count_pending);
if (val < 0) {
rtnl_unlock();
return;
}
call_netdevice_notifiers(NETDEV_RESEND_IGMP, team->dev);
rtnl_unlock();
if (!atomic_dec_and_test(&team->mcast_rejoin.count_pending))
if (val)
schedule_delayed_work(&team->mcast_rejoin.dw,
msecs_to_jiffies(team->mcast_rejoin.interval));
}
Expand Down

0 comments on commit 58f2f9c

Please sign in to comment.