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

* Re: [PATCH] xfrm bugs with mark logic
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2010-07-02 15:01 UTC (permalink / raw)
  To: Peter Kosyh; +Cc: netdev

Le vendredi 02 juillet 2010 à 14:40 +0400, Peter Kosyh a écrit :
> 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)
> --

Hi Peter

XFRMA_MARK part already in net-2.6 tree :

http://git.kernel.org/?p=linux/kernel/git/davem/net-2.6.git;a=commit;h=4efd7e833591721bec21cc4730a7f6261417840f

Please submit another patch the second problem you spotted ?





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

* Re: [PATCH] xfrm bugs with mark logic
  2010-07-02 15:01 ` Eric Dumazet
@ 2010-07-02 16:24   ` Peter Kosyh
  2010-07-02 16:59     ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Kosyh @ 2010-07-02 16:24 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: netdev

[-- Attachment #1: Type: text/plain, Size: 335 bytes --]

> 
> Hi Peter
> 
> XFRMA_MARK part already in net-2.6 tree :
> 
> http://git.kernel.org/?p=linux/kernel/git/davem/net-2.6.git;a=commit;h=4efd7e833591721bec21cc4730a7f6261417840f
> 
> Please submit another patch the second problem you spotted ?
> 

Yes, i see. Here it is, but i am little unsure about ipv6 fix.

-- 
w.b.r. Peter Kosyh

[-- Attachment #2: linux-2.6.36-xfrm-mark.patch --]
[-- Type: text/plain, Size: 1036 bytes --]

diff -Nur linux-2.6.35-rc3.orig/net/ipv4/xfrm4_policy.c linux-2.6.35-rc3/net/ipv4/xfrm4_policy.c
--- linux-2.6.35-rc3.orig/net/ipv4/xfrm4_policy.c	2010-06-12 06:14:04.000000000 +0400
+++ linux-2.6.35-rc3/net/ipv4/xfrm4_policy.c	2010-07-02 20:20:49.000000000 +0400
@@ -108,6 +108,8 @@
 	u8 *xprth = skb_network_header(skb) + iph->ihl * 4;
 
 	memset(fl, 0, sizeof(struct flowi));
+	fl->mark = skb->mark;
+
 	if (!(iph->frag_off & htons(IP_MF | IP_OFFSET))) {
 		switch (iph->protocol) {
 		case IPPROTO_UDP:
diff -Nur linux-2.6.35-rc3.orig/net/ipv6/xfrm6_policy.c linux-2.6.35-rc3/net/ipv6/xfrm6_policy.c
--- linux-2.6.35-rc3.orig/net/ipv6/xfrm6_policy.c	2010-06-12 06:14:04.000000000 +0400
+++ linux-2.6.35-rc3/net/ipv6/xfrm6_policy.c	2010-07-02 20:20:22.000000000 +0400
@@ -124,6 +124,8 @@
 	u8 nexthdr = nh[IP6CB(skb)->nhoff];
 
 	memset(fl, 0, sizeof(struct flowi));
+	fl->mark = skb->mark;
+
 	ipv6_addr_copy(&fl->fl6_dst, reverse ? &hdr->saddr : &hdr->daddr);
 	ipv6_addr_copy(&fl->fl6_src, reverse ? &hdr->daddr : &hdr->saddr);
 

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

* Re: [PATCH] xfrm bugs with mark logic
  2010-07-02 16:24   ` Peter Kosyh
@ 2010-07-02 16:59     ` Eric Dumazet
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2010-07-02 16:59 UTC (permalink / raw)
  To: Peter Kosyh; +Cc: netdev

Le vendredi 02 juillet 2010 à 20:24 +0400, Peter Kosyh a écrit :
> > 
> > Hi Peter
> > 
> > XFRMA_MARK part already in net-2.6 tree :
> > 
> > http://git.kernel.org/?p=linux/kernel/git/davem/net-2.6.git;a=commit;h=4efd7e833591721bec21cc4730a7f6261417840f
> > 
> > Please submit another patch the second problem you spotted ?
> > 
> 
> Yes, i see. Here it is, but i am little unsure about ipv6 fix.
> 

Seems fine, but please read Documentation/SubmittingPatches to submit an
official patch.

Thanks !



^ 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).