All of lore.kernel.org
 help / color / mirror / Atom feed
From: Veaceslav Falico <vfalico@redhat.com>
To: Nikolay Aleksandrov <nikolay@redhat.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net,
	Jay Vosburgh <fubar@us.ibm.com>,
	Andy Gospodarek <andy@greyhouse.net>
Subject: Re: [PATCH net] bonding: fix two race conditions in bond_store_updelay/downdelay
Date: Thu, 14 Nov 2013 11:17:54 +0100	[thread overview]
Message-ID: <20131114101754.GR19702@redhat.com> (raw)
In-Reply-To: <1384358866-15157-1-git-send-email-nikolay@redhat.com>

On Wed, Nov 13, 2013 at 05:07:46PM +0100, Nikolay Aleksandrov wrote:
>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 <fubar@us.ibm.com>
>CC: Andy Gospodarek <andy@greyhouse.net>
>CC: Veaceslav Falico <vfalico@redhat.com>
>Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com>

Nice, thanks! :)

Acked-by: Veaceslav Falico <vfalico@redhat.com>

>---
> drivers/net/bonding/bond_sysfs.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
>diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
>index bc8fd36..8f8a607 100644
>--- a/drivers/net/bonding/bond_sysfs.c
>+++ b/drivers/net/bonding/bond_sysfs.c
>@@ -701,6 +701,8 @@ static ssize_t bonding_store_downdelay(struct device *d,
> 	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);
>@@ -734,6 +736,7 @@ static ssize_t bonding_store_downdelay(struct device *d,
> 	}
>
> out:
>+	rtnl_unlock();
> 	return ret;
> }
> static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR,
>@@ -756,6 +759,8 @@ static ssize_t bonding_store_updelay(struct device *d,
> 	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);
>@@ -789,6 +794,7 @@ static ssize_t bonding_store_updelay(struct device *d,
> 	}
>
> out:
>+	rtnl_unlock();
> 	return ret;
> }
> static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,
>-- 
>1.8.1.4
>

  parent reply	other threads:[~2013-11-14 10:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-13 16:07 [PATCH net] bonding: fix two race conditions in bond_store_updelay/downdelay Nikolay Aleksandrov
2013-11-13 16:34 ` Nikolay Aleksandrov
2013-11-13 17:03 ` Eric Dumazet
2013-11-13 17:06   ` Nikolay Aleksandrov
2013-11-13 17:38     ` Eric Dumazet
2013-11-14  1:50     ` Ding Tianhong
2013-11-14 10:17 ` Veaceslav Falico [this message]
2013-11-14 21:29 ` David Miller

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=20131114101754.GR19702@redhat.com \
    --to=vfalico@redhat.com \
    --cc=andy@greyhouse.net \
    --cc=davem@davemloft.net \
    --cc=fubar@us.ibm.com \
    --cc=netdev@vger.kernel.org \
    --cc=nikolay@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.