Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9184768pxu; Mon, 28 Dec 2020 08:42:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1RvXoLeE7f4NAeTvBuo9iL278RshezZ4A345qlgTxHUoVTowBzNeu6UlNmFy8TaHbK/vj X-Received: by 2002:a05:6402:1a30:: with SMTP id be16mr43554526edb.124.1609173730752; Mon, 28 Dec 2020 08:42:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609173730; cv=none; d=google.com; s=arc-20160816; b=BxS2edrDW3BU0ovZu8vzQiVJC0j2P+apn6VGXgFxSIsx8AFGmOgCpaFGcOSLf3rP/O rvdsLRBt3W8aoVmU8WogrK9b1h2dnPZ0g1vE+AVE/2wpOI113if/jiTiZRebDyAdMEuL IYyH9dZu1cIVgGT0KmrjtY9kquFUKgvHPHeAJSgJ6cekvYQBHrMCoeeeYLK4aPO+niQs CP/sYcrJVxKtN15PgFtlQxrGj68cFecx2ETSyJZLaqRqVObY5CtIhWNO+hhl2u1wW9DR 7QdHfNwFEsIr2ePQg/ZVgEzGr8ISe8ZGVt7RgdNv67iZs2Jy/Atdbl0yF+iwfmQoHw+I w5CQ== 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=eqrZUqPFdlDK4G7JlyZD0fTnQxtVFYIibYru3LxPno8=; b=Zac261qg6NNZmN/DddjLkHQ3e3R0D/ev+MTFE40KcIom7fu+iqkd1IMY5koeV3OyEq 3Q9xensciPtzkV1ORm8e4AKoTXeLx7tpJZDj454HL0X2P9eNWrUBApC6kE2za8A0/p/b Kl0nTS7LMsYwQJJAplZxnv+MvbYeDljkBUD6uyO/NKDgVRUm2t8x+UQbAxeZ8NB2r15O /xZExOcRLtbxmC8ruEcXyPz5YKYeYUOYc808oE2/UJMX/bcZj1uTQKyxoq9iRrurj3FI miP1crAMpYJ+jAp7cMHjdsvmDM90rhI/lBhVFVmBIDpCuCuXD1Z9bfjbd2kR/8ygvwOX W0/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Pkl2IlYy; 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 u9si20112860edd.26.2020.12.28.08.41.48; Mon, 28 Dec 2020 08:42:10 -0800 (PST) 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=Pkl2IlYy; 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 S2633769AbgL1QjC (ORCPT + 99 others); Mon, 28 Dec 2020 11:39:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:57558 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729731AbgL1NBK (ORCPT ); Mon, 28 Dec 2020 08:01:10 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 81922208B6; Mon, 28 Dec 2020 13:00:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160430; bh=JuwKukq8lgf5WbumW5sYzDx3og/QUFn4dWKuiTmMJN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pkl2IlYywPh0jb56wngpUp8tMx0EKVaRWFbWKGpypp2y4X1pv6qmq6ilS+jLJ9dGR 6DgqTu3lPTvx6nCLgXO2mUlfcdEhBBS1Le1QXYLe41uKSr+iosS4c6rZozcH4cVYWh /0enF88ZjQ48GJ+i6HE6OKxKP7BhKh8Pz4zE3/ic= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+1e46a0864c1a6e9bd3d8@syzkaller.appspotmail.com, "Dae R. Jeong" , Song Liu Subject: [PATCH 4.9 048/175] md: fix a warning caused by a race between concurrent md_ioctl()s Date: Mon, 28 Dec 2020 13:48:21 +0100 Message-Id: <20201228124855.584925250@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124853.216621466@linuxfoundation.org> References: <20201228124853.216621466@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: Dae R. Jeong commit c731b84b51bf7fe83448bea8f56a6d55006b0615 upstream. Syzkaller reports a warning as belows. WARNING: CPU: 0 PID: 9647 at drivers/md/md.c:7169 ... Call Trace: ... RIP: 0010:md_ioctl+0x4017/0x5980 drivers/md/md.c:7169 RSP: 0018:ffff888096027950 EFLAGS: 00010293 RAX: ffff88809322c380 RBX: 0000000000000932 RCX: ffffffff84e266f2 RDX: 0000000000000000 RSI: ffffffff84e299f7 RDI: 0000000000000007 RBP: ffff888096027bc0 R08: ffff88809322c380 R09: ffffed101341a482 R10: ffff888096027940 R11: ffff88809a0d240f R12: 0000000000000932 R13: ffff8880a2c14100 R14: ffff88809a0d2268 R15: ffff88809a0d2408 __blkdev_driver_ioctl block/ioctl.c:304 [inline] blkdev_ioctl+0xece/0x1c10 block/ioctl.c:606 block_ioctl+0xee/0x130 fs/block_dev.c:1930 vfs_ioctl fs/ioctl.c:46 [inline] file_ioctl fs/ioctl.c:509 [inline] do_vfs_ioctl+0xd5f/0x1380 fs/ioctl.c:696 ksys_ioctl+0xab/0xd0 fs/ioctl.c:713 __do_sys_ioctl fs/ioctl.c:720 [inline] __se_sys_ioctl fs/ioctl.c:718 [inline] __x64_sys_ioctl+0x73/0xb0 fs/ioctl.c:718 do_syscall_64+0xfd/0x680 arch/x86/entry/common.c:301 entry_SYSCALL_64_after_hwframe+0x49/0xbe This is caused by a race between two concurrenct md_ioctl()s closing the array. CPU1 (md_ioctl()) CPU2 (md_ioctl()) ------ ------ set_bit(MD_CLOSING, &mddev->flags); did_set_md_closing = true; WARN_ON_ONCE(test_bit(MD_CLOSING, &mddev->flags)); if(did_set_md_closing) clear_bit(MD_CLOSING, &mddev->flags); Fix the warning by returning immediately if the MD_CLOSING bit is set in &mddev->flags which indicates that the array is being closed. Fixes: 065e519e71b2 ("md: MD_CLOSING needs to be cleared after called md_set_readonly or do_md_stop") Reported-by: syzbot+1e46a0864c1a6e9bd3d8@syzkaller.appspotmail.com Cc: stable@vger.kernel.org Signed-off-by: Dae R. Jeong Signed-off-by: Song Liu Signed-off-by: Greg Kroah-Hartman --- drivers/md/md.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -6857,8 +6857,11 @@ static int md_ioctl(struct block_device err = -EBUSY; goto out; } - WARN_ON_ONCE(test_bit(MD_CLOSING, &mddev->flags)); - set_bit(MD_CLOSING, &mddev->flags); + if (test_and_set_bit(MD_CLOSING, &mddev->flags)) { + mutex_unlock(&mddev->open_mutex); + err = -EBUSY; + goto out; + } did_set_md_closing = true; mutex_unlock(&mddev->open_mutex); sync_blockdev(bdev);