Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp1791288iof; Tue, 7 Jun 2022 11:26:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFgP6SIakPeUEshxaXjreyEvA4rLQMjaOPhCxkYKAWLVgmKmP3Mm6Q5zYXOfB0TCNnVsIZ X-Received: by 2002:a17:907:3e15:b0:6fe:f10e:6337 with SMTP id hp21-20020a1709073e1500b006fef10e6337mr28372815ejc.209.1654625993539; Tue, 07 Jun 2022 11:19:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654625993; cv=none; d=google.com; s=arc-20160816; b=Cs86nXH3JfkffjyXK5rkuDHhODoFabMcIL8pG5zTt4hxHkAxaR+iWPrAseHHs8qZx+ cy9oDabGTQvisOZmh0vGFZr92GUTBg9+4zwopkoV5vNQPsROOXiGxjxG7OmPxkX6iw3T 2wcBAfKawXb3CFEy9Rcv9PjvsS4eb967xr8GkGQEYQQcO588geowa4rcJb/TaHdUeUGz 0/u6XrnU324vw9B5UmSzl89E+Wog4qq56IDr6k5TXa3j85JCoMTBtvHFiNZ+qr15nkYz /VAXadtOv0vnaLM0jLydz7bexkAK6permZpRRzFhrFdNCspPtTIIg+qXoFCMcVHDllE3 2SGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=QocnDs5w4TazSvMjzZtEO2lYhuTH55BPpRIi6NIvCgU=; b=wXgNDJ0Lgw33dQEcRHbuK6OlSBb5gyFe6zSgh5iy5hmMIeOSWhzLtWvkbRTc7u52xD nKVl/tZPrukj/Z6X3TWBIh9XewkXtmHakI9jfJYL7n5l5zfcaxBQ6fP88+mIRtIRkwmL nTfgNi/JPj74JpR1AtueyGnIK8O2gkTQmj1nkwL+Ii4Blf7VkRp16Qmyb3F6bhWK+N3N FHIo1CyVyNQfGsHLWUn2CUJc55bOos6+ZGABLujjrmpvf372VH2DQJ1TvDp/lvyEmziL UzYVRkSy5KRmXyWQaI94dRg+xCEfC1fkhxLH4ObfKyEZr9TiZ35z8V+rcEJPq0R7SxxA J1rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=dRIKodz4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i32-20020a0564020f2000b004316c8ba451si5857179eda.488.2022.06.07.11.19.26; Tue, 07 Jun 2022 11:19:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=dRIKodz4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344490AbiFGRGt (ORCPT + 99 others); Tue, 7 Jun 2022 13:06:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237338AbiFGRGl (ORCPT ); Tue, 7 Jun 2022 13:06:41 -0400 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDE3C54037 for ; Tue, 7 Jun 2022 10:06:39 -0700 (PDT) Received: by mail-il1-x131.google.com with SMTP id y16so14685296ili.13 for ; Tue, 07 Jun 2022 10:06:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QocnDs5w4TazSvMjzZtEO2lYhuTH55BPpRIi6NIvCgU=; b=dRIKodz4tDRakIwL0rM81s0k+Y6sZzcFymClpndB8u/CNXlwMmEmdV6eO7OFiQEORL RK+hl2KV8qmY2zotWqT9OqXbxCSCqmtKPR2fKLk/Mb0c+F8ZI2wckPqNLd2ds4vZP1jG C/vot/RN14YqPvaWRF8f28nNs5npMlddiM4VpnBfok8fA8fMw/xmkGhAh8qIwpbGG7zA etgWLnPu1MN2lSSOGQzLJHcc+BFtSeWfbom4aOkEuu1b+IVR71PRroP+Quo3BaXb/zMK WLh8pUvlVbF3b6e3ZlxSjOR9QVU+ORoPadn3wP2qQZvV2aTu6gfnZelrf7gUwLUfRxot fCVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QocnDs5w4TazSvMjzZtEO2lYhuTH55BPpRIi6NIvCgU=; b=K/cf37krr3Ubbcjy/CGqy49yFM90Uqod/jZpl6LvXuQDV0fW5eeoI/uS710Ipt3njF 57z7rgDh+/nB2tBEkqaD3WIvyTDP+p7c0dS3pAWtXsa2c+BGb0e0FTnWYb5Ijj+pJzLC qpy1eOwlnsmt9OEPl/vcBH/6mOj+IVqQGo72MYTU70h/d+gf7iiBiq/4MpX6mGoesdX+ oW4c1qG1w4mGDMqUcrzWJ1Yznd2Kb07DmdD2EunbX/NI/5U4Fkyb/vqAYNMJejDuDueh Z6SlxwFAPS3ugNEKnVyqNy/hY6yNMw7LS4Xr1hTyS0YdmPIRPNdkN0JLf4a8bzOs5jDg GF6w== X-Gm-Message-State: AOAM533LT8jlr9QqJRiiA1cFJyrznAg0E3O5frjs3/R6Pl7waNOc/jnw HSJ+BhbV7itSnSoT9b62TUNr0nHlIOScY4poxpyfFA== X-Received: by 2002:a05:6e02:1e0b:b0:2d1:b5e8:38a0 with SMTP id g11-20020a056e021e0b00b002d1b5e838a0mr17440930ila.296.1654621598804; Tue, 07 Jun 2022 10:06:38 -0700 (PDT) MIME-Version: 1.0 References: <20220607142337.78458-1-duoming@zju.edu.cn> In-Reply-To: <20220607142337.78458-1-duoming@zju.edu.cn> From: Eric Dumazet Date: Tue, 7 Jun 2022 10:06:27 -0700 Message-ID: Subject: Re: [PATCH v2] net: ax25: Fix deadlock caused by skb_recv_datagram in ax25_recvmsg To: Duoming Zhou Cc: LKML , jreuter@yaina.de, Ralf Baechle , David Miller , Jakub Kicinski , Paolo Abeni , netdev , linux-hams@vger.kernel.org, thomas@osterried.de Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 7, 2022 at 7:24 AM Duoming Zhou 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: > > [ 369.606973] INFO: task ax25_deadlock:157 blocked for more than 245 seconds. > [ 369.608919] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. > [ 369.613058] Call Trace: > [ 369.613315] > [ 369.614072] __schedule+0x2f9/0xb20 > [ 369.615029] schedule+0x49/0xb0 > [ 369.615734] __lock_sock+0x92/0x100 > [ 369.616763] ? destroy_sched_domains_rcu+0x20/0x20 > [ 369.617941] lock_sock_nested+0x6e/0x70 > [ 369.618809] ax25_bind+0xaa/0x210 > [ 369.619736] __sys_bind+0xca/0xf0 > [ 369.620039] ? do_futex+0xae/0x1b0 > [ 369.620387] ? __x64_sys_futex+0x7c/0x1c0 > [ 369.620601] ? fpregs_assert_state_consistent+0x19/0x40 > [ 369.620613] __x64_sys_bind+0x11/0x20 > [ 369.621791] do_syscall_64+0x3b/0x90 > [ 369.622423] entry_SYSCALL_64_after_hwframe+0x46/0xb0 > [ 369.623319] RIP: 0033:0x7f43c8aa8af7 > [ 369.624301] RSP: 002b:00007f43c8197ef8 EFLAGS: 00000246 ORIG_RAX: 0000000000000031 > [ 369.625756] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f43c8aa8af7 > [ 369.626724] RDX: 0000000000000010 RSI: 000055768e2021d0 RDI: 0000000000000005 > [ 369.628569] RBP: 00007f43c8197f00 R08: 0000000000000011 R09: 00007f43c8198700 > [ 369.630208] R10: 0000000000000000 R11: 0000000000000246 R12: 00007fff845e6afe > [ 369.632240] R13: 00007fff845e6aff R14: 00007f43c8197fc0 R15: 00007f43c8198700 > > This patch moves the skb_recv_datagram() before lock_sock() in order > that other functions that need lock_sock could be executed. > > Suggested-by: Thomas Osterried > Signed-off-by: Duoming Zhou > Reported-by: Thomas Habets > --- > Changes in v2: > - Make commit messages clearer. > > net/ax25/af_ax25.c | 11 ++++++----- > 1 file changed, 6 insertions(+), 5 deletions(-) > > diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c > index 95393bb2760..02cd6087512 100644 > --- a/net/ax25/af_ax25.c > +++ b/net/ax25/af_ax25.c > @@ -1665,6 +1665,11 @@ static int ax25_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, > int copied; > int err = 0; > > + /* Now we can treat all alike */ > + skb = skb_recv_datagram(sk, flags, &err); > + if (!skb) > + goto done; > + So at this point we have skb=something. This means that the following branch will leak it. if (sk->sk_type == SOCK_SEQPACKET && sk->sk_state != TCP_ESTABLISHED) { err = -ENOTCONN; goto out; // skb will be leaked } > /* > * This works for seqpacket too. The receiver has ordered the > @@ -1675,11 +1680,6 @@ static int ax25_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, > goto out; > } > > - /* Now we can treat all alike */ > - skb = skb_recv_datagram(sk, flags, &err); > - if (skb == NULL) > - goto out; > - > if (!sk_to_ax25(sk)->pidincl) > skb_pull(skb, 1); /* Remove PID */ > > @@ -1725,6 +1725,7 @@ static int ax25_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, > out: > release_sock(sk); > > +done: > return err; > } > > -- > 2.17.1 >