Skip to contentSkip to conversation

libipq, kernel panics/oopses, and other undesirable traits

DISCUSSION Matt Walters 3 participants 13 messages Aug 15, 2004 – Aug 23, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw
Quoted 3 lines
Quoted 1 line · Matt Walters

Below is one of the stack traces that actually made it into the

logs

Quoted 1 line
Quoted 1 line

(oh yeah - did I mention that sometimes the machine is kind of

alright

Quoted 1 line
Quoted 1 line

after this? mostly it locks up immediately, or locks up trying to

stop

Quoted 1 line
Quoted 1 line

iptables though). The trace is from one of the times that it

exploded

Quoted 3 lines
Quoted 3 lines

with my application, not the test code.

Thanks in advance for any hints, confirmations, denials,

drop-kicks or

Quoted 1 line
Quoted 1 line

head smacks you might be able to offer. I'm going to try compiling

a

Quoted 1 line
Quoted 1 line

non-SMP kernel tonight or tomorrow to see if the issue persists,

and I

Quoted 3 lines
Quoted 1 line

will update the list.

This looks like the packet contents (ping) of a non-linear skb

corrupted

Quoted 2 lines

the registers. Please try the ip_queue_nonlinear_skbs patch from patch-o-matic-ng.

Patrick et al-

Firstly, thanks for the input. I applied the patch yesterday to the
2.6.7 kernel without luck. I then noticed that 2.6.8 was at kernel.org, so I downloaded it, applied the nonlinear_skbs patch to it, and built it. No love there either.

When I say "without luck", incidentally, I mean that the issue isn't
resolved. It's become more predictable and repeatible though, which is good, since it means I'll be able to roll up my sleeves today and dig in. Any packet being copied back from userspace that is larger than the destination device's MTU (that is being fragmented, that is) is causing the machine to throw a bunch of "Unable to handle kernel paging request at [foo]" messages. The good news? Even between boots, and even with the ip_queue module compiled statically into the kernel (something else I tried, just for giggles), the address it is complaining about is identical, and it's one of those suspicious addresses (0xbcbcbcbc or something like it, sorry I don't have it written down here). As I said, I'll dig into it later on today and keep the list updated.

Thanks again,

-Matt

#1 lore raw

Greetings, friends-

I've inlined a patch for ip_queue.c (diff -u is the standard
patch-o-matic format, right?) which will fix the issue I've been having with large packets coming back from userspace causing kernel panics. It should probably be added to the nonlinear_skbs patch, since it's the same type of fix (memcpy --> copy_skb_bits). There's also a storage-type modification for ipq_rcv_skb - skb_len is an unsigned int and it was being stored in an int.

I also noticed several storage-type issues in the netlink code, which
I've messed with ("corrected" - maybe) on my machine, but messed with *prior* to finding the memcpy in ip_queue.c, so I'll have to revert those changes and see if it stays fixed, otherwise I guess I'll have to get ahold of the netlink guys and send them a patch too. :)

Do please ignore the fact that my development machine thinks it's
tomorrow. I've just noticed.

I'm interested in doing further development for netfilter. Please feel
free to add my name to a list somewhere or something.

(addendum: I'm currently testing the code with icmp on INPUT and OUTPUT
going through userspace and having TOS bits tickled, etc, copied back into kernelspace, with a flood of 64kB pings across a pair of Intel e1000s -- IN octets: 2159535768 packets: 33458 // OUT octets:
2159470740 packets: 33457 -- looking really good)

-Matt

ip_queue.c 2004-08-17 15:02:11.583159408 -0700 renamed from ip_queue.c.orig 2004-08-16 14:32:43.000000000 -0700 +8 -4
@@ -333,7 +333,7 @@
 static int
 ipq_mangle_ipv4(ipq_verdict_msg_t *v, struct ipq_queue_entry *e)
 {
-       int diff;
+       int diff, status;
        struct iphdr *user_iph = (struct iphdr *)v->payload;
 
        if (v->data_len < sizeof(*user_iph))
@@ -346,7 +346,7 @@
                        return -EINVAL;
                if (diff > skb_tailroom(e->skb)) {
                        struct sk_buff *newskb;
-
+
                        newskb = skb_copy_expand(e->skb,
                                                 skb_headroom(e->skb),
                                                 diff,
@@ -363,7 +363,10 @@
                }
                skb_put(e->skb, diff);
        }
-       memcpy(e->skb->data, v->payload, v->data_len);
+
+       if ((status = skb_copy_bits(e->skb, 0, v->payload, v->data_len))) {
+               return status;
+       }
        e->skb->nfcache |= NFC_ALTERED;
 
        /*
@@ -477,7 +480,8 @@
 static inline void
 ipq_rcv_skb(struct sk_buff *skb)
 {
-       int status, type, pid, flags, nlmsglen, skblen;
+       int status, type, pid, flags;
+       size_t nlmsglen, skblen;
        struct nlmsghdr *nlh;
 
        skblen = skb->len;
#2 lore raw
Quoted 10 lines · Matt Walters

Greetings, friends-

I've inlined a patch for ip_queue.c (diff -u is the standard
patch-o-matic format, right?) which will fix the issue I've been having with large packets coming back from userspace causing kernel panics. It should probably be added to the nonlinear_skbs patch, since it's the same type of fix (memcpy --> copy_skb_bits). There's also a storage-type modification for ipq_rcv_skb - skb_len is an unsigned int and it was being stored in an int.

The skb_copy_bits can't be right. You change skb from being the destination to the source. If the skb really is nonlinear, we need to linearize it. But skb_tailroom should return 0 in this case and the skb should be linearized by skb_copy_expand already. The check isn't triggered because this line is wrong:

diff = v->data_len - e->skb->len

skb->len is the total length, including fragments. If we want to copy to it, we either need to linearize it or look at skb_headlen(skb). It's complicated getting everything right, I need to think about it some more.

Regards
Patrick

#3 lore raw
Quoted 12 lines · Patrick McHardy
Quoted 10 lines · Matt Walters

Greetings, friends-

I've inlined a patch for ip_queue.c (diff -u is the standard
patch-o-matic format, right?) which will fix the issue I've been having with large packets coming back from userspace causing kernel panics. It should probably be added to the nonlinear_skbs patch, since it's the same type of fix (memcpy --> copy_skb_bits). There's also a storage-type modification for ipq_rcv_skb - skb_len is an unsigned int and it was being stored in an int.

Quoted 2 lines

The skb_copy_bits can't be right. You change skb from being the destination to the source. If the skb really is nonlinear, we need to linearize it. But

..whoops. Perhaps some sleep is in order. It seemed like a success
because (naturally) the test program wasn't mangling the packets...

Quoted 9 lines

skb_tailroom should return 0 in this case and the skb should be linearized by skb_copy_expand already. The check isn't triggered because this line is wrong:

diff = v->data_len - e->skb->len

skb->len is the total length, including fragments. If we want to copy to it, we either need to linearize it or look at skb_headlen(skb). It's complicated getting everything right, I need to think about it some more.

Yeah, and for some twisted reason I was figuring on skb_copy_bits to do
that (since it *does* unwind fragment lists, etc). My apologies for the waste of bandwidth.

I'm going to get some sleep and have another look at this later.
Thanks for the smack on the head.

-Matt

#4 lore raw
Quoted 15 lines · Matt Walters
Quoted 11 lines · Patrick McHardy

skb_tailroom should return 0 in this case and the skb should be linearized by skb_copy_expand already. The check isn't triggered because this line is wrong:

diff = v->data_len - e->skb->len

skb->len is the total length, including fragments. If we want to copy to it, we either need to linearize it or look at skb_headlen(skb). It's complicated getting everything right, I need to think about it some more.

Quoted 5 lines

Yeah, and for some twisted reason I was figuring on skb_copy_bits to do
that (since it *does* unwind fragment lists, etc). My apologies for the waste of bandwidth.

No problem, your testing provided valuable information about the cause of the problem.

Regards
Patrick

#5 lore raw
In reply to Matt Walters
Quoted 6 lines · Matt Walters
Quoted 4 lines · Patrick McHardy

skb_tailroom should return 0 in this case and the skb should be linearized by skb_copy_expand already. The check isn't triggered because this line is wrong:

Quoted 7 lines
Quoted 7 lines

diff = v->data_len - e->skb->len

skb->len is the total length, including fragments. If we want to copy to it, we either need to linearize it or look at skb_headlen(skb). It's complicated getting everything right, I need to think about it some more.

This patch on top of the ip_queue_nonlinear_skbs patch should fix the problem. It wastes a couple of bytes when enlarging a non-linear skb, but that shouldn't be a problem. When you test it, please try all three possibilities (replace by smaller, equally sized and larger packet).

Regards
Patrick

===== net/ipv4/netfilter/ip_queue.c 1.16 vs edited =====

net/ipv4/netfilter/ip_queue.c +2 -0
@@ -362,6 +362,8 @@
 		}
 		skb_put(e->skb, diff);
 	}
+	if (!skb_ip_make_writable(&e->skb, v->data_len))
+		return -ENOMEM;
 	memcpy(e->skb->data, v->payload, v->data_len);
 	e->skb->nfcache |= NFC_ALTERED;
 
#6 lore raw
Quoted 16 lines · Patrick McHardy
Quoted 6 lines · Matt Walters
Quoted 4 lines · Patrick McHardy

skb_tailroom should return 0 in this case and the skb should be linearized by skb_copy_expand already. The check isn't triggered because this line is wrong:

Quoted 7 lines
Quoted 7 lines

diff = v->data_len - e->skb->len

skb->len is the total length, including fragments. If we want to copy to it, we either need to linearize it or look at skb_headlen(skb). It's complicated getting everything right, I need to think about it some more.

Quoted 7 lines

This patch on top of the ip_queue_nonlinear_skbs patch should fix the problem.
It wastes a couple of bytes when enlarging a non-linear skb, but that shouldn't be
a problem. When you test it, please try all three possibilities (replace by smaller,
equally sized and larger packet).

Thanks Patrick-

A quick test shows that unaltered packets being passed back from
userspace no longer cause kernel panics (yay) but also that they are not being responded to (boo). I'll have a look deeper into it later on.

-Matt

#7 lore raw
Quoted 5 lines · Matt Walters

Thanks Patrick-

A quick test shows that unaltered packets being passed back from
userspace no longer cause kernel panics (yay) but also that they are not being responded to (boo). I'll have a look deeper into it later on.

Patrkick, do you think we should push your make_writable fix to davem yet?

Quoted 1 line

-Matt

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
#8 lore raw
Quoted 5 lines · Harald Welte
Quoted 2 lines · Matt Walters

Thanks Patrick-

Quoted 10 lines
Quoted 5 lines

A quick test shows that unaltered packets being passed back from
userspace no longer cause kernel panics (yay) but also that they are not being responded to (boo). I'll have a look deeper into it later on.

Patrkick, do you think we should push your make_writable fix to davem yet?

No, let's wait until we know what's causing Matt's problems.

Regards
Patrick

#9 lore raw
In reply to Matt Walters

Hi Matt,

Quoted 7 lines · Matt Walters

Thanks Patrick-

A quick test shows that unaltered packets being passed back from
userspace no longer cause kernel panics (yay) but also that they are not being responded to (boo). I'll have a look deeper into it later on.

any news on this ?

Regards
Patrick

Quoted 4 lines

-Matt

#10 lore raw
Quoted 4 lines · Patrick McHardy

Hi Matt,

Matt Walters wrote:

Quoted 8 lines
Quoted 7 lines

Thanks Patrick-

A quick test shows that unaltered packets being passed back from
userspace no longer cause kernel panics (yay) but also that they are not being responded to (boo). I'll have a look deeper into it later on.

any news on this ?

I apologize, work didn't allow me to dig into this last week (pesky
deadlines). This week isn't nearly as insane, so I'll have a look at it and get back to the list.

-Matt

#11 lore raw
In reply to Matt Walters
Quoted 3 lines · Matt Walters

I'm interested in doing further development for netfilter. Please feel
free to add my name to a list somewhere or something.

I missed this before. You are already on the only list, the development list ;) There is no official contributor-list, but we always welcome help. If you're looking for things to do, we have multiple todo-lists in CVS. I can also give you some additional pointers if you want.

Regards
Patrick

#12 lore raw
Quoted 11 lines · Patrick McHardy
Quoted 3 lines · Matt Walters

I'm interested in doing further development for netfilter. Please feel
free to add my name to a list somewhere or something.

I missed this before. You are already on the only list, the development list ;)
There is no official contributor-list, but we always welcome help. If you're looking for things to do, we have multiple todo-lists in CVS. I can also give
you some additional pointers if you want.

That would be luverly. Maybe the next patch I submit will do something
other than short-circuit the path it was intending to mend! ;)

-Matt