Skip to contentSkip to conversation

Fragment ID wrap workaround (read-only, untested).

PATCH Rusty Russell (IBM) 2 participants 2 messages Jul 15, 2004

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi all,

I spoke about this today, thought I'd send the code out. Useful only
for reading, as it's entirely untested and some is tricky and needs careful thinking.

Name: Fragment ID Wrap Workaround
Status: Untested

There's at least one old IBM Bugzilla bug, in which fragement IDs wrapped, causing NFS data corruption on UDP stresstesting.

Solution presented here is twofold:

1) Move the offset of the fragments every time the ID wraps (usually the packet doesn't fit exactly into the MTU, so we have some slack), and

2) Check overlapping fragments that the contents match: if not, drop the whole thing.

Note that I also implemented skb_iter functions, so I could compare the fragment overlap efficiently: really should be a separate patch. DaveM points out (FIXME) that doing the double walk means we need to guarantee two kmaps for the networking code.

Also applies to IPv6. Simpler implementation would just drop all fragments on any overlap as a "doesn't happen IRL" case (it needs someone to duplicate a packet, then send each one by a different MTU path).

include/linux/ip.h +1 -1
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .4882-linux-2.6.7-bk20/include/linux/ip.h .4882-linux-2.6.7-bk20.updated/include/linux/ip.h
@@ -118,12 +118,12 @@ struct inet_opt {
 	int			tos;		/* TOS */
 	unsigned	   	cmsg_flags;
 	struct ip_options	*opt;
+	__u32			id;		/* ID counter for DF pkts */
 	__u16			sport;		/* Source port */
 	unsigned char		hdrincl;	/* Include headers ? */
 	__u8			mc_ttl;		/* Multicasting TTL */
 	__u8			mc_loop;	/* Loopback */
 	__u8			pmtudisc;
-	__u16			id;		/* ID counter for DF pkts */
 	unsigned		recverr : 1,
 				freebind : 1;
 	int			mc_index;	/* Multicast device index */
include/linux/skbuff.h +17 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .4882-linux-2.6.7-bk20/include/linux/skbuff.h .4882-linux-2.6.7-bk20.updated/include/linux/skbuff.h
@@ -1108,6 +1108,23 @@ extern void	       skb_split(struct sk_b
 extern void skb_init(void);
 extern void skb_add_mtu(int mtu);
 
+struct skb_iter
+{
+	/* Iteration functions set these */
+	unsigned char *data;
+	unsigned int len;
+
+	/* Private to iteration */
+	unsigned int nextfrag;
+	struct sk_buff *fraglist;
+};
+
+/* Keep iterating until skb_iter_next returns false. */
+extern void skb_iter_first(const struct sk_buff *skb, struct skb_iter *i);
+extern int skb_iter_next(const struct sk_buff *skb, struct skb_iter *i);
+/* Call this if aborting loop before !skb_iter_next */
+extern void skb_iter_abort(const struct sk_buff *skb, struct skb_iter *i);
+
 #ifdef CONFIG_NETFILTER
 static inline void nf_conntrack_put(struct nf_ct_info *nfct)
 {
net/core/skbuff.c +64 -0

70 lines not on this page · raw message

net/ipv4/ip_fragment.c +95 -9

137 lines not on this page · raw message

net/ipv4/ip_output.c +32 -9

58 lines not on this page · raw message

#1 lore raw

net/ipv4/ip_output.c slow_path: · line 604

Quoted 9 lines
net/ipv4/ip_output.c +9 -0
+	 * other end detect ID wrap. */
+	if (skb->sk) {
+		unsigned int slack;
+		struct inet_opt *inet = inet_sk(skb->sk);
+
+		slack = (left % mtu);
+		if (slack)
+			/* Shift by 8 bytes per id wrap. */
+			len = mtu - (slack % ((inet->id >> 16) << 3));

I'm pretty sure inet->id is wrong here. You would like the counter in the inet peer entry. inet_sk(sk)->id is just used for the pseudo counter in TCP that only works around VJ compression bugs. It's never used for real fragmentation.

-Andi