[lkml]   [2006]   [Nov]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectIPv4: ip_options_compile() how can we avoid blowing up on a NULL skb???

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
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 <>
Don't top-post
Plain text mails only, please
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2006-11-16 23:37    [W:0.036 / U:17.224 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site