From patchwork Fri Sep 2 05:18:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahesh Bandewar X-Patchwork-Id: 665117 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3sQS8T2GYNz9sdm for ; Fri, 2 Sep 2016 15:18:49 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bandewar-net.20150623.gappssmtp.com header.i=@bandewar-net.20150623.gappssmtp.com header.b=wVC/3p7T; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751055AbcIBFSo (ORCPT ); Fri, 2 Sep 2016 01:18:44 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34069 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750754AbcIBFSl (ORCPT ); Fri, 2 Sep 2016 01:18:41 -0400 Received: by mail-pf0-f195.google.com with SMTP id g202so5326925pfb.1 for ; Thu, 01 Sep 2016 22:18:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bandewar-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=hBvE81hVy/XkxPJaYcsLpScdEZCyvG/U4rKnIPGWe2w=; b=wVC/3p7Tuictoq1DuQc9MIV2fxi2Imm6ujnmSvLslQwY1+OX7Sf4ugm1oKkmYdlxvY GDsID029lUmIgGpS4ou6QO+k125c8/+RIpYUBM/DCcvdTH/cuyXvGENNYJWEps8HM/YE v1HM3dt0YuzlECo4PfB0a1Sa5KLf9M/yHBm6zQi88bHnQ3btHLPhZenz+mcZp0SswFlC jHL6XpuYfgmv1h7b2sRLMCa4cGyYVBnARHIGz3enqPHAm1oo4KRv/B/EuKK6D1fUEPNu mhy4JCO+cCUyr0W4DI35F1QvXwSkoIiDZdnmkgOU97l1BB24+EQUjeuyYNsNYg3Kn033 mBlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=hBvE81hVy/XkxPJaYcsLpScdEZCyvG/U4rKnIPGWe2w=; b=lczo5eRFn4wbeOPuGInuesysfUJzQHS5QnFSTqjav5TXVNOyPxtfcrc4j6iHA3uNMd /awDwAm9KubK1/DSUO8oj6Xt/9Y/PvK38Zn4zkNi6vdQjU75aT0uoYLhhq99ipOfjw0z Rxf1nVAfS5OxRKB2fItWuBE8PJYbaGdqJP+yaaMjv03dFLJ4qyHZLlGovJ49Bw2aQlq4 /GUrnJlkn23t8N9vE5GjbaBLMnMGqcpO6lPIvsRZtXBjKQrPFO8akQM7U2Y9Xdv4pzTS YRzote2ZRqEngJHoS8NT8PgSJo0nNHvSLDJ8PBCTWjXtaPZybJFFZImFu77esucxzmw8 mWUg== X-Gm-Message-State: AE9vXwNIFsip0Wvvy1XfiW/94j+aIKQ9DoxCkUdHaFDIbauOmrGrCNfpq7jYG7lgL4IotQ== X-Received: by 10.98.41.195 with SMTP id p186mr32721890pfp.81.1472793520963; Thu, 01 Sep 2016 22:18:40 -0700 (PDT) Received: from localhost ([2620:0:1000:3012:d58f:26cc:b9ad:32ee]) by smtp.gmail.com with ESMTPSA id m65sm11234078pfg.79.2016.09.01.22.18.40 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 01 Sep 2016 22:18:40 -0700 (PDT) From: Mahesh Bandewar To: Jay Vosburgh , Andy Gospodarek , Veaceslav Falico , David Miller Cc: Mahesh Bandewar , Eric Dumazet , netdev Subject: [PATCH net] bonding: Fix bonding crash Date: Thu, 1 Sep 2016 22:18:34 -0700 Message-Id: <1472793514-31850-1-git-send-email-mahesh@bandewar.net> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Mahesh Bandewar Following few steps will crash kernel - (a) Create bonding master > modprobe bonding miimon=50 (b) Create macvlan bridge on eth2 > ip link add link eth2 dev mvl0 address aa:0:0:0:0:01 \ type macvlan (c) Now try adding eth2 into the bond > echo +eth2 > /sys/class/net/bond0/bonding/slaves Bonding does lots of things before checking if the device enslaved is busy or not. In this case when the notifier call-chain sends notifications, the bond_netdev_event() assumes that the rx_handler /rx_handler_data is registered while the bond_enslave() hasn't progressed far enough to register rx_handler for the new slave. This patch adds a rx_handler check that can be performed right at the beginning of the enslave code to avoid getting into this situation. Signed-off-by: Mahesh Bandewar Acked-by: Eric Dumazet --- drivers/net/bonding/bond_main.c | 7 ++++--- include/linux/netdevice.h | 1 + net/core/dev.c | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 217e8da0628c..9599ed6f1213 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -1341,9 +1341,10 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) slave_dev->name); } - /* already enslaved */ - if (slave_dev->flags & IFF_SLAVE) { - netdev_dbg(bond_dev, "Error: Device was already enslaved\n"); + /* already in-use? */ + if (netdev_is_rx_handler_busy(slave_dev)) { + netdev_err(bond_dev, + "Error: Device is in use and cannot be enslaved\n"); return -EBUSY; } diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index d122be9345c7..99ba59a7b114 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3266,6 +3266,7 @@ static inline void napi_free_frags(struct napi_struct *napi) napi->skb = NULL; } +bool netdev_is_rx_handler_busy(struct net_device *dev); int netdev_rx_handler_register(struct net_device *dev, rx_handler_func_t *rx_handler, void *rx_handler_data); diff --git a/net/core/dev.c b/net/core/dev.c index 34b5322bc081..81e6f7298122 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3965,6 +3965,22 @@ sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret, } /** + * netdev_is_rx_handler_busy - check if receive handler is registered + * @dev: device to check + * + * Check if a receive handler is already registered for a given device. + * Return true if there one. + * + * The caller must hold the rtnl_mutex. + */ +bool netdev_is_rx_handler_busy(struct net_device *dev) +{ + ASSERT_RTNL(); + return dev && rtnl_dereference(dev->rx_handler); +} +EXPORT_SYMBOL_GPL(netdev_is_rx_handler_busy); + +/** * netdev_rx_handler_register - register receive handler * @dev: device to register a handler for * @rx_handler: receive handler to register