Skip to content

Commit 65c161c

Browse files
gfreewindgregkh
authored andcommitted
tcp: sysctl: Fix a race to avoid unexpected 0 window from space
[ Upstream commit c48367427a39ea0b85c7cf018fe4256627abfd9e ] 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 <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4ae1886 commit 65c161c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

include/net/tcp.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,9 +1099,11 @@ void tcp_select_initial_window(int __space, __u32 mss, __u32 *rcv_wnd,
10991099

11001100
static inline int tcp_win_from_space(int space)
11011101
{
1102-
return sysctl_tcp_adv_win_scale<=0 ?
1103-
(space>>(-sysctl_tcp_adv_win_scale)) :
1104-
space - (space>>sysctl_tcp_adv_win_scale);
1102+
int tcp_adv_win_scale = sysctl_tcp_adv_win_scale;
1103+
1104+
return tcp_adv_win_scale <= 0 ?
1105+
(space>>(-tcp_adv_win_scale)) :
1106+
space - (space>>tcp_adv_win_scale);
11051107
}
11061108

11071109
/* Note: caller must be prepared to deal with negative returns */

0 commit comments

Comments
 (0)