netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tcp: cookie transactions setsockopt memory leak
@ 2010-07-29 11:59 Dmitry Popov
  2010-07-31  6:05 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Popov @ 2010-07-29 11:59 UTC (permalink / raw)
  To: David S. Miller, Alexey Kuznetsov, James Morris, Patrick McHardy
  Cc: Pekka Savola (ipv6), Hideaki YOSHIFUJI, Eric Dumazet,
	Ilpo Järvinen, Andrew Morton, Steven J. Magnani, netdev,
	linux-kernel, William Allen Simpson

From: Dmitry Popov <dp@highloadlab.com>

There is a bug in do_tcp_setsockopt(net/ipv4/tcp.c),
TCP_COOKIE_TRANSACTIONS case.
In some cases (when tp->cookie_values == NULL) new tcp_cookie_values
structure can be allocated (at cvp), but not bound to
tp->cookie_values. So a memory leak occurs.

Signed-off-by: Dmitry Popov <dp@highloadlab.com>
---
tp->cookie_values can be NULL if socket was initialized with
sysctl_tcp_cookie_size == 0 (tcp_v4_init_sock, net/ipv4/tcp_ipv4.c)
Buggy releases: 2.6.33+ (since commit e56fb50f2b7958b931c8a2fc0966061b3f3c8f3a)

 net/ipv4/tcp.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 83d0213..9c490a1 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -2179,6 +2179,8 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
 				      GFP_KERNEL);
 			if (cvp == NULL)
 				return -ENOMEM;
+
+			kref_init(&cvp->kref);
 		}
 		lock_sock(sk);
 		tp->rx_opt.cookie_in_always =
@@ -2193,12 +2195,11 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
 				 */
 				kref_put(&tp->cookie_values->kref,
 					 tcp_cookie_values_release);
-				kref_init(&cvp->kref);
-				tp->cookie_values = cvp;
 			} else {
 				cvp = tp->cookie_values;
 			}
 		}
+
 		if (cvp != NULL) {
 			cvp->cookie_desired = ctd.tcpct_cookie_desired;

@@ -2212,6 +2213,8 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
 				cvp->s_data_desired = ctd.tcpct_s_data_desired;
 				cvp->s_data_constant = 0; /* false */
 			}
+
+			tp->cookie_values = cvp;
 		}
 		release_sock(sk);
 		return err;

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

* Re: [PATCH] tcp: cookie transactions setsockopt memory leak
  2010-07-29 11:59 [PATCH] tcp: cookie transactions setsockopt memory leak Dmitry Popov
@ 2010-07-31  6:05 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2010-07-31  6:05 UTC (permalink / raw)
  To: dp
  Cc: kuznet, jmorris, kaber, pekkas, yoshfuji, eric.dumazet,
	ilpo.jarvinen, akpm, steve, netdev, linux-kernel,
	william.allen.simpson

From: Dmitry Popov <dp@highloadlab.com>
Date: Thu, 29 Jul 2010 15:59:36 +0400

> From: Dmitry Popov <dp@highloadlab.com>
> 
> There is a bug in do_tcp_setsockopt(net/ipv4/tcp.c),
> TCP_COOKIE_TRANSACTIONS case.
> In some cases (when tp->cookie_values == NULL) new tcp_cookie_values
> structure can be allocated (at cvp), but not bound to
> tp->cookie_values. So a memory leak occurs.
> 
> Signed-off-by: Dmitry Popov <dp@highloadlab.com>

Applied and queued up for -stable, thanks Dmitry.

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

end of thread, other threads:[~2010-07-31  6:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-29 11:59 [PATCH] tcp: cookie transactions setsockopt memory leak Dmitry Popov
2010-07-31  6:05 ` David Miller

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