mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jesper Juhl" <jesper.juhl@gmail.com>
To: netdev@vger.kernel.org
Cc: "David Miller" <davem@davemloft.net>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>
Subject: IPv4: ip_options_compile() how can we avoid blowing up on a NULL skb???
Date: Thu, 16 Nov 2006 23:34:14 +0100	[thread overview]
Message-ID: <9a8748490611161434oc393db0o1e1c23ba99b1c796@mail.gmail.com> (raw)

Hi,

In net/ipv4/ip_options.c::ip_options_compile() we have the following
code at the start of the function :


int ip_options_compile(struct ip_options * opt, struct sk_buff * skb)
{
        int l;
        unsigned char * iph;
        unsigned char * optptr;
        int optlen;
        unsigned char * pp_ptr = NULL;
        struct rtable *rt = skb ? (struct rtable*)skb->dst : NULL;

        if (!opt) {
                opt = &(IPCB(skb)->opt);
                iph = skb->nh.raw;
                opt->optlen = ((struct iphdr *)iph)->ihl*4 -
sizeof(struct iphdr);
                optptr = iph + sizeof(struct iphdr);
                opt->is_data = 0;
        } else {
                optptr = opt->is_data ? opt->__data : (unsigned
char*)&(skb->nh.iph[1]);
                iph = optptr - sizeof(struct iphdr);
        }

...

I don't see how that avoids blowing up if we get passed a NULL skb.

>From the line
    struct rtable *rt = skb ? (struct rtable*)skb->dst : NULL;
it is clear that we /may/ get passed a null skb.

Then a bit further down in the  if (!opt)  bit we dereference 'skb' :
    opt = &(IPCB(skb)->opt);
and we also may dereference it in the  else  part :
    optptr = opt->is_data ? opt->__data : (unsigned char*)&(skb->nh.iph[1]);

So if 'skb' is NULL, the only route I see that doesn't cause a NULL
pointer deref is if  (opt != NULL)  and at the same time
(opt->is_data != NULL)  .   Is that guaranteed in any way?  If now,
how come we don't blow up regularly?


-- 
Jesper Juhl <jesper.juhl@gmail.com>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html

             reply	other threads:[~2006-11-16 22:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-16 22:34 Jesper Juhl [this message]
2006-11-16 23:47 ` David Miller
2006-11-17  0:37   ` Herbert Xu
2006-11-17  3:46     ` Dmitry Torokhov
2006-11-17  5:28       ` Herbert Xu
2006-11-17  0:22 ` Herbert Xu

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=9a8748490611161434oc393db0o1e1c23ba99b1c796@mail.gmail.com \
    --to=jesper.juhl@gmail.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®