Patchwork [net-next] ipv6: use ipv6_dup_options() from ip6_append_data()

login
register
mail settings
Submitter Eric Dumazet
Date May 17, 2013, 2:53 p.m.
Message ID <1368802393.3301.90.camel@edumazet-glaptop>
Download mbox | patch
Permalink /patch/244666/
State Accepted
Delegated to: David Miller
Headers show

Comments

Eric Dumazet - May 17, 2013, 2:53 p.m.
From: Eric Dumazet <edumazet@google.com>

On Fri, 2013-05-17 at 21:58 +0800, Herbert Xu wrote:

> However, I think this function is just as buggy as the original
> code that I replaced.  If you look at the code that fills in the
> options in ip6_datagram_send_ctl, you'll find that the options do
> not lie in the memory area of the opt + opt->tot_len.  They instead
> point to data in the cmsg.
> 
> So I think we should
> 
> 1) fix ipv6_dup_options to do what I tried do but in a non-buggy way;
> 2) make the UDP path use it.
> 
> BTW, in the UDP path we also have a socket so we can just charge the
> memory to it and avoid using kmalloc at all.

OK, so I guess for stable we should use kzalloc(), and work on a cleanup
in net-next.

Thanks !

[PATCH] ipv6: fix possible crashes in ip6_cork_release()

commit 0178b695fd6b4 ("ipv6: Copy cork options in ip6_append_data")
added some code duplication and bad error recovery, leading to potential
crash in ip6_cork_release() as kfree() could be called with garbage.

use kzalloc() to make sure this wont happen.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
Cc: Neal Cardwell <ncardwell@google.com>
---
 net/ipv6/ip6_output.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Herbert Xu - May 17, 2013, 11:36 p.m.
On Fri, May 17, 2013 at 07:53:13AM -0700, Eric Dumazet wrote:
>
> OK, so I guess for stable we should use kzalloc(), and work on a cleanup
> in net-next.

I agree.  Thank you.
David Miller - May 18, 2013, 7:57 p.m.
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Fri, 17 May 2013 07:53:13 -0700

> [PATCH] ipv6: fix possible crashes in ip6_cork_release()
> 
> commit 0178b695fd6b4 ("ipv6: Copy cork options in ip6_append_data")
> added some code duplication and bad error recovery, leading to potential
> crash in ip6_cork_release() as kfree() could be called with garbage.
> 
> use kzalloc() to make sure this wont happen.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Applied and queued up for -stable, thanks.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index d2eedf1..dae1949 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -1147,7 +1147,7 @@  int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
 			if (WARN_ON(np->cork.opt))
 				return -EINVAL;
 
-			np->cork.opt = kmalloc(opt->tot_len, sk->sk_allocation);
+			np->cork.opt = kzalloc(opt->tot_len, sk->sk_allocation);
 			if (unlikely(np->cork.opt == NULL))
 				return -ENOBUFS;