From patchwork Mon Aug 17 15:11:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 266450 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB664C433E1 for ; Mon, 17 Aug 2020 15:45:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9215622CF8 for ; Mon, 17 Aug 2020 15:45:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597679101; bh=bpCArGqYhu7XR0T4plFq2F98eNWRFqKGrxCDzFsaknQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=voXyR7dMUYmXu07lY/yntE0eXNcOp1iMjyC+DOQzrYMjXTKctgDTp/QwHvN7RK6vC ha+sUjz5pAjUBy+5vTK55jfWY+PoLEjvwPPUqyOXaF3x9gJuyx+fzLSZluBhATyKiD eLUF2Gd4sUw2TX9yu+WX/gcxkCkUSmnY0tLQrSfw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730553AbgHQPo6 (ORCPT ); Mon, 17 Aug 2020 11:44:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:55930 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387717AbgHQPo4 (ORCPT ); Mon, 17 Aug 2020 11:44:56 -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 CCF3322CF8; Mon, 17 Aug 2020 15:44:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597679095; bh=bpCArGqYhu7XR0T4plFq2F98eNWRFqKGrxCDzFsaknQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ylwX6LekODkLGtVkwVsQt33smWArj1NvO9y8Gt67yrp1Wwr3LsekIl/DDKGoF2OZ1 Jl75aei2rnPynXdJUAgMSGdCWk/mhB2BN/YGPALhjqee+UB2hgk53WfB1RpZ/XcjT6 mg/n8nlejL6gGNamTtA5cqI94JeNz2QtL6vnWxo8= 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.7 054/393] md: raid0/linear: fix dereference before null check on pointer mddev Date: Mon, 17 Aug 2020 17:11:44 +0200 Message-Id: <20200817143822.237081915@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143819.579311991@linuxfoundation.org> References: <20200817143819.579311991@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 41eead9cbee98..d5a5c18813985 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -469,17 +469,18 @@ static blk_qc_t md_make_request(struct request_queue *q, struct bio *bio) struct mddev *mddev = q->queuedata; 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;