Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3922541pxb; Mon, 4 Oct 2021 12:43:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUCxu+a0TSykgzIVKjF7a7c9bKXgNir8SsymXatlZ1svhQG3jNUaObiP301VcFJo06QnQA X-Received: by 2002:aa7:d59a:: with SMTP id r26mr20205084edq.86.1633376611332; Mon, 04 Oct 2021 12:43:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633376611; cv=none; d=google.com; s=arc-20160816; b=GE+eQM0xW9fCpqQqqmMjhqVS7zRClqVrNf9SWXxIiaPoqtTOtoJpw5CihyljfWkQuq E+OEfA8cy+U594vQUzseaVunmUq1ZmZOQa0PvjbiynA8IfGA51dtrZbX+DDzaDZ3Btco a07qiOmG32mX0oAsidZHZTzDVxEYF83b6Xjg2Y6HLHLvnCNZ+377KN19KeJALglsg0ij snR4wLt69BOipOeXHaQhY2NPtNW6ZOOtXcBVlL1c5JkgiQuOnYZKUKwhM/pFfs+MZ1VJ s+D7m9mvwW7xX0fatJt9wHMjSBP0keMqhgNghjT1NJvmicoGLBqnvYKX8nEsFfISKcZa BmKQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wNS7qYz/TkF9+1Dd3Pmo9oC3TDdt0lyEgehJ3DhsaEU=; b=or63ZUpKroN31sRoCI2JOKeVzPJSGXsx5VFomQPr5G8NjoWGRI0cLa6I3YPgD+jskd jC+PePTus7gKy9N+tG/xZnp9uPbBzi2wgvujkPoC1KuybShM/cs/h0KktYEaiA+E9ohC gSdBJVmu8lLVSduvZE6bPrD89xL7IHpUPgjvgAWUAKErdu+lv2ZzRo6n7X/i8xJ1Dud5 uXESmr+w633OVhf229+qXYVgvBc3d2DW9l07kMaE+GP3bLZ9SXVV1shy7QgNx4RRhW+Z CNzXdIv4cruZJefwIDMm8QmwgbeB1iTMh0bJYwC5mjcQypP8G2L/bPeuzvDEfSDmEIGa 2XrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iZPmTwqP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u19si19006656edv.208.2021.10.04.12.43.03; Mon, 04 Oct 2021 12:43:31 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iZPmTwqP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234535AbhJDND4 (ORCPT + 99 others); Mon, 4 Oct 2021 09:03:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:37450 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234102AbhJDNCH (ORCPT ); Mon, 4 Oct 2021 09:02:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9A8946136F; Mon, 4 Oct 2021 12:58:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633352338; bh=TmY0Ggc7kznm0+HSGp0QLZ03YBiBeR1Q6935jrzMTBk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iZPmTwqPSeNY16K76iOmA4sUx2zP7rDoowcXL78qOV945u+66ekuEu0AhQI7ew+MV 9bThJ6v1rLmKuSdmXBchLK5HSm/LaxWIeCiDUq07lZ5Vb1b0kx5aTG0+lK2rjSmUoB wf/qUb816tnEYIlUBpY1KwSJ1fUMiGGx+cvuRWBA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+fadc0aaf497e6a493b9f@syzkaller.appspotmail.com, Christoph Hellwig , NeilBrown , Song Liu , Sasha Levin Subject: [PATCH 4.14 22/75] md: fix a lock order reversal in md_alloc Date: Mon, 4 Oct 2021 14:51:57 +0200 Message-Id: <20211004125032.258530117@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125031.530773667@linuxfoundation.org> References: <20211004125031.530773667@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christoph Hellwig [ Upstream commit 7df835a32a8bedf7ce88efcfa7c9b245b52ff139 ] Commit b0140891a8cea3 ("md: Fix race when creating a new md device.") not only moved assigning mddev->gendisk before calling add_disk, which fixes the races described in the commit log, but also added a mddev->open_mutex critical section over add_disk and creation of the md kobj. Adding a kobject after add_disk is racy vs deleting the gendisk right after adding it, but md already prevents against that by holding a mddev->active reference. On the other hand taking this lock added a lock order reversal with what is not disk->open_mutex (used to be bdev->bd_mutex when the commit was added) for partition devices, which need that lock for the internal open for the partition scan, and a recent commit also takes it for non-partitioned devices, leading to further lockdep splatter. Fixes: b0140891a8ce ("md: Fix race when creating a new md device.") Fixes: d62633873590 ("block: support delayed holder registration") Reported-by: syzbot+fadc0aaf497e6a493b9f@syzkaller.appspotmail.com Signed-off-by: Christoph Hellwig Tested-by: syzbot+fadc0aaf497e6a493b9f@syzkaller.appspotmail.com Reviewed-by: NeilBrown Signed-off-by: Song Liu Signed-off-by: Sasha Levin --- drivers/md/md.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 0af9aa187ce5..5e8706a66c31 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -5375,10 +5375,6 @@ static int md_alloc(dev_t dev, char *name) */ disk->flags |= GENHD_FL_EXT_DEVT; mddev->gendisk = disk; - /* As soon as we call add_disk(), another thread could get - * through to md_open, so make sure it doesn't get too far - */ - mutex_lock(&mddev->open_mutex); add_disk(disk); error = kobject_init_and_add(&mddev->kobj, &md_ktype, @@ -5394,7 +5390,6 @@ static int md_alloc(dev_t dev, char *name) if (mddev->kobj.sd && sysfs_create_group(&mddev->kobj, &md_bitmap_group)) pr_debug("pointless warning\n"); - mutex_unlock(&mddev->open_mutex); abort: mutex_unlock(&disks_mutex); if (!error && mddev->kobj.sd) { -- 2.33.0