Skip to contentSkip to conversation

Bug in using inet_lookup ()

DISCUSSION Nj A 2 participants 2 messages Nov 14, 2007

Subsystems (2)
lore
Share & tools
lore

Nj A

author
#0 lore raw

Dear All,
I need to use the inet_lookup function to find the sock structure of a TCP connection in a SYN_RECV state. Here is what I used to do so:
/* The kernel TCP hashtable */
struct inet_hashinfo __cacheline_aligned tcp_hashinfo = {
.lhash_lock = __RW_LOCK_UNLOCKED (tcp_hashinfo.lhash_lock),
.lhash_users = ATOMIC_INIT (0),
.lhash_wait = __WAIT_QUEUE_HEAD_INITIALIZER (tcp_hashinfo.lhash_wait),
};
...
struct sock *sk;
struct sk_buff *skb;
skb = alloc_skb (MAX_TCP_HEADER + 15, GFP_KERNEL);
if (skb == NULL)
printk ("%s: Unable to allocate memory \n", __FUNCTION__);
sk = inet_lookup (&tcp_hashinfo, ip_src, src_port, ip_dst, dst_port, inet_iif (skb));
if (!sk)
...
This portion of code seems to cause the kernel to panic due to dereferencing a NULL pointer. Can anyone please tell me what is the error above?
Best Regards,

      _____________________________________________________________________________ 

Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail

#1 lore raw
Quoted 10 lines · Nj A

/* The kernel TCP hashtable */
struct inet_hashinfo __cacheline_aligned tcp_hashinfo = { .lhash_lock = __RW_LOCK_UNLOCKED (tcp_hashinfo.lhash_lock), .lhash_users = ATOMIC_INIT (0),
.lhash_wait = __WAIT_QUEUE_HEAD_INITIALIZER (tcp_hashinfo.lhash_wait), };
...
struct sock *sk;
struct sk_buff *skb;
skb = alloc_skb (MAX_TCP_HEADER + 15, GFP_KERNEL);

Quoted 8 lines

if (skb == NULL)
printk ("%s: Unable to allocate memory \n", __FUNCTION__);
sk = inet_lookup (&tcp_hashinfo, ip_src, src_port, ip_dst, dst_port, inet_iif (skb)); if (!sk)
...
This portion of code seems to cause the kernel to panic due to dereferencing a NULL pointer. Can anyone please tell me what is the error above?
Best Regards,

Where exactly? Likely in inet_iif(), since it dereferences dst (routing info), which is not presented after simple alloc_skb().
You have to setup skb correctly, check how ip_rcv() does it.

Signature · 1 line
	Evgeniy Polyakov