Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9446746pxu; Mon, 28 Dec 2020 16:52:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJyXfkiierSBZ5sUMNqiKC7dTva/XC6NxPn+qcquiKmNSA+VGIAIr09kKGxyKirzMeCC+kfo X-Received: by 2002:a50:c3c5:: with SMTP id i5mr44467988edf.166.1609203176932; Mon, 28 Dec 2020 16:52:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609203176; cv=none; d=google.com; s=arc-20160816; b=kt2Pvn2t8RtcbmQ9/aCKVhCzukeh+M1DmTzfwG9oC2+55s//VweOoYri7n5oKt4ieV W+zTB2XvjXHxf87H2mjMNQHah0odbmqrz5LrEQcRKQDa2+xhYW4IRQDAUKCX3JAMubSH QRELLcDeU0umhkX2Dc+2fNxMch1dqAfMoYYGuuCDVtkYDXJgM/9/TJ7kaYwsehW8vPOs /jqem52S6Tvz53hfUQOCSBjrkQLJkI3ho8XjLHptwUmiMgGY/dTFBNQFRC2qJY0Iqa3Q Ctl3P6TV9147isplbC4tSrQlUJvnP88EcH8BziDZicqe8t3/gisZ6l74srzmXmZsbFTK rqPg== 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=W7nW1Nvb/cwZcCC/uaUuDm9HXWt6raTSs1OyCd/pYcs=; b=mpn8ut7utT3zAo1roLUnCybuPEy2aDTqxYVJVCRQ1ODhORsVkq9fss86sONl+2Dh3b hhgRWGW7SOq4iJdvARSLS7EcuNRhT4pxfZ/18CpytvJG9hDG34oUFwa8vH9hdp/ecdlo wO76JUEtPT7CaWSoJie1LfIdzKRE5xgZb0WMkda91saXgghqb8Zyl4GF00u4aakrRg35 kC1OM1tarnSA06qG6QSwsZJk9XhZFaJLlgXk0zlVzpS/1Io3bzhZpz90p/yh9XdiLA+2 C/PBD7GKVSGV+RVD3EKDgCvsb2yfZJ1dvSXBpPc42Oupb+MtAme7HBhzs78YkZWeyqOP PO2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=04OF0eU4; 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 r22si19836234eji.295.2020.12.28.16.52.34; Mon, 28 Dec 2020 16:52:56 -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=04OF0eU4; 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 S2393568AbgL1QJy (ORCPT + 99 others); Mon, 28 Dec 2020 11:09:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:51886 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388622AbgL1NYA (ORCPT ); Mon, 28 Dec 2020 08:24:00 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 38D8E20719; Mon, 28 Dec 2020 13:23:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161824; bh=H6BzZeKckpudv6x4USlSM9Lax6zS4rZ563RWifU4GwQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=04OF0eU4u6cxzRw8zBXGDU05SwAYBcqZwyvnKqHCWj1FKfmh0NjaLrBgjC+bS67mx 6LEZQr6HlVgPGRU+y2FXwW1E6LxmBC8xWRPPwdsVWxUsVmSg/jJ36sA/YO6okOoi6n GUP/zfW/3fYN/h4Mc14buY+1T/v4DznWULiUUvxI= 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.19 095/346] md: fix a warning caused by a race between concurrent md_ioctl()s Date: Mon, 28 Dec 2020 13:46:54 +0100 Message-Id: <20201228124924.389380874@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124919.745526410@linuxfoundation.org> References: <20201228124919.745526410@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 @@ -7214,8 +7214,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);