From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FAD0200CE for ; Thu, 13 Jul 2023 22:23:44 +0000 (UTC) Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EAC6359A for ; Thu, 13 Jul 2023 15:23:16 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-676f16e0bc4so832438b3a.0 for ; Thu, 13 Jul 2023 15:23:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1689286988; x=1691878988; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=gPJRqg7ajyeL4du6RG8R0w4sPMlBCtxY9hG6485AJxc=; b=tkAIp3Mxs21mO0syOvSfhIJnKbHEVEWbvFyzLoto2x01rHRZ8u1RSlARS0Jjlpqp60 mwI0Ec4wbZb4Tb3Gl0z6J1C+dotBmDCo7JoSo5Q46IEFDvJy+Gw2H8Vsh8+z0So4FqQ/ 0ljRfD3HTiiUR3KT2bc+9DvNkkWRwCSMB1GL6eXyfF/ox2YPReN074r8Y6q63gDBPQUj ibJfaqcG+mnZ6j5SNPPaKgafx/W9hAED42Op91PlcJaZ7h5JlLZ1/P5I/i7xnu4eTbZY SNeV6g82RNy5LBSs826Z7HTv+YPXpWVnyR4UXj7Ci13ol3xKBgDH9gF0D0byBnGA7i4Z yhHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689286988; x=1691878988; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gPJRqg7ajyeL4du6RG8R0w4sPMlBCtxY9hG6485AJxc=; b=cFuZATsmoRU3Mz0Sson+j8O6GLW0GQRF7r4e+5IwzRTrPcnzhOBZDYpH1gHWg/kRxb yxkkH/B6aQORlw36g09VwAXsag0qEgkJ2eCd72LaFUztkCaScEkA9nARWhk5hbd+kjY0 3dczFtRvhJPxPFRqRQ23/K2oo3RJiboU76zCVQe6Mdyn0rDYVwtj6jYxng+X9KDb/W1z /U6lhLpAV1pus4v6mQ+mQLCd6EJ7OLvl5vvmposDdvEILFgHesGvfoc2xMi8UxP5gv5c /KLIqHEXGTYwmVINFOdtE7PfW0RyqmpmTuxBxWOkLIL+8nsjZWB4PYdjDbfU6D63MAbf x3lQ== X-Gm-Message-State: ABy/qLZvvJ10/RFv93yc0PbdLNURJ2V5vs/8lEWQ2pfd+M6jbGeuD88l UgPaS32DKBkTRT3qboD+vf85CQ== X-Google-Smtp-Source: APBJJlFHVWSKYJGwaAF7RyGQ4hb39qQwi3/2ZA1sbjnSW0v8O2cboYPbu0mc5q6Qgzb9OnBBytt9Ag== X-Received: by 2002:a05:6a00:1a51:b0:657:f26e:b01a with SMTP id h17-20020a056a001a5100b00657f26eb01amr2433653pfv.26.1689286987833; Thu, 13 Jul 2023 15:23:07 -0700 (PDT) Received: from hermes.local (204-195-116-219.wavecable.com. [204.195.116.219]) by smtp.gmail.com with ESMTPSA id j20-20020aa79294000000b006833bcc95b0sm2482755pfa.115.2023.07.13.15.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 15:23:07 -0700 (PDT) Date: Thu, 13 Jul 2023 15:23:05 -0700 From: Stephen Hemminger To: Ziqi Zhao Cc: syzbot+1591462f226d9cbf0564@syzkaller.appspotmail.com, davem@davemloft.net, dvyukov@google.com, 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, o.rempel@pengutronix.de, pabeni@redhat.com, robin@protonic.nl, skhan@linuxfoundation.org, socketcan@hartkopp.net, syzkaller-bugs@googlegroups.com, syzkaller@googlegroups.com Subject: Re: [PATCH] can: j1939: prevent deadlock by changing j1939_socks_lock to rwlock Message-ID: <20230713152305.153e7aba@hermes.local> In-Reply-To: <20230712004750.2476-1-astrajoan@yahoo.com> References: <000000000000b57ce3060025aa46@google.com> <20230712004750.2476-1-astrajoan@yahoo.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net On Tue, 11 Jul 2023 17:47:50 -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. > > #syz test: > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master > > Signed-off-by: Ziqi Zhao > --- Reader-writer locks are not the best way to fix a lock hierarchy problem. Instead either fix the lock ordering, or use RCU. Other devices don't have this problem, so perhaps the unique locking in this device is the problem.