[PATCH 2/5] tcp: small user_mss code change

From: Dmitry Popov
Date: Wed Oct 27 2010 - 09:28:17 EST


From: Dmitry Popov <dp@xxxxxxxxxxxxxxx>

No double access to user_mss part of socket.

This is done to prevent possible race conditions if accessed without
socket lock.

Signed-off-by: Dmitry Popov <dp@xxxxxxxxxxxxxxx>
---
net/ipv4/tcp_ipv4.c | 7 ++++---
net/ipv4/tcp_output.c | 6 ++++--
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 3de881e..c7e9b2a 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1510,6 +1510,7 @@ struct sock *tcp_v4_syn_recv_sock(struct sock
*sk, struct sk_buff *skb,
struct inet_sock *newinet;
struct tcp_sock *newtp;
struct sock *newsk;
+ int user_mss;
#ifdef CONFIG_TCP_MD5SIG
struct tcp_md5sig_key *key;
#endif
@@ -1545,9 +1546,9 @@ struct sock *tcp_v4_syn_recv_sock(struct sock
*sk, struct sk_buff *skb,
tcp_mtup_init(newsk);
tcp_sync_mss(newsk, dst_mtu(dst));
newtp->advmss = dst_metric(dst, RTAX_ADVMSS);
- if (tcp_sk(sk)->rx_opt.user_mss &&
- tcp_sk(sk)->rx_opt.user_mss < newtp->advmss)
- newtp->advmss = tcp_sk(sk)->rx_opt.user_mss;
+ user_mss = tcp_sk(sk)->rx_opt.user_mss;
+ if (user_mss && user_mss < newtp->advmss)
+ newtp->advmss = user_mss;

tcp_initialize_rcv_mss(newsk);

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index eef2d66..561a7f3 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -2416,6 +2416,7 @@ struct sk_buff *tcp_make_synack(struct sock *sk,
struct dst_entry *dst,
struct tcp_md5sig_key *md5;
int tcp_header_size;
int mss;
+ int user_mss;
int s_data_desired;

rcu_read_lock();
@@ -2439,8 +2440,9 @@ struct sk_buff *tcp_make_synack(struct sock *sk,
struct dst_entry *dst,
skb_dst_set(skb, dst_clone(dst));

mss = dst_metric(dst, RTAX_ADVMSS);
- if (tp->rx_opt.user_mss && tp->rx_opt.user_mss < mss)
- mss = tp->rx_opt.user_mss;
+ user_mss = tp->rx_opt.user_mss;
+ if (user_mss && user_mss < mss)
+ mss = user_mss;

if (req->rcv_wnd == 0) { /* ignored for retransmitted syns */
__u8 rcv_wscale;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/