From: Ben Hutchings <ben@decadent.org.uk>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: akpm@linux-foundation.org, "Jay Vosburgh" <fubar@us.ibm.com>,
"nikolay@redhat.com" <nikolay@redhat.com>,
"David S. Miller" <davem@davemloft.net>
Subject: [58/74] bonding: fix miimon and arp_interval delayed work race conditions
Date: Sun, 07 Apr 2013 23:45:43 +0100 [thread overview]
Message-ID: <lsq.1365374743.574335065@decadent.org.uk> (raw)
In-Reply-To: <lsq.1365374742.214522651@decadent.org.uk>
3.2.43-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "nikolay@redhat.com" <nikolay@redhat.com>
[ Upstream commit fbb0c41b814d497c656fc7be9e35456f139cb2fb ]
First I would give three observations which will be used later.
Observation 1: if (delayed_work_pending(wq)) cancel_delayed_work(wq)
This usage is wrong because the pending bit is cleared just before the
work's fn is executed and if the function re-arms itself we might end up
with the work still running. It's safe to call cancel_delayed_work_sync()
even if the work is not queued at all.
Observation 2: Use of INIT_DELAYED_WORK()
Work needs to be initialized only once prior to (de/en)queueing.
Observation 3: IFF_UP is set only after ndo_open is called
Related race conditions:
1. Race between bonding_store_miimon() and bonding_store_arp_interval()
Because of Obs.1 we can end up having both works enqueued.
2. Multiple races with INIT_DELAYED_WORK()
Since the works are not protected by anything between INIT_DELAYED_WORK()
and calls to (en/de)queue it is possible for races between the following
functions:
(races are also possible between the calls to INIT_DELAYED_WORK()
and workqueue code)
bonding_store_miimon() - bonding_store_arp_interval(), bond_close(),
bond_open(), enqueued functions
bonding_store_arp_interval() - bonding_store_miimon(), bond_close(),
bond_open(), enqueued functions
3. By Obs.1 we need to change bond_cancel_all()
Bugs 1 and 2 are fixed by moving all work initializations in bond_open
which by Obs. 2 and Obs. 3 and the fact that we make sure that all works
are cancelled in bond_close(), is guaranteed not to have any work
enqueued.
Also RTNL lock is now acquired in bonding_store_miimon/arp_interval so
they can't race with bond_close and bond_open. The opposing work is
cancelled only if the IFF_UP flag is set and it is cancelled
unconditionally. The opposing work is already cancelled if the interface
is down so no need to cancel it again. This way we don't need new
synchronizations for the bonding workqueue. These bugs (and fixes) are
tied together and belong in the same patch.
Note: I have left 1 line intentionally over 80 characters (84) because I
didn't like how it looks broken down. If you'd prefer it otherwise,
then simply break it.
v2: Make description text < 75 columns
Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com>
Signed-off-by: Jay Vosburgh <fubar@us.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
drivers/net/bonding/bond_main.c | 88 ++++++++++++----------------------------
drivers/net/bonding/bond_sysfs.c | 34 +++++-----------
2 files changed, 36 insertions(+), 86 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 63e3c47..2d9faa1 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -3422,6 +3422,28 @@ static int bond_xmit_hash_policy_l2(struct sk_buff *skb, int count)
/*-------------------------- Device entry points ----------------------------*/
+static void bond_work_init_all(struct bonding *bond)
+{
+ INIT_DELAYED_WORK(&bond->mcast_work,
+ bond_resend_igmp_join_requests_delayed);
+ INIT_DELAYED_WORK(&bond->alb_work, bond_alb_monitor);
+ INIT_DELAYED_WORK(&bond->mii_work, bond_mii_monitor);
+ if (bond->params.mode == BOND_MODE_ACTIVEBACKUP)
+ INIT_DELAYED_WORK(&bond->arp_work, bond_activebackup_arp_mon);
+ else
+ INIT_DELAYED_WORK(&bond->arp_work, bond_loadbalance_arp_mon);
+ INIT_DELAYED_WORK(&bond->ad_work, bond_3ad_state_machine_handler);
+}
+
+static void bond_work_cancel_all(struct bonding *bond)
+{
+ cancel_delayed_work_sync(&bond->mii_work);
+ cancel_delayed_work_sync(&bond->arp_work);
+ cancel_delayed_work_sync(&bond->alb_work);
+ cancel_delayed_work_sync(&bond->ad_work);
+ cancel_delayed_work_sync(&bond->mcast_work);
+}
+
static int bond_open(struct net_device *bond_dev)
{
struct bonding *bond = netdev_priv(bond_dev);
@@ -3444,41 +3466,27 @@ static int bond_open(struct net_device *bond_dev)
}
read_unlock(&bond->lock);
- INIT_DELAYED_WORK(&bond->mcast_work, bond_resend_igmp_join_requests_delayed);
+ bond_work_init_all(bond);
if (bond_is_lb(bond)) {
/* bond_alb_initialize must be called before the timer
* is started.
*/
- if (bond_alb_initialize(bond, (bond->params.mode == BOND_MODE_ALB))) {
- /* something went wrong - fail the open operation */
+ if (bond_alb_initialize(bond, (bond->params.mode == BOND_MODE_ALB)))
return -ENOMEM;
- }
-
- INIT_DELAYED_WORK(&bond->alb_work, bond_alb_monitor);
queue_delayed_work(bond->wq, &bond->alb_work, 0);
}
- if (bond->params.miimon) { /* link check interval, in milliseconds. */
- INIT_DELAYED_WORK(&bond->mii_work, bond_mii_monitor);
+ if (bond->params.miimon) /* link check interval, in milliseconds. */
queue_delayed_work(bond->wq, &bond->mii_work, 0);
- }
if (bond->params.arp_interval) { /* arp interval, in milliseconds. */
- if (bond->params.mode == BOND_MODE_ACTIVEBACKUP)
- INIT_DELAYED_WORK(&bond->arp_work,
- bond_activebackup_arp_mon);
- else
- INIT_DELAYED_WORK(&bond->arp_work,
- bond_loadbalance_arp_mon);
-
queue_delayed_work(bond->wq, &bond->arp_work, 0);
if (bond->params.arp_validate)
bond->recv_probe = bond_arp_rcv;
}
if (bond->params.mode == BOND_MODE_8023AD) {
- INIT_DELAYED_WORK(&bond->ad_work, bond_3ad_state_machine_handler);
queue_delayed_work(bond->wq, &bond->ad_work, 0);
/* register to receive LACPDUs */
bond->recv_probe = bond_3ad_lacpdu_recv;
@@ -3493,34 +3501,10 @@ static int bond_close(struct net_device *bond_dev)
struct bonding *bond = netdev_priv(bond_dev);
write_lock_bh(&bond->lock);
-
bond->send_peer_notif = 0;
-
write_unlock_bh(&bond->lock);
- if (bond->params.miimon) { /* link check interval, in milliseconds. */
- cancel_delayed_work_sync(&bond->mii_work);
- }
-
- if (bond->params.arp_interval) { /* arp interval, in milliseconds. */
- cancel_delayed_work_sync(&bond->arp_work);
- }
-
- switch (bond->params.mode) {
- case BOND_MODE_8023AD:
- cancel_delayed_work_sync(&bond->ad_work);
- break;
- case BOND_MODE_TLB:
- case BOND_MODE_ALB:
- cancel_delayed_work_sync(&bond->alb_work);
- break;
- default:
- break;
- }
-
- if (delayed_work_pending(&bond->mcast_work))
- cancel_delayed_work_sync(&bond->mcast_work);
-
+ bond_work_cancel_all(bond);
if (bond_is_lb(bond)) {
/* Must be called only after all
* slaves have been released
@@ -4364,26 +4348,6 @@ static void bond_setup(struct net_device *bond_dev)
bond_dev->features |= bond_dev->hw_features;
}
-static void bond_work_cancel_all(struct bonding *bond)
-{
- if (bond->params.miimon && delayed_work_pending(&bond->mii_work))
- cancel_delayed_work_sync(&bond->mii_work);
-
- if (bond->params.arp_interval && delayed_work_pending(&bond->arp_work))
- cancel_delayed_work_sync(&bond->arp_work);
-
- if (bond->params.mode == BOND_MODE_ALB &&
- delayed_work_pending(&bond->alb_work))
- cancel_delayed_work_sync(&bond->alb_work);
-
- if (bond->params.mode == BOND_MODE_8023AD &&
- delayed_work_pending(&bond->ad_work))
- cancel_delayed_work_sync(&bond->ad_work);
-
- if (delayed_work_pending(&bond->mcast_work))
- cancel_delayed_work_sync(&bond->mcast_work);
-}
-
/*
* Destroy a bonding device.
* Must be under rtnl_lock when this function is called.
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index a03fde9..a549f36 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -514,6 +514,8 @@ static ssize_t bonding_store_arp_interval(struct device *d,
int new_value, ret = count;
struct bonding *bond = to_bond(d);
+ if (!rtnl_trylock())
+ return restart_syscall();
if (sscanf(buf, "%d", &new_value) != 1) {
pr_err("%s: no arp_interval value specified.\n",
bond->dev->name);
@@ -540,10 +542,6 @@ static ssize_t bonding_store_arp_interval(struct device *d,
pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
bond->dev->name, bond->dev->name);
bond->params.miimon = 0;
- if (delayed_work_pending(&bond->mii_work)) {
- cancel_delayed_work(&bond->mii_work);
- flush_workqueue(bond->wq);
- }
}
if (!bond->params.arp_targets[0]) {
pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
@@ -555,19 +553,12 @@ static ssize_t bonding_store_arp_interval(struct device *d,
* timer will get fired off when the open function
* is called.
*/
- if (!delayed_work_pending(&bond->arp_work)) {
- if (bond->params.mode == BOND_MODE_ACTIVEBACKUP)
- INIT_DELAYED_WORK(&bond->arp_work,
- bond_activebackup_arp_mon);
- else
- INIT_DELAYED_WORK(&bond->arp_work,
- bond_loadbalance_arp_mon);
-
- queue_delayed_work(bond->wq, &bond->arp_work, 0);
- }
+ cancel_delayed_work_sync(&bond->mii_work);
+ queue_delayed_work(bond->wq, &bond->arp_work, 0);
}
out:
+ rtnl_unlock();
return ret;
}
static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR,
@@ -963,6 +954,8 @@ static ssize_t bonding_store_miimon(struct device *d,
int new_value, ret = count;
struct bonding *bond = to_bond(d);
+ if (!rtnl_trylock())
+ return restart_syscall();
if (sscanf(buf, "%d", &new_value) != 1) {
pr_err("%s: no miimon value specified.\n",
bond->dev->name);
@@ -994,10 +987,6 @@ static ssize_t bonding_store_miimon(struct device *d,
bond->params.arp_validate =
BOND_ARP_VALIDATE_NONE;
}
- if (delayed_work_pending(&bond->arp_work)) {
- cancel_delayed_work(&bond->arp_work);
- flush_workqueue(bond->wq);
- }
}
if (bond->dev->flags & IFF_UP) {
@@ -1006,15 +995,12 @@ static ssize_t bonding_store_miimon(struct device *d,
* timer will get fired off when the open function
* is called.
*/
- if (!delayed_work_pending(&bond->mii_work)) {
- INIT_DELAYED_WORK(&bond->mii_work,
- bond_mii_monitor);
- queue_delayed_work(bond->wq,
- &bond->mii_work, 0);
- }
+ cancel_delayed_work_sync(&bond->arp_work);
+ queue_delayed_work(bond->wq, &bond->mii_work, 0);
}
}
out:
+ rtnl_unlock();
return ret;
}
static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR,
next prev parent reply other threads:[~2013-04-07 23:26 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-07 22:45 [00/74] 3.2.43-rc1 review Ben Hutchings
2013-04-07 22:45 ` [03/74] UBIFS: make space fixup work in the remount case Ben Hutchings
2013-04-07 22:45 ` [41/74] virtio: console: rename cvq_lock to c_ivq_lock Ben Hutchings
2013-04-07 22:45 ` [55/74] tcp: undo spurious timeout after SACK reneging Ben Hutchings
2013-04-07 22:45 ` [35/74] b43: A fix for DMA transmission sequence errors Ben Hutchings
2013-04-07 22:45 ` [31/74] Nest rename_lock inside vfsmount_lock Ben Hutchings
2013-04-07 22:45 ` [53/74] sky2: Threshold for Pause Packet is set wrong Ben Hutchings
2013-04-07 22:45 ` [32/74] vt: synchronize_rcu() under spinlock is not nice Ben Hutchings
2013-04-07 22:45 ` [54/74] tcp: preserve ACK clocking in TSO Ben Hutchings
2013-04-07 22:45 ` [25/74] ASoC: dma-sh7760: Fix compile error Ben Hutchings
2013-04-07 22:45 ` [45/74] mm: prevent mmap_cache race in find_vma() Ben Hutchings
2013-04-07 22:45 ` [09/74] Bluetooth: Add support for atheros 04ca:3004 device to ath3k Ben Hutchings
2013-04-07 22:45 ` [56/74] 8021q: fix a potential use-after-free Ben Hutchings
2013-04-07 22:45 ` [49/74] udf: Fix bitmap overflow on large filesystems with small block size Ben Hutchings
2013-04-07 22:45 ` [27/74] SUNRPC: Add barriers to ensure read ordering in rpc_wake_up_task_queue_locked Ben Hutchings
2013-04-07 22:45 ` [34/74] can: sja1000: fix define conflict on SH Ben Hutchings
2013-04-07 22:45 ` [04/74] Bluetooth: Add support for IMC Networks [13d3:3393] Ben Hutchings
2013-04-07 22:45 ` [40/74] tile: expect new initramfs name from hypervisor file system Ben Hutchings
2013-04-07 22:45 ` [29/74] staging: comedi: s626: fix continuous acquisition Ben Hutchings
2013-04-07 22:45 ` [07/74] Bluetooth: Add support for Foxconn / Hon Hai [0489:e056] Ben Hutchings
2013-04-07 22:45 ` [43/74] spi/mpc512x-psc: optionally keep PSC SS asserted across xfer segmensts Ben Hutchings
2013-04-07 22:45 ` [14/74] HID: usbhid: quirk for MSI GX680R led panel Ben Hutchings
2013-04-07 22:45 ` [47/74] rt2x00: error in configurations with mesh support disabled Ben Hutchings
2013-04-07 22:45 ` [26/74] IPoIB: Fix send lockup due to missed TX completion Ben Hutchings
2013-04-07 22:45 ` [44/74] EISA/PCI: Init EISA early, before PNP Ben Hutchings
2013-04-07 22:45 ` [24/74] NFSv4.1: Fix a race in pNFS layoutcommit Ben Hutchings
2013-04-07 22:45 ` [17/74] ath9k_hw: revert chainmask to user configuration after calibration Ben Hutchings
2013-04-07 22:45 ` [51/74] loop: prevent bdev freeing while device in use Ben Hutchings
2013-04-07 22:45 ` [38/74] usb: ftdi_sio: Add support for Mitsubishi FX-USB-AW/-BD Ben Hutchings
2013-04-07 22:45 ` [22/74] sysfs: handle failure path correctly for readdir() Ben Hutchings
2013-04-07 22:45 ` [52/74] sky2: Receive Overflows not counted Ben Hutchings
2013-04-07 22:45 ` [23/74] pnfs-block: removing DM device maybe cause oops when call dev_remove Ben Hutchings
2013-04-07 22:45 ` [28/74] usb: xhci: Fix TRB transfer length macro used for Event TRB Ben Hutchings
2013-04-07 22:45 ` [16/74] Bluetooth: Add support for Dell[QCA 0cf3:817a] Ben Hutchings
2013-04-07 22:45 ` [42/74] virtio: console: add locking around c_ovq operations Ben Hutchings
2013-04-07 22:45 ` [08/74] Bluetooth device 04ca:3008 should use ath3k Ben Hutchings
2013-04-07 22:45 ` [46/74] ixgbe: fix registration order of driver and DCA nofitication Ben Hutchings
2013-04-07 22:45 ` [11/74] Bluetooth: Add support for Dell[QCA 0cf3:0036] Ben Hutchings
2013-04-07 22:45 ` [30/74] nfsd4: reject "negative" acl lengths Ben Hutchings
2013-04-07 22:45 ` [50/74] NFS: nfs_getaclargs.acl_len is a size_t Ben Hutchings
2013-04-07 22:45 ` [21/74] sysfs: fix race between readdir and lseek Ben Hutchings
2013-04-07 22:45 ` [13/74] HID: usbhid: quirk for Realtek Multi-card reader Ben Hutchings
2013-04-07 22:45 ` [02/74] ASoC: imx-ssi: Fix occasional AC97 reset failure Ben Hutchings
2013-04-07 22:45 ` [05/74] Bluetooth: Add support for GC-WB300D PCIe [04ca:3006] to ath3k Ben Hutchings
2013-04-07 22:45 ` [12/74] tty: atmel_serial_probe(): index of atmel_ports[] fix Ben Hutchings
2013-04-07 22:45 ` [18/74] rtlwifi: usb: add missing freeing of skbuff Ben Hutchings
2013-04-07 22:45 ` [37/74] Btrfs: limit the global reserve to 512mb Ben Hutchings
2013-04-07 22:45 ` [15/74] HID: usbhid: fix build problem Ben Hutchings
2013-04-07 22:45 ` [36/74] tg3: fix length overflow in VPD firmware parsing Ben Hutchings
2013-04-07 22:45 ` [33/74] iommu/amd: Make sure dma_ops are set for hotplug devices Ben Hutchings
2013-04-07 22:45 ` [19/74] xen-blkback: fix dispatch_rw_block_io() error path Ben Hutchings
2013-04-07 22:45 ` [39/74] reiserfs: Fix warning and inode leak when deleting inode with xattrs Ben Hutchings
2013-04-07 22:45 ` [06/74] Bluetooth: Add support for Foxconn / Hon Hai [0489:e04e] Ben Hutchings
2013-04-07 22:45 ` [01/74] clockevents: Don't allow dummy broadcast timers Ben Hutchings
2013-04-07 22:45 ` [10/74] Bluetooth: Device 0cf3:3008 should map AR 3012 Ben Hutchings
2013-04-07 22:45 ` [48/74] key: Fix resource leak Ben Hutchings
2013-04-07 22:45 ` [20/74] net/irda: add missing error path release_sock call Ben Hutchings
2013-04-07 22:45 ` [63/74] aoe: reserve enough headroom on skbs Ben Hutchings
2013-04-07 22:45 ` [61/74] bonding: fix disabling of arp_interval and miimon Ben Hutchings
2013-04-07 22:45 ` [72/74] smsc75xx: fix jumbo frame support Ben Hutchings
2013-04-07 22:45 ` [73/74] bonding: get netdev_rx_handler_unregister out of locks Ben Hutchings
2013-04-07 22:45 ` [57/74] thermal: shorten too long mcast group name Ben Hutchings
2013-04-07 22:45 ` [64/74] atl1e: drop pci-msi support because of packet corruption Ben Hutchings
2013-04-07 22:45 ` [67/74] ipv6: fix bad free of addrconf_init_net Ben Hutchings
2013-04-07 22:45 ` [62/74] drivers: net: ethernet: davinci_emac: use netif_wake_queue() while restarting tx queue Ben Hutchings
2013-04-07 22:45 ` Ben Hutchings [this message]
2013-04-07 22:45 ` [74/74] HID: microsoft: do not use compound literal - fix build Ben Hutchings
2013-04-07 22:45 ` [71/74] pch_gbe: fix ip_summed checksum reporting on rx Ben Hutchings
2013-04-07 22:45 ` [65/74] DM9000B: driver initialization upgrade Ben Hutchings
2013-04-07 22:45 ` [59/74] unix: fix a race condition in unix_release() Ben Hutchings
2013-04-07 22:45 ` [68/74] ipv6: don't accept node local multicast traffic from the wire Ben Hutchings
2013-04-07 22:45 ` [70/74] net: add a synchronize_net() in netdev_rx_handler_unregister() Ben Hutchings
2013-04-07 22:45 ` [69/74] ks8851: Fix interpretation of rxlen field Ben Hutchings
2013-04-07 22:45 ` [60/74] bonding: remove already created master sysfs link on failure Ben Hutchings
2013-04-07 22:45 ` [66/74] ipv6: don't accept multicast traffic with scope 0 Ben Hutchings
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=lsq.1365374743.574335065@decadent.org.uk \
--to=ben@decadent.org.uk \
--cc=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=fubar@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nikolay@redhat.com \
--cc=stable@vger.kernel.org \
/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®