From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759012Ab3LFVwf (ORCPT ); Fri, 6 Dec 2013 16:52:35 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:60473 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758982Ab3LFVwc (ORCPT ); Fri, 6 Dec 2013 16:52:32 -0500 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jay Vosburgh , Andy Gospodarek , Veaceslav Falico , Nikolay Aleksandrov , "David S. Miller" Subject: [PATCH 3.12 18/83] bonding: fix two race conditions in bond_store_updelay/downdelay Date: Fri, 6 Dec 2013 13:51:08 -0800 Message-Id: <20131206214641.765412064@linuxfoundation.org> X-Mailer: git-send-email 1.8.5.1.67.gb00d244 In-Reply-To: <20131206214640.002320724@linuxfoundation.org> References: <20131206214640.002320724@linuxfoundation.org> User-Agent: quilt/0.60-8.1.3 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Nikolay Aleksandrov [ Upstream commit b869ccfab1e324507fa3596e3e1308444fb68227 ] This patch fixes two race conditions between bond_store_updelay/downdelay and bond_store_miimon which could lead to division by zero as miimon can be set to 0 while either updelay/downdelay are being set and thus miss the zero check in the beginning, the zero div happens because updelay/downdelay are stored as new_value / bond->params.miimon. Use rtnl to synchronize with miimon setting. CC: Jay Vosburgh CC: Andy Gospodarek CC: Veaceslav Falico Signed-off-by: Nikolay Aleksandrov Acked-by: Veaceslav Falico Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/bonding/bond_sysfs.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/net/bonding/bond_sysfs.c +++ b/drivers/net/bonding/bond_sysfs.c @@ -760,6 +760,8 @@ static ssize_t bonding_store_downdelay(s int new_value, ret = count; struct bonding *bond = to_bond(d); + if (!rtnl_trylock()) + return restart_syscall(); if (!(bond->params.miimon)) { pr_err("%s: Unable to set down delay as MII monitoring is disabled\n", bond->dev->name); @@ -793,6 +795,7 @@ static ssize_t bonding_store_downdelay(s } out: + rtnl_unlock(); return ret; } static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR, @@ -815,6 +818,8 @@ static ssize_t bonding_store_updelay(str int new_value, ret = count; struct bonding *bond = to_bond(d); + if (!rtnl_trylock()) + return restart_syscall(); if (!(bond->params.miimon)) { pr_err("%s: Unable to set up delay as MII monitoring is disabled\n", bond->dev->name); @@ -848,6 +853,7 @@ static ssize_t bonding_store_updelay(str } out: + rtnl_unlock(); return ret; } static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,