Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2622622pxa; Mon, 17 Aug 2020 14:40:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEuP5yjX6GEwLjY9FB6EFljCeXYiI1eH27Q6AAauGL6gSR57noR3r+7hXLtARca9AJ4+oj X-Received: by 2002:a17:906:eb4f:: with SMTP id mc15mr16732851ejb.435.1597700402479; Mon, 17 Aug 2020 14:40:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597700402; cv=none; d=google.com; s=arc-20160816; b=Ry462ZwL33kdR8WJwVq5xHv4dHYr0+9gYojk45NB8ATGqVgYvW+sKLUDeesZy8w+7a bv/fqvhTrdiWqdOxW9K1EApwlL6EH1je9R7WtqYAHEz1Vn9DOMmTnQuAXGX3IJAMwiAy NnbrcUtQz8zetK+TvQtZ2ubuxU2l2sBd4wrzjAGEQJSp4RIhrgdtrpyKvLswLvFcGG7u zZu9f1RuilHYTa6ItVkShz/ZY96rKjxQTrzNaehX+M8dsFjtOxYzZW+RJ/0cp2D/Rw2L 6daJoBTCgzYW8Elb/0eaV0qFadvJ0w7MhE2QJQoYoCsu8ngKCJn40KxwR3hPbNws7jhb /x4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LgytwITeXe1hDtIrO1UlfWSZW49V7VBMDCpQnBaCSLA=; b=Qy3fVhU16oHoEFDY4DtFg6ceMSZfW/a6eit95LxNsx0ni/WigFMDC2GhexNBxXTcsh cJfkJ2FxYOGVnxZeBPTXaFHr07uVtp9zDDmK6Dp9oZKJll1GjQHA/CJU6ngvQ3iYeuAn C2bWtrqdv6/L3DqdymYdYPI85gRMEsyEiCPVK3j5VeEXNNW4d8QMf6LXUacH7xfbSnkk BmViOM55t3bf8G24NxmwG7bvvjqBeONNP7dLQ4HCtgaei1XdJoaf2SvqIl41IhhcVhZE P43KsKr5WIz38HH9GKy+QBHzwyN8rSTku1942tSezyzTktb0tZ+vkhYNteD2+JHgUkOc Wv9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rB0zAR1I; 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=fail (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 i11si11370705edx.429.2020.08.17.14.39.39; Mon, 17 Aug 2020 14:40:02 -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=@kernel.org header.s=default header.b=rB0zAR1I; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729366AbgHQPVe (ORCPT + 99 others); Mon, 17 Aug 2020 11:21:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:41178 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729306AbgHQPU6 (ORCPT ); Mon, 17 Aug 2020 11:20:58 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4BD6D2065C; Mon, 17 Aug 2020 15:20:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597677657; bh=AiOlWcS4Nc4rzG2Flyr2zCMjKAcNKrD8KD3GG6vV3I8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rB0zAR1IS7hc6vXyZDuurCgvKJAJHgPqfq85AktSmEtvAgTCDwEnjOoR4dvumv3dO DJMp37Lpa8Nrty42ecaH4m6DdwvIe6x971TptmUt+8FBxGQv97yJY5kD5ILoFT0c2N JT4iDKM5HgMwpFBRwBeG0k2kfLcOwBvEFH5k7gdE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , "Guilherme G. Piccoli" , Song Liu , Sasha Levin Subject: [PATCH 5.8 062/464] md: raid0/linear: fix dereference before null check on pointer mddev Date: Mon, 17 Aug 2020 17:10:15 +0200 Message-Id: <20200817143836.734203816@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King [ Upstream commit 9a5a85972c073f720d81a7ebd08bfe278e6e16db ] Pointer mddev is being dereferenced with a test_bit call before mddev is being null checked, this may cause a null pointer dereference. Fix this by moving the null pointer checks to sanity check mddev before it is dereferenced. Addresses-Coverity: ("Dereference before null check") Fixes: 62f7b1989c02 ("md raid0/linear: Mark array as 'broken' and fail BIOs if a member is gone") Signed-off-by: Colin Ian King Reviewed-by: Guilherme G. Piccoli Signed-off-by: Song Liu Signed-off-by: Sasha Levin --- drivers/md/md.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index f567f536b529b..90756450b9588 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -470,17 +470,18 @@ static blk_qc_t md_make_request(struct request_queue *q, struct bio *bio) struct mddev *mddev = bio->bi_disk->private_data; unsigned int sectors; - if (unlikely(test_bit(MD_BROKEN, &mddev->flags)) && (rw == WRITE)) { + if (mddev == NULL || mddev->pers == NULL) { bio_io_error(bio); return BLK_QC_T_NONE; } - blk_queue_split(q, &bio); - - if (mddev == NULL || mddev->pers == NULL) { + if (unlikely(test_bit(MD_BROKEN, &mddev->flags)) && (rw == WRITE)) { bio_io_error(bio); return BLK_QC_T_NONE; } + + blk_queue_split(q, &bio); + if (mddev->ro == 1 && unlikely(rw == WRITE)) { if (bio_sectors(bio) != 0) bio->bi_status = BLK_STS_IOERR; -- 2.25.1