Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp355645rdb; Fri, 17 Nov 2023 00:10:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFpd/SC7Uv2X1zTsf7hu9cI98WPiuJ34MN8RhiI/06q7mvT8isnzz07wsQlkrh91nTpd2ZE X-Received: by 2002:a17:902:dace:b0:1ce:5f67:cfd3 with SMTP id q14-20020a170902dace00b001ce5f67cfd3mr697262plx.18.1700208646265; Fri, 17 Nov 2023 00:10:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700208646; cv=none; d=google.com; s=arc-20160816; b=rbUjl8rcXJS0KT912nK3UeA2bykK6BcUthY9nZVFhjId8ZLhz71PODKWDsWBE/Ln8M 3nhcUcrhGwC5Qlpt1ra+dKRocwXMmXsNAvbQHMHTXG0kfenJxMFs2aAFswcYrWbd0K8v uXUN3P05EAJtRxZOvYCQEGpkBrdj/WjLT1Zftu81GxBi/IlBOS07Ix0ahO09HdiQpwqV mO7PY1vAw8cwonVFC4YnpGE6ELfIHwfAHTLSfFVw8Llhhiizp1EU1fOhaGWIf3uwNhhG g8d+r8qo8XtGivnqLpzkpuUPjkZkHM+O0o57uThIhHWxZWT9EskQA84/2fYl0oLNw3ZC X+uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=vBfOo1hgsgHzPr67TD5otwLRDs2vbyHjrpju+fppnnI=; fh=3W/oC3ea+3u00IETVyo8STTf7yxYCngWSASMGqf7Oo8=; b=a6f6be8Krp4oiV9wFpTlVcSSZhuxfDXObj5h8e9MluVxTAs78KZ9s3PNVEH8wlTYQT oIbZODDs7uU7P+zpdo+uvXltUmK3eGJGPPJt5i6/othm7cO0kGgqs1ggDnHQQMRDQ06K f78QWei1jbTbB0CPolM8zGgAR8SwAK/QJGbWGq8TS41CutnaPbJCTN5NVv8qHXw4hGuj xLl0Vze6Fsi4Z4ivBsJomBgg1VQTqdYTZyY0N7aDwt4o4t8NeLfc9k2u9fJ11yq5wpYT agmVZdMf8/5JQFb3kCJ8N85W7aa2P1dgqFrjOa0cFpJ1ShRWftBDetJzSzdKD+f5YrOn gdqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id 11-20020a170902c14b00b001cc0e39373bsi1298562plj.32.2023.11.17.00.10.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 00:10:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 3A4F081BE2E7; Fri, 17 Nov 2023 00:10:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231405AbjKQIKa (ORCPT + 99 others); Fri, 17 Nov 2023 03:10:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231445AbjKQIK2 (ORCPT ); Fri, 17 Nov 2023 03:10:28 -0500 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F00F130 for ; Fri, 17 Nov 2023 00:10:25 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r3tvT-0005ZF-4D; Fri, 17 Nov 2023 09:10:07 +0100 Received: from [2a0a:edc0:2:b01:1d::c0] (helo=ptx.whiteo.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r3tvO-009d5q-RY; Fri, 17 Nov 2023 09:10:02 +0100 Received: from ore by ptx.whiteo.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1r3tvO-002Tie-O0; Fri, 17 Nov 2023 09:10:02 +0100 Date: Fri, 17 Nov 2023 09:10:02 +0100 From: Oleksij Rempel To: Ziqi Zhao Cc: ivan.orlov0322@gmail.com, edumazet@google.com, syzbot+881d65229ca4f9ae8c84@syzkaller.appspotmail.com, socketcan@hartkopp.net, bridge@lists.linux-foundation.org, nikolay@nvidia.com, syzbot+1591462f226d9cbf0564@syzkaller.appspotmail.com, roopa@nvidia.com, kuba@kernel.org, pabeni@redhat.com, arnd@arndb.de, syzkaller-bugs@googlegroups.com, mudongliangabcd@gmail.com, linux-can@vger.kernel.org, mkl@pengutronix.de, skhan@linuxfoundation.org, robin@protonic.nl, linux-kernel@vger.kernel.org, linux@rempel-privat.de, kernel@pengutronix.de, netdev@vger.kernel.org, davem@davemloft.net Subject: Re: [PATCH] can: j1939: prevent deadlock by changing j1939_socks_lock to rwlock Message-ID: <20231117081002.GA590719@pengutronix.de> References: <20230704064710.3189-1-astrajoan@yahoo.com> <20230721162226.8639-1-astrajoan@yahoo.com> <20230807044634.GA5736@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230807044634.GA5736@pengutronix.de> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-Accept-Language: de,en X-Accept-Content-Type: text/plain User-Agent: Mutt/1.10.1 (2018-07-13) X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 17 Nov 2023 00:10:43 -0800 (PST) On Mon, Aug 07, 2023 at 06:46:34AM +0200, Oleksij Rempel wrote: > On Fri, Jul 21, 2023 at 09:22:26AM -0700, Ziqi Zhao wrote: > > The following 3 locks would race against each other, causing the > > deadlock situation in the Syzbot bug report: > > > > - j1939_socks_lock > > - active_session_list_lock > > - sk_session_queue_lock > > > > A reasonable fix is to change j1939_socks_lock to an rwlock, since in > > the rare situations where a write lock is required for the linked list > > that j1939_socks_lock is protecting, the code does not attempt to > > acquire any more locks. This would break the circular lock dependency, > > where, for example, the current thread already locks j1939_socks_lock > > and attempts to acquire sk_session_queue_lock, and at the same time, > > another thread attempts to acquire j1939_socks_lock while holding > > sk_session_queue_lock. > > > > NOTE: This patch along does not fix the unregister_netdevice bug > > reported by Syzbot; instead, it solves a deadlock situation to prepare > > for one or more further patches to actually fix the Syzbot bug, which > > appears to be a reference counting problem within the j1939 codebase. > > > > Reported-by: syzbot+1591462f226d9cbf0564@syzkaller.appspotmail.com > > Signed-off-by: Ziqi Zhao Reviewed-by: Oleksij Rempel -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |