On 7/8/20 4:18 PM, Christoph Paasch wrote:
> syzkaller found its way into setsockopt with TCP_CONGESTION "cdg".
> tcp_cdg_init() does a kcalloc to store the gradients. As sk_clone_lock
> just copies all the memory, the allocated pointer will be copied as
> well, if the app called setsockopt(..., TCP_CONGESTION) on the listener.
> If now the socket will be destroyed before the congestion-control
> has properly been initialized (through a call to tcp_init_transfer), we
> will end up freeing memory that does not belong to that particular
> socket, opening the door to a double-free:
> 


> Wei Wang fixed a part of these CDG-malloc issues with commit c12014440750
> ("tcp: memset ca_priv data to 0 properly").
> 
> This patch here fixes the listener-scenario: We make sure that listeners
> setting the congestion-control through setsockopt won't initialize it
> (thus CDG never allocates on listeners). For those who use AF_UNSPEC to
> reuse a socket, tcp_disconnect() is changed to cleanup afterwards.
> 
> (The issue can be reproduced at least down to v4.4.x.)
> 
> Cc: Wei Wang <wei...@google.com>
> Cc: Eric Dumazet <eduma...@google.com>
> Fixes: 2b0a8c9eee81 ("tcp: add CDG congestion control")
> Signed-off-by: Christoph Paasch <cpaa...@apple.com>
> ---
> 
> Notes:
>     v2: Rather prevent listeners from initializign congestion-control state 
> and
>         make sure tcp_disconnect() cleans up for those that want to re-use 
> sockets
>         with AF_UNSPEC (suggested by Eric)

SGTM, thanks.

Signed-off-by: Eric Dumazet <eduma...@google.com>

Reply via email to