]> git.baikalelectronics.ru Git - kernel.git/commit
team: avoid possible underflow of count_pending value for notify_peers and mcast_rejoin
authorJiri Pirko <jiri@resnulli.us>
Wed, 14 Jan 2015 17:15:30 +0000 (18:15 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 14 Jan 2015 21:53:57 +0000 (16:53 -0500)
commit6e5fbee6f901598d1d98942c28c96c1e2bbbc2b4
tree06ca980eca49523be349e19fdbd50c2e090d7f6f
parent7113aa39bb5e7efaa866085e3a55d6d3b4c96727
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: 05d961a5cebed21b5cad ("team: add peer notification")
Fixes: 4c74850fa685ec9904e ("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>
drivers/net/team/team.c