lkml.org 
[lkml]   [2018]   [Mar]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH AUTOSEL for 3.18 20/63] tcp: sysctl: Fix a race to avoid unexpected 0 window from space
    Date
    From: Gao Feng <fgao@ikuai8.com>

    [ 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 <fgao@ikuai8.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
    Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
    ---
    include/net/tcp.h | 8 +++++---
    1 file changed, 5 insertions(+), 3 deletions(-)

    diff --git a/include/net/tcp.h b/include/net/tcp.h
    index 2cd7003a8a19..15564a2cc28c 100644
    --- a/include/net/tcp.h
    +++ b/include/net/tcp.h
    @@ -1099,9 +1099,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 */
    --
    2.14.1
    \
     
     \ /
      Last update: 2018-03-03 23:53    [W:4.154 / U:0.100 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site