From: Tobias DiPasquale <toby@cbcg.net>
To: netdev@oss.sgi.com
Cc: linux-net@vger.kernel.org, linux-kernel@vger.kernel.org,
coreteam@netfilter.org, netfilter@lists.netfilter.org,
akpm@zip.com.au, jgarzik@pobox.com, davem@redhat.com,
kuznet@ms2.inr.ac.ru, pekkas@netcore.fi,
jmorris@intercode.com.au, yoshfuji@linux-ipv6.org
Subject: [PATCH] kfree_skb() bug in 2.4.22
Date: Wed, 08 Oct 2003 08:44:35 -0400 [thread overview]
Message-ID: <1065617075.1514.29.camel@localhost> (raw)
Hi all,
I was debugging one of my iptables/netfilter modules yesterday and I
came across this bug in kfree_skb(). One of my functions returns a
struct skbuff * on success and NULL on failure. When it failed, the code
calling said function attempted to free the struct skbuff *, which at
that point was NULL. This produced a kernel panic. I investigated the
problem and found that, not only should I be checking for a NULL pointer
when freeing the struct skbuff *, but the actual cause of the panic was
because kfree_skb() and kfree_skb_fast() do not check for skb==NULL,
either. They immediately attempt to dereference the users field of the
struct skbuff * in order to decrement that reference counter.
I have come up with a patch that applies to both the 2.4.22 pristine
source tree and the 2.4.23-pre6 source tree that solves this issue (see
below). I tried to follow Documentation/SubmittingPatches to the letter;
please let me know if I failed this in some way. Thanks :)
P.S. I wasn't sure who exactly maintains this particular code; that's
why I just sent it to everyone listed in MAINTAINERS remotely associated
with include/linux/skbuff.h ;)
--- include/linux/skbuff.h.orig 2003-10-08 07:52:31.000000000 -0400
+++ include/linux/skbuff.h 2003-10-08 07:52:52.000000000 -0400
@@ -293,6 +293,8 @@
static inline void kfree_skb(struct sk_buff *skb)
{
+ if (!skb)
+ return;
if (atomic_read(&skb->users) == 1 || atomic_dec_and_test(&skb->users))
__kfree_skb(skb);
}
@@ -300,6 +302,8 @@
/* Use this if you didn't touch the skb state [for fast switching] */
static inline void kfree_skb_fast(struct sk_buff *skb)
{
+ if (!skb)
+ return;
if (atomic_read(&skb->users) == 1 || atomic_dec_and_test(&skb->users))
kfree_skbmem(skb);
}
next reply other threads:[~2003-10-08 12:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-10-08 12:44 Tobias DiPasquale [this message]
2003-10-08 13:09 ` [PATCH] kfree_skb() bug in 2.4.22 Jeff Garzik
2003-10-08 13:47 ` David S. Miller
2003-10-10 12:53 ` Ingo Oeser
2003-10-10 13:00 ` David S. Miller
2003-10-10 15:43 ` Ingo Oeser
2003-10-10 16:57 ` Dan Kegel
2003-10-08 14:11 ` Tobias DiPasquale
2003-10-08 14:11 ` David S. 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=1065617075.1514.29.camel@localhost \
--to=toby@cbcg.net \
--cc=akpm@zip.com.au \
--cc=coreteam@netfilter.org \
--cc=davem@redhat.com \
--cc=jgarzik@pobox.com \
--cc=jmorris@intercode.com.au \
--cc=kuznet@ms2.inr.ac.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-net@vger.kernel.org \
--cc=netdev@oss.sgi.com \
--cc=netfilter@lists.netfilter.org \
--cc=pekkas@netcore.fi \
--cc=yoshfuji@linux-ipv6.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.