summaryrefslogtreecommitdiffstats
path: root/include/net/tcp.h
diff options
context:
space:
mode:
authorGao Feng2017-03-24 00:05:12 +0100
committerDavid S. Miller2017-03-24 21:29:16 +0100
commitc48367427a39ea0b85c7cf018fe4256627abfd9e (patch)
tree740f51767793ae5765a0ecedc931c1704d0bbf06 /include/net/tcp.h
parentnet: make in_aton() 32-bit internally (diff)
downloadkernel-qcow2-linux-c48367427a39ea0b85c7cf018fe4256627abfd9e.tar.gz
kernel-qcow2-linux-c48367427a39ea0b85c7cf018fe4256627abfd9e.tar.xz
kernel-qcow2-linux-c48367427a39ea0b85c7cf018fe4256627abfd9e.zip
tcp: sysctl: Fix a race to avoid unexpected 0 window from space
Because sysctl_tcp_adv_win_scale could be changed any time, so there is one race in tcp_win_from_space. For example, 1.sysctl_tcp_adv_win_scale<=0 (sysctl_tcp_adv_win_scale is negative now) 2.space>>(-sysctl_tcp_adv_win_scale) (sysctl_tcp_adv_win_scale is postive now) As a result, tcp_win_from_space returns 0. It is unexpected. Certainly if the compiler put the sysctl_tcp_adv_win_scale into one register firstly, then use the register directly, it would be ok. But we could not depend on the compiler behavior. Signed-off-by: Gao Feng <fgao@ikuai8.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/tcp.h')
-rw-r--r--include/net/tcp.h8
1 files changed, 5 insertions, 3 deletions
diff --git a/include/net/tcp.h b/include/net/tcp.h
index e614ad4d613e..582e3772c0d9 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1248,9 +1248,11 @@ void tcp_select_initial_window(int __space, __u32 mss, __u32 *rcv_wnd,
static inline int tcp_win_from_space(int space)
{
- return sysctl_tcp_adv_win_scale<=0 ?
- (space>>(-sysctl_tcp_adv_win_scale)) :
- space - (space>>sysctl_tcp_adv_win_scale);
+ int tcp_adv_win_scale = sysctl_tcp_adv_win_scale;
+
+ return tcp_adv_win_scale <= 0 ?
+ (space>>(-tcp_adv_win_scale)) :
+ space - (space>>tcp_adv_win_scale);
}
/* Note: caller must be prepared to deal with negative returns */