Re: [PATCH net v5] net: ax25: Fix deadlock caused by skb_recv_datagram in ax25_recvmsg

From: Eric Dumazet
Date: Tue Jun 14 2022 - 10:48:25 EST


On Tue, Jun 14, 2022 at 2:26 AM Duoming Zhou <duoming@xxxxxxxxxx> wrote:
>
> The skb_recv_datagram() in ax25_recvmsg() will hold lock_sock
> and block until it receives a packet from the remote. If the client
> doesn`t connect to server and calls read() directly, it will not
> receive any packets forever. As a result, the deadlock will happen.
>
> The fail log caused by deadlock is shown below:
>
> This patch replaces skb_recv_datagram() with an open-coded variant of it
> releasing the socket lock before the __skb_wait_for_more_packets() call
> and re-acquiring it after such call in order that other functions that
> need socket lock could be executed.
>
> what's more, the socket lock will be released only when recvmsg() will
> block and that should produce nicer overall behavior.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Suggested-by: Thomas Osterried <thomas@xxxxxxxxxxxx>
> Signed-off-by: Duoming Zhou <duoming@xxxxxxxxxx>
> Reported-by: Thomas Habets <thomas@@habets.se>
> Acked-by: Paolo Abeni <pabeni@xxxxxxxxxx>
> ---

Reviewed-by: Eric Dumazet <edumazet@xxxxxxxxxx>