netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xfrm bugs with mark logic
@ 2010-07-02 10:40 Peter Kosyh
  2010-07-02 15:01 ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Kosyh @ 2010-07-02 10:40 UTC (permalink / raw)
  To: netdev

Hello! I am currently working with 2.6.34, trying to use iptables ...
-j MARK with XFRM policy. So, i found at least
two bugs in 2.6.34 kernel.

First bug is just typo in  xfrm_mark_get (net/xfrm.h):

memcpy(m, nla_data(attrs[XFRMA_MARK]), sizeof(m));

must be:

memcpy(m, nla_data(attrs[XFRMA_MARK]), sizeof(*m));

The second one, is clearing mark in flowi structure via memset in
_decode_session4 (net/ipv4/xfrm4_policy.c).
(see net/ipv4/netfilter.c, ip_route_me_harder function)
int ip_route_me_harder(struct sk_buff *skb, unsigned addr_type)
/* ... */
        if (addr_type == RTN_LOCAL) {
/* ... */
                fl.mark = skb->mark; /* here, set mark from skb */
/* ... */
#ifdef CONFIG_XFRM
        if (!(IPCB(skb)->flags & IPSKB_XFRM_TRANSFORMED) &&
            xfrm_decode_session(skb, &fl, AF_INET) == 0) { /* here
fl->mark will be zeroed */
            /* ... */
            if (xfrm_lookup(net, &dst, &fl, skb->sk, 0)) /* here
policy lookup will fail */

Do not know about ipv6 anything, but it's like that it affected by
this bug too. :(

P.S. Sorry for my bad English. :)

w.b.r. Peter Kosyh

diff -Nur linux-2.6.34/include/net/xfrm.h linux-2.6.34.fix/include/net/xfrm.h
--- linux-2.6.34/include/net/xfrm.h	2010-05-16 21:17:36.000000000 +0000
+++ linux-2.6.34.fix/include/net/xfrm.h	2010-07-02 10:05:33.000000000 +0000
@@ -1587,7 +1587,7 @@
 static inline int xfrm_mark_get(struct nlattr **attrs, struct xfrm_mark *m)
 {
 	if (attrs[XFRMA_MARK])
-		memcpy(m, nla_data(attrs[XFRMA_MARK]), sizeof(m));
+		memcpy(m, nla_data(attrs[XFRMA_MARK]), sizeof(*m));
 	else
 		m->v = m->m = 0;
diff -Nur linux-2.6.34/net/ipv4/xfrm4_policy.c
linux-2.6.34.fix/net/ipv4/xfrm4_policy.c
--- linux-2.6.34/net/ipv4/xfrm4_policy.c	2010-05-16 21:17:36.000000000 +0000
+++ linux-2.6.34.fix/net/ipv4/xfrm4_policy.c	2010-07-02 10:17:51.000000000 +0000
@@ -186,6 +186,7 @@
 	fl->fl4_dst = reverse ? iph->saddr : iph->daddr;
 	fl->fl4_src = reverse ? iph->daddr : iph->saddr;
 	fl->fl4_tos = iph->tos;
+	fl->mark = skb->mark;
 }

 static inline int xfrm4_garbage_collect(struct dst_ops *ops)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-07-02 16:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-02 10:40 [PATCH] xfrm bugs with mark logic Peter Kosyh
2010-07-02 15:01 ` Eric Dumazet
2010-07-02 16:24   ` Peter Kosyh
2010-07-02 16:59     ` Eric Dumazet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).