From patchwork Tue Feb 19 14:37:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 10819971 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DD162139A for ; Tue, 19 Feb 2019 14:37:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C96C72C5CA for ; Tue, 19 Feb 2019 14:37:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD4AD2C5E7; Tue, 19 Feb 2019 14:37:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 643EC2C5CA for ; Tue, 19 Feb 2019 14:37:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726141AbfBSOhE (ORCPT ); Tue, 19 Feb 2019 09:37:04 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:55596 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725803AbfBSOhE (ORCPT ); Tue, 19 Feb 2019 09:37:04 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1gw6W7-00065B-3H; Tue, 19 Feb 2019 14:37:03 +0000 From: Colin King To: Jens Axboe , linux-block@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next][V2] block: don't dereference a potential null bio pointer until is has been null checked Date: Tue, 19 Feb 2019 14:37:02 +0000 Message-Id: <20190219143702.11926-1-colin.king@canonical.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Colin Ian King The bio pointer is being null checked hence it can be potentially null, however earlier it is being derefefenced on the assignment of front_seg_size. Avoid the dereference issue by only assigning front_seg_size after bios has been null sanity checked. Fixes: dcebd755926b ("block: use bio_for_each_bvec() to compute multi-page bvec count") Signed-off-by: Colin Ian King --- V2: remove front_seg_size assignment when it is declared --- block/blk-merge.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index bed065904677..096947413ea9 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -363,7 +363,7 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q, struct bio_vec bv, bvprv = { NULL }; int prev = 0; unsigned int seg_size, nr_phys_segs; - unsigned front_seg_size = bio->bi_seg_front_size; + unsigned front_seg_size; struct bio *fbio, *bbio; struct bvec_iter iter; @@ -379,6 +379,7 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q, return 1; } + front_seg_size = bio->bi_seg_front_size; fbio = bio; seg_size = 0; nr_phys_segs = 0;