public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Guillaume Chazarain <guichaz@yahoo•fr>
To: netdev@vger•kernel.org
Subject: [PATCH] Fix slab corruption with netem (2nd try)
Date: Sun, 16 Jul 2006 23:56:31 +0200	[thread overview]
Message-ID: <44BAB60F.7060600@yahoo.fr> (raw)

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

CONFIG_DEBUG_SLAB found the following bug:
netem_enqueue() in sch_netem.c gets a pointer inside a slab object:
struct netem_skb_cb *cb = (struct netem_skb_cb *)skb->cb;
But then, the slab object may be freed:
skb = skb_unshare(skb, GFP_ATOMIC)
cb is still pointing inside the freed skb, so here is a patch to
initialize cb later, and make it clear that initializing it sooner
is a bad idea.

[From Stephen Hemminger: leave cb unitialized in order to let gcc
complain in case of use before initialization]

Thanks.

-- 
Guillaume




[-- Attachment #2: netem_cb_initialization.diff --]
[-- Type: text/x-patch, Size: 967 bytes --]

Signed-off-by: Guillaume Chazarain <guichaz@yahoo•fr>
---
 net/sched/sch_netem.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff -r 1b8d63e34819 net/sched/sch_netem.c
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -148,7 +148,8 @@ static int netem_enqueue(struct sk_buff 
 static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch)
 {
 	struct netem_sched_data *q = qdisc_priv(sch);
-	struct netem_skb_cb *cb = (struct netem_skb_cb *)skb->cb;
+	/* We don't fill cb now as skb_unshare() may invalidate it */
+	struct netem_skb_cb *cb;
 	struct sk_buff *skb2;
 	int ret;
 	int count = 1;
@@ -200,6 +201,7 @@ static int netem_enqueue(struct sk_buff 
 		skb->data[net_random() % skb_headlen(skb)] ^= 1<<(net_random() % 8);
 	}
 
+	cb = (struct netem_skb_cb *)skb->cb;
 	if (q->gap == 0 		/* not doing reordering */
 	    || q->counter < q->gap 	/* inside last reordering gap */
 	    || q->reorder < get_crandom(&q->reorder_cor)) {


             reply	other threads:[~2006-07-16 21:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-16 21:56 Guillaume Chazarain [this message]
2006-07-17  2:02 ` [PATCH] Fix slab corruption with netem (2nd try) 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=44BAB60F.7060600@yahoo.fr \
    --to=guichaz@yahoo$(echo .)fr \
    --cc=netdev@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox