Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp770653pxv; Thu, 15 Jul 2021 15:52:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8T0MkgK6lEfiyXV3FCteM4I2CVhAY6Reh11i1wA4wH+39evHvT/3u5lSGOEe5QnmQME6Z X-Received: by 2002:a05:6402:b88:: with SMTP id cf8mr10317947edb.6.1626389532758; Thu, 15 Jul 2021 15:52:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626389532; cv=none; d=google.com; s=arc-20160816; b=Ym08Q63kgS8z28/gRpb1mG8bwo32QafCHJwXN5+RgEjoOnQ8OMKmGq8QdHaLN3fBfB IQKgau9NNxA9fGffVuANwqdwvNrjiYoJkcOxAncMjHwByaydIf/x9Darfp2kczSKLb9d VXDqsSKeGlrLUkmicijuHa/oEc5Bat1rbSwyG5umZHbgtiBSK6xuw0ZhMerpwoo9s6Sj m5JHjcSpTO2X4n40fedQnT+ovgBvxLwwp4ocRlkMLrh/Np/XCNCDMkh0NrXDEVCStNsq mRFo3BPnKB4/08t+7SaIeBkmwJV9FncYctajsGn++ySTxOIKuFvGYZ7GnyYgqIfYjIca 30JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Fnq99CBndTSa11XoYul2i2zzP0Ahu5GTMFaY6L9qYQM=; b=tXXfKa6nvp2BupXhHM52p8Lcu2FULjLo7WWqV2jV/9NqQ9/YCiW43ZBW/opCRlun3x XXyOfQNKoy7RmQf5AkNyF5xqao+kcMBOnhZoFp0BpMAPQCNFmStDkucnUW5jIBpS4o0O nCpNc2OT0VzNi1eC1C/F98ius8dP4gsI0c3nI+ky76wu0bfoeTf7nE0syZdZYoZQw353 V19ob4DyY5yOHauUZlg6dMC+mmVazJ8237dRQnI8VS2AcGi+Kb5tZcDA/SU9Y+EY+2ku bm5mcVUVAadEXhTZ50/VEeJf/29Nwn3/tjCQ5bsOcs6yaeeLgQmIFfEbFjnlh6Phhkk1 56tA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j24si9834393ejk.659.2021.07.15.15.51.49; Thu, 15 Jul 2021 15:52:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232238AbhGOWxg (ORCPT + 99 others); Thu, 15 Jul 2021 18:53:36 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:45791 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232139AbhGOWxg (ORCPT ); Thu, 15 Jul 2021 18:53:36 -0400 Received: (Authenticated sender: miquel.raynal@bootlin.com) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 79FB21BF208; Thu, 15 Jul 2021 22:50:40 +0000 (UTC) From: Miquel Raynal To: Desmond Cheong Zhi Xi , miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org, gregkh@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, syzbot+6a8a0d93c91e8fbf2e80@syzkaller.appspotmail.com, Christoph Hellwig Subject: Re: [PATCH v2] mtd: break circular locks in register_mtd_blktrans Date: Fri, 16 Jul 2021 00:50:40 +0200 Message-Id: <20210715225040.66117-1-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210617160904.570111-1-desmondcheongzx@gmail.com> References: MIME-Version: 1.0 X-linux-mtd-patch-notification: thanks X-linux-mtd-patch-commit: b'962bf783ef65d15b0f8ca9c33342cf3b20bf0d2e' Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2021-06-17 at 16:09:04 UTC, Desmond Cheong Zhi Xi wrote: > Syzbot reported a circular locking dependency: > https://syzkaller.appspot.com/bug?id=7bd106c28e846d1023d4ca915718b1a0905444cb > > This happens because of the following lock dependencies: > > 1. loop_ctl_mutex -> bdev->bd_mutex (when loop_control_ioctl calls > loop_remove, which then calls del_gendisk; this also happens in > loop_exit which eventually calls loop_remove) > > 2. bdev->bd_mutex -> mtd_table_mutex (when blkdev_get_by_dev calls > __blkdev_get, which then calls blktrans_open) > > 3. mtd_table_mutex -> major_names_lock (when register_mtd_blktrans > calls __register_blkdev) > > 4. major_names_lock -> loop_ctl_mutex (when blk_request_module calls > loop_probe) > > Hence there's an overall dependency of: > > loop_ctl_mutex ----------> bdev->bd_mutex > ^ | > | | > | v > major_names_lock <--------- mtd_table_mutex > > We can break this circular dependency by holding mtd_table_mutex only > for the required critical section in register_mtd_blktrans. This > avoids the mtd_table_mutex -> major_names_lock dependency. > > Reported-and-tested-by: syzbot+6a8a0d93c91e8fbf2e80@syzkaller.appspotmail.com > Co-developed-by: Christoph Hellwig > Signed-off-by: Christoph Hellwig > Signed-off-by: Desmond Cheong Zhi Xi Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/fixes, thanks. Miquel