Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9176510pxu; Mon, 28 Dec 2020 08:29:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJxOrKNIb4uA2apL5/u43D822ChmrAnTtWmwl0dSk99vLOdGX50Bp2bbHo1UysZLefEWSoCE X-Received: by 2002:a17:906:ae0c:: with SMTP id le12mr42575502ejb.283.1609172944209; Mon, 28 Dec 2020 08:29:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609172944; cv=none; d=google.com; s=arc-20160816; b=ELiuHqPMud8kG59NtaoZwCf2K6WOwwVoJ9KR15DXW0TWMWfRJBQWhGQcw8G917pgaR UD7/rouaJPlzVth9QBSeQiEptGYjVuyekW5I7DtClR+uIoM7en5eTSjSugYgAO5GxJ0f UuZ0MglYU7JNXe9z05DGePOTdwjPPg38feiYG3LSPZxlSxQ3E0xm3H9SkyXa0NAiGYMh HHzet80wLiokrmXw/aE5Rxy1BHlh8QIFJ3FumIu4k2g7SunZ31Xxfk3pO+DcxU/XzU+P HUuTKffFALwl5XmVQkFj3KYluEc7xTYYaJXsa2OMQzRtyNlm0FJd9J5RxHDDoO5slV0j zb7w== 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=Ama7rk6azDyTuLuYlBFSa0sQC/fSOghw+LcMwXueOuw=; b=Lw5ZciglbrKVTgN45zb6ODAY6YwZjZmuItigZkSFoGAbtHpBTxKDoJxGvoSu4Qikka ROlLkY0cMx0i0tFppZ/v7m0/luozbH2ULkwOzawHtbmBrWdRH7tL3r4nrePFH8VxRcxT NReKFmMbjVeJOeFE/FJdbjc+uCjjDz9SBt+f4AlotnHOXiy7aN/HgUvE0DNgt5jxfV9R v54A9TmugpcLBp1I8iBat1fBpnOGkgYi1dWGr5JniyafbET0Te52NzqfikYB51JIt86P zI9+dC9pqmRzaGXe2VNz/UMWxRDgP7fFSxk8OpOIj8ruwKcXn1xjrTovkABvI/Qmwxba Yxrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XpCbKWyY; 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 u17si20596436edo.494.2020.12.28.08.28.41; Mon, 28 Dec 2020 08:29:04 -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=XpCbKWyY; 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 S1731577AbgL1QYx (ORCPT + 99 others); Mon, 28 Dec 2020 11:24:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:37570 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731268AbgL1NKH (ORCPT ); Mon, 28 Dec 2020 08:10:07 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DC221206ED; Mon, 28 Dec 2020 13:09:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160991; bh=1DaF/85+Whecx+sQMqbF/Fotl1ecWKjQJQYQl9Jn2ZI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XpCbKWyYRt8NYqaTf3a7dwfDVjj0SQMYl+hoZ66z6gdTlwdmcdU62hhFJ6Zy8W92a iMoTirkC4aBWY4YYMQGwtOSusqjBFvO4aAs8Kdd3Y53atLqF/QiRZtfEyDG9RYP49g lLuwP4b93Dv//0jPgpTAaZ+EC7ZGkfpvNzHYnkSw= 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.14 063/242] md: fix a warning caused by a race between concurrent md_ioctl()s Date: Mon, 28 Dec 2020 13:47:48 +0100 Message-Id: <20201228124907.785123170@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@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 @@ -7187,8 +7187,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);