summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorDmitry Popov <dp@highloadlab.com>2010-07-29 01:59:36 +0000
committerGreg Kroah-Hartman <gregkh@suse.de>2010-08-26 16:43:42 -0700
commit77c043b1e3a8bbb264fca4018fc518e179324fef (patch)
tree8026b54fd48817fe06d0b5e8ba62395659b26095 /net
parent73be303e5c91ee98bfd67a5fba755ebc29aae391 (diff)
tcp: cookie transactions setsockopt memory leak
[ Upstream commit a3bdb549e30e7a263f7a589747c40e9c50110315 ] 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> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'net')
-rw-r--r--net/ipv4/tcp.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 296150b2a62f..4fbf48132869 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -2175,6 +2175,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 =
@@ -2189,12 +2191,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;
@@ -2208,6 +2209,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;