Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp27304392rwd; Tue, 4 Jul 2023 00:45:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlHK17OEsvQIvLv/loRu3tS4ra/yIQyTdey0KMGgDzIMmnCePsroNRw5wxTPPWm656Zw1oMl X-Received: by 2002:a05:6a20:430a:b0:12e:7ca2:8706 with SMTP id h10-20020a056a20430a00b0012e7ca28706mr7876216pzk.58.1688456712028; Tue, 04 Jul 2023 00:45:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688456712; cv=none; d=google.com; s=arc-20160816; b=GjGYwPY6OVQJvFnKB8ajXrdWxEA90JUMliBEqJTCRYorQoenR6zdzyq7P6/yeiBvWA 7X7oK2NpR8BdKmqdyp11arFY1MNWNctWhONJnJPD/PDkqZ+1K0ZqAcxVyMuGt/vF9NvU 6QU74OdbOC9bZCYcqB0uhVzGcyvgo1GnODbkAeOR89rcF41ALi85UZ5J+0f3S7NebtV8 xoyAMOnOZFxeTDDXSceJP2dI9S4+Nx8iJ9jJZtoaWnZ0Tb/fiUjpmwr5oQSQq7H3MxUF Kri9d0SLh7TLoupwbGNJDlzorqkwwZ3kDVII5oClwymaU74VgS1sM2lmHnzxTLanl/M8 jRAg== 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=avhYWOD63gJQqmHbvh/+dMAkZY2mWgAg+N++K803aa4=; fh=7P+oit2H+eIIPRaDMnqUilDIHEKKlPQkVGu0ifeUxQs=; b=wqjXtwFAud7mceZJCPABfMum6XhYWlXT6mkhtCqN/kCePou/8UOzPRFpzgxvRgn+fq 5HoCnrN1DAFZq3I8qYAlLt8lNurYALlVF4bhYZ2jARcSizcoJIjr6+lA+wC1RJ2v3duY u9ogxd8pZZAQPNJlAIOYHyz7edhENKCnjrp/anUYBZwxcG7PH9rGxhnoC70sCP5qS5zY wAeR5+smRjppimLX6U8yCoy328BRG/CnVdKVDBawZmlxIn352z7NgNCrvPJ1QmbM28GE hucato//JpNVqX/PXivaSdJB2p0d23zx/FTrP8x0jiB0QzPpehT6AeeZrFVvwCRabwXE Y6qQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z19-20020a63e113000000b00553ced07d15si20897512pgh.368.2023.07.04.00.44.59; Tue, 04 Jul 2023 00:45:12 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231432AbjGDHiB (ORCPT + 99 others); Tue, 4 Jul 2023 03:38:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230195AbjGDHh5 (ORCPT ); Tue, 4 Jul 2023 03:37:57 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8793EAD for ; Tue, 4 Jul 2023 00:37:56 -0700 (PDT) Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qGabR-0005k3-4E; Tue, 04 Jul 2023 09:37:37 +0200 Received: from ore by ptx.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1qGabP-0002j5-5n; Tue, 04 Jul 2023 09:37:35 +0200 Date: Tue, 4 Jul 2023 09:37:35 +0200 From: Oleksij Rempel To: syzbot Cc: astrajoan@yahoo.com, davem@davemloft.net, edumazet@google.com, ivan.orlov0322@gmail.com, kernel@pengutronix.de, kuba@kernel.org, linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, linux@rempel-privat.de, mkl@pengutronix.de, netdev@vger.kernel.org, pabeni@redhat.com, robin@protonic.nl, skhan@linuxfoundation.org, socketcan@hartkopp.net, syzkaller-bugs@googlegroups.com Subject: Re: [PATCH] can: j1939: prevent deadlock by changing j1939_socks_lock to rwlock Message-ID: <20230704073735.GC15522@pengutronix.de> References: <20230704064710.3189-1-astrajoan@yahoo.com> <00000000000002937705ffa3a80b@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <00000000000002937705ffa3a80b@google.com> 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: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SORTED_RECIPS,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=no 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 Mon, Jul 03, 2023 at 11:47:26PM -0700, syzbot 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. > > > > #syz test: > > This crash does not have a reproducer. I cannot test it. > To stress this code path, the socket should be configured with err queue enabled. For example like this: value = 1; setsockopt(priv->sock, SOL_CAN_J1939, SO_J1939_ERRQUEUE, &value, sizeof(value)); sock_opt = SOF_TIMESTAMPING_SOFTWARE | SOF_TIMESTAMPING_OPT_CMSG | SOF_TIMESTAMPING_TX_ACK | SOF_TIMESTAMPING_TX_SCHED | SOF_TIMESTAMPING_OPT_STATS | SOF_TIMESTAMPING_OPT_TSONLY | SOF_TIMESTAMPING_OPT_ID | SOF_TIMESTAMPING_RX_SOFTWARE; setsockopt(priv->sock, SOL_SOCKET, SO_TIMESTAMPING, (char *) &sock_opt, sizeof(sock_opt)); I hope it will help to create the reproducer Regards, Oleksij -- 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 |