All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Krzysztof Mazur <krzysiek@podlesie.net>
Cc: "Chas Williams (CONTRACTOR)" <chas@cmf.nrl.navy.mil>,
	David Laight <David.Laight@ACULAB.COM>,
	davem@davemloft.net, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, nathan@traverse.com.au
Subject: Re: [PATCH v2 3/3] pppoatm: protect against freeing of vcc
Date: Fri, 30 Nov 2012 16:23:46 +0000	[thread overview]
Message-ID: <1354292626.21562.298.camel@shinybook.infradead.org> (raw)
In-Reply-To: <1354277415.21562.284.camel@shinybook.infradead.org>

[-- Attachment #1: Type: text/plain, Size: 5095 bytes --]

On Fri, 2012-11-30 at 12:10 +0000, David Woodhouse wrote:
> In that case I think we're fine. I'll just do the same thing in
> br2684_push(), fix up the comment you just corrected, and we're all
> good.

OK, here's an update to me my patch 8/17 'br2684: don't send frames on
not-ready vcc'. It takes the socket lock and does fairly much the same
thing as your pppoatm version. It returns NETDEV_TX_BUSY and stops the
queue if the socket is locked, and it gets woken from the ->release_cb
callback.

I've dropped your Acked-By: since it's mostly new, but feel free to give
me a fresh one. With this I think we're done.

Unless Chas has any objections, I'll ask Dave to pull it...


From 47d5ad4c98452bcddfd00da1c659dac85202f213 Mon Sep 17 00:00:00 2001
From: David Woodhouse <dwmw2@infradead.org>
Date: Tue, 27 Nov 2012 23:28:36 +0000
Subject: [PATCH] br2684: don't send frames on not-ready vcc

Avoid submitting packets to a vcc which is being closed. Things go badly
wrong when the ->pop method gets later called after everything's been
torn down.

Use the ATM socket lock for synchronisation with vcc_destroy_socket(),
which clears the ATM_VF_READY bit under the same lock. Otherwise, we
could end up submitting a packet to the device driver even after its
->ops->close method has been called. And it could call the vcc's ->pop
method after the protocol has been shut down. Which leads to a panic.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
---
 net/atm/br2684.c | 48 +++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 45 insertions(+), 3 deletions(-)

diff --git a/net/atm/br2684.c b/net/atm/br2684.c
index 8eb6fbe..5ff145f 100644
--- a/net/atm/br2684.c
+++ b/net/atm/br2684.c
@@ -68,6 +68,7 @@ struct br2684_vcc {
 	/* keep old push, pop functions for chaining */
 	void (*old_push)(struct atm_vcc *vcc, struct sk_buff *skb);
 	void (*old_pop)(struct atm_vcc *vcc, struct sk_buff *skb);
+	void (*old_release_cb)(struct atm_vcc *vcc);
 	enum br2684_encaps encaps;
 	struct list_head brvccs;
 #ifdef CONFIG_ATM_BR2684_IPFILTER
@@ -269,6 +270,22 @@ static int br2684_xmit_vcc(struct sk_buff *skb, struct net_device *dev,
 	return !atmvcc->send(atmvcc, skb);
 }
 
+static void br2684_release_cb(struct atm_vcc *atmvcc)
+{
+	struct br2684_vcc *brvcc = BR2684_VCC(atmvcc);
+
+	/*
+	 * A race with br2684_xmit_vcc() might cause a spurious wakeup just
+	 * after that function *stops* the queue, and qspace might actually
+	 * go negative before the queue stops again. We cope with that.
+	 */
+	if (atomic_read(&brvcc->qspace) > 0)
+		netif_wake_queue(brvcc->device);
+
+	if (brvcc->old_release_cb)
+		brvcc->old_release_cb(atmvcc);
+}
+
 static inline struct br2684_vcc *pick_outgoing_vcc(const struct sk_buff *skb,
 						   const struct br2684_dev *brdev)
 {
@@ -280,6 +297,8 @@ static netdev_tx_t br2684_start_xmit(struct sk_buff *skb,
 {
 	struct br2684_dev *brdev = BRPRIV(dev);
 	struct br2684_vcc *brvcc;
+	struct atm_vcc *atmvcc;
+	netdev_tx_t ret = NETDEV_TX_OK;
 
 	pr_debug("skb_dst(skb)=%p\n", skb_dst(skb));
 	read_lock(&devs_lock);
@@ -290,9 +309,26 @@ static netdev_tx_t br2684_start_xmit(struct sk_buff *skb,
 		dev->stats.tx_carrier_errors++;
 		/* netif_stop_queue(dev); */
 		dev_kfree_skb(skb);
-		read_unlock(&devs_lock);
-		return NETDEV_TX_OK;
+		goto out_devs;
+	}
+	atmvcc = brvcc->atmvcc;
+
+	bh_lock_sock(sk_atm(atmvcc));
+
+	if (test_bit(ATM_VF_RELEASED, &atmvcc->flags) ||
+	    test_bit(ATM_VF_CLOSE, &atmvcc->flags) ||
+	    !test_bit(ATM_VF_READY, &atmvcc->flags)) {
+		dev->stats.tx_dropped++;
+		dev_kfree_skb(skb);
+		goto out;
 	}
+
+	if (sock_owned_by_user(sk_atm(atmvcc))) {
+		netif_stop_queue(brvcc->device);
+		ret = NETDEV_TX_BUSY;
+		goto out;
+	}
+
 	if (!br2684_xmit_vcc(skb, dev, brvcc)) {
 		/*
 		 * We should probably use netif_*_queue() here, but that
@@ -304,8 +340,11 @@ static netdev_tx_t br2684_start_xmit(struct sk_buff *skb,
 		dev->stats.tx_errors++;
 		dev->stats.tx_fifo_errors++;
 	}
+ out:
+	bh_unlock_sock(sk_atm(atmvcc));
+ out_devs:
 	read_unlock(&devs_lock);
-	return NETDEV_TX_OK;
+	return ret;
 }
 
 /*
@@ -378,6 +417,7 @@ static void br2684_close_vcc(struct br2684_vcc *brvcc)
 	list_del(&brvcc->brvccs);
 	write_unlock_irq(&devs_lock);
 	brvcc->atmvcc->user_back = NULL;	/* what about vcc->recvq ??? */
+	brvcc->atmvcc->release_cb = brvcc->old_release_cb;
 	brvcc->old_push(brvcc->atmvcc, NULL);	/* pass on the bad news */
 	kfree(brvcc);
 	module_put(THIS_MODULE);
@@ -554,9 +594,11 @@ static int br2684_regvcc(struct atm_vcc *atmvcc, void __user * arg)
 	brvcc->encaps = (enum br2684_encaps)be.encaps;
 	brvcc->old_push = atmvcc->push;
 	brvcc->old_pop = atmvcc->pop;
+	brvcc->old_release_cb = atmvcc->release_cb;
 	barrier();
 	atmvcc->push = br2684_push;
 	atmvcc->pop = br2684_pop;
+	atmvcc->release_cb = br2684_release_cb;
 
 	/* initialize netdev carrier state */
 	if (atmvcc->dev->signal == ATM_PHY_SIG_LOST)
-- 
1.8.0





-- 
dwmw2


[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 6171 bytes --]

  reply	other threads:[~2012-11-30 16:23 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-22 17:14 [PATCH v2 1/3] pppoatm: don't send frames to destroyed vcc Krzysztof Mazur
2012-10-22 17:14 ` [PATCH v2 2/3] pppoatm: fix race condition with destroying of vcc Krzysztof Mazur
2012-10-30  9:37   ` David Woodhouse
2012-10-30 19:07     ` Krzysztof Mazur
2012-10-30 19:52       ` Krzysztof Mazur
2012-10-31 10:16         ` David Woodhouse
2012-10-31 11:30           ` Krzysztof Mazur
2012-10-31 11:52             ` David Woodhouse
2012-10-30 14:26   ` Chas Williams (CONTRACTOR)
2012-10-30 18:20     ` Krzysztof Mazur
2012-10-31  9:41       ` Krzysztof Mazur
2012-10-31 10:22         ` Krzysztof Mazur
2012-10-31 20:03         ` chas williams - CONTRACTOR
2012-10-31 22:04           ` Krzysztof Mazur
2012-11-01 14:26             ` chas williams - CONTRACTOR
2012-11-02  9:40               ` Krzysztof Mazur
2012-11-02 10:54                 ` Krzysztof Mazur
2012-10-22 17:14 ` [PATCH v2 3/3] pppoatm: protect against freeing " Krzysztof Mazur
2012-10-30  9:39   ` David Woodhouse
2012-10-30 19:26     ` Krzysztof Mazur
2012-11-27 17:16   ` David Woodhouse
2012-11-27 17:39     ` Krzysztof Mazur
2012-11-27 18:02       ` David Woodhouse
2012-11-27 18:28         ` Krzysztof Mazur
2012-11-28 20:18           ` Krzysztof Mazur
2012-11-28 20:44             ` David Woodhouse
2012-11-28 21:24               ` Krzysztof Mazur
2012-11-28 21:20             ` chas williams - CONTRACTOR
2012-11-28 21:45               ` [PATCH] atm: introduce vcc_pop() Krzysztof Mazur
2012-11-28 21:59                 ` chas williams - CONTRACTOR
2012-11-28 22:10                   ` Krzysztof Mazur
2012-11-28 22:33                     ` [PATCH] atm: introduce vcc_pop_skb() Krzysztof Mazur
2012-12-03 13:22                       ` David Woodhouse
2012-12-03 20:11                         ` Krzysztof Mazur
2012-11-27 18:39         ` [PATCH v2 3/3] pppoatm: protect against freeing of vcc Krzysztof Mazur
2012-11-27 18:54         ` chas williams - CONTRACTOR
2012-11-27 22:36           ` [PATCH] solos-pci: Wait for pending TX to complete when releasing vcc David Woodhouse
2012-11-27 23:28             ` [PATCH] br2684: don't send frames on not-ready vcc David Woodhouse
2012-11-27 23:51               ` Krzysztof Mazur
2012-11-28  0:54                 ` David Woodhouse
2012-11-28  8:08                   ` Krzysztof Mazur
2012-11-28  9:58                     ` David Woodhouse
2012-11-28 16:41               ` David Miller
2012-11-28 17:01                 ` David Woodhouse
2012-11-28 17:04                   ` David Miller
2012-11-28 17:09                     ` David Woodhouse
2012-11-28 17:11                       ` David Miller
2012-11-30  1:18                       ` Nathan Williams
2012-11-30  1:34                         ` David Woodhouse
2012-11-28  9:21           ` [PATCH v2 3/3] pppoatm: protect against freeing of vcc David Laight
2012-11-28 10:04             ` Krzysztof Mazur
2012-11-28 10:24               ` David Woodhouse
2012-11-28 15:18                 ` chas williams - CONTRACTOR
2012-11-28 22:18             ` David Woodhouse
2012-11-29 10:57               ` Krzysztof Mazur
2012-11-29 11:55                 ` David Woodhouse
2012-11-29 12:43                   ` [PATCH] solos-pci: don't call vcc->pop() after pclose() Krzysztof Mazur
2012-11-29 12:57                     ` David Woodhouse
2012-11-29 13:20                       ` Krzysztof Mazur
2012-11-29 14:42                         ` David Woodhouse
2012-11-29 14:55                           ` Krzysztof Mazur
2012-11-29 14:41                     ` chas williams - CONTRACTOR
2012-11-29 14:29                 ` [PATCH v2 3/3] pppoatm: protect against freeing of vcc chas williams - CONTRACTOR
2012-11-29 15:09               ` Krzysztof Mazur
2012-11-29 15:47                 ` David Woodhouse
2012-11-29 15:59                   ` chas williams - CONTRACTOR
2012-11-29 16:24                     ` David Woodhouse
2012-11-29 17:17                       ` chas williams - CONTRACTOR
2012-11-29 18:11                         ` David Woodhouse
2012-11-29 18:29                           ` chas williams - CONTRACTOR
2012-11-29 22:17                             ` David Woodhouse
2012-11-30  1:38                               ` Chas Williams (CONTRACTOR)
2012-11-30  1:57                                 ` David Woodhouse
2012-11-30  8:25                                   ` David Woodhouse
2012-11-30  9:53                                     ` Krzysztof Mazur
2012-11-30 12:10                                       ` David Woodhouse
2012-11-30 16:23                                         ` David Woodhouse [this message]
2012-11-30 17:00                                           ` Krzysztof Mazur
2012-11-30 18:33                                             ` David Woodhouse
2012-11-30 17:12                                           ` chas williams - CONTRACTOR
2012-11-30 17:39                                             ` Krzysztof Mazur
2012-11-29 16:28                   ` Krzysztof Mazur
2012-11-29 15:37               ` chas williams - CONTRACTOR
2012-11-29 15:59                 ` David Woodhouse
2012-11-29 16:11                   ` chas williams - CONTRACTOR
2012-10-23  6:52 ` [PATCH v2 1/3] pppoatm: don't send frames to destroyed vcc David Miller
2012-10-23  8:12   ` David Woodhouse
2012-10-30  9:35 ` David Woodhouse
2012-10-30 20:19   ` Krzysztof Mazur

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=1354292626.21562.298.camel@shinybook.infradead.org \
    --to=dwmw2@infradead.org \
    --cc=David.Laight@ACULAB.COM \
    --cc=chas@cmf.nrl.navy.mil \
    --cc=davem@davemloft.net \
    --cc=krzysiek@podlesie.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nathan@traverse.com.au \
    --cc=netdev@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 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.