LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH] ATM, Solos PCI ADSL2+: Don't deref NULL pointer if net_ratelimit() and alloc_skb() interact badly.
@ 2011-02-13 20:49 Jesper Juhl
  2011-02-14  0:55 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Jesper Juhl @ 2011-02-13 20:49 UTC (permalink / raw
  To: linux-kernel
  Cc: Chas Williams, linux-atm-general, netdev, Nathan Williams,
	David Woodhouse, Treker Chen

If alloc_skb() fails to allocate memory and returns NULL then we want to 
return -ENOMEM from drivers/atm/solos-pci.c::popen() regardless of the 
value of net_ratelimit(). The way the code is today, we may not return if 
net_ratelimit() returns 0, then we'll proceed to pass a NULL pointer to 
skb_put() which will blow up in our face.
This patch ensures that we always return -ENOMEM on alloc_skb() failure 
and only let the dev_warn() be controlled by the value of net_ratelimit().

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 solos-pci.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
index 73fb1c4..25ef1a4 100644
--- a/drivers/atm/solos-pci.c
+++ b/drivers/atm/solos-pci.c
@@ -866,8 +866,9 @@ static int popen(struct atm_vcc *vcc)
 	}
 
 	skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
-	if (!skb && net_ratelimit()) {
-		dev_warn(&card->dev->dev, "Failed to allocate sk_buff in popen()\n");
+	if (!skb) {
+		if (net_ratelimit())
+			dev_warn(&card->dev->dev, "Failed to allocate sk_buff in popen()\n");
 		return -ENOMEM;
 	}
 	header = (void *)skb_put(skb, sizeof(*header));


-- 
Jesper Juhl <jj@chaosbits.net>            http://www.chaosbits.net/
Plain text mails only, please.
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ATM, Solos PCI ADSL2+: Don't deref NULL pointer if net_ratelimit() and alloc_skb() interact badly.
  2011-02-13 20:49 [PATCH] ATM, Solos PCI ADSL2+: Don't deref NULL pointer if net_ratelimit() and alloc_skb() interact badly Jesper Juhl
@ 2011-02-14  0:55 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2011-02-14  0:55 UTC (permalink / raw
  To: jj; +Cc: linux-kernel, chas, linux-atm-general, netdev, nathan, dwmw2,
	treker

From: Jesper Juhl <jj@chaosbits.net>
Date: Sun, 13 Feb 2011 21:49:32 +0100 (CET)

> If alloc_skb() fails to allocate memory and returns NULL then we want to 
> return -ENOMEM from drivers/atm/solos-pci.c::popen() regardless of the 
> value of net_ratelimit(). The way the code is today, we may not return if 
> net_ratelimit() returns 0, then we'll proceed to pass a NULL pointer to 
> skb_put() which will blow up in our face.
> This patch ensures that we always return -ENOMEM on alloc_skb() failure 
> and only let the dev_warn() be controlled by the value of net_ratelimit().
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>

Applied.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-02-14  0:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-13 20:49 [PATCH] ATM, Solos PCI ADSL2+: Don't deref NULL pointer if net_ratelimit() and alloc_skb() interact badly Jesper Juhl
2011-02-14  0:55 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).