mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-07 19:30:30 +09:00
tcp: sysctl: Fix a race to avoid unexpected 0 window from space
[ Upstream commit c48367427a ]
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>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
84353d9d99
commit
694f219a60
@@ -1265,9 +1265,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 */
|
||||
|
||||
Reference in New Issue
Block a user