Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp735727imm; Thu, 13 Sep 2018 07:02:17 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbFxkB8jSyP4QmNeoMSTbpImZILHNU/s7KlNON9s4b2r8Da9FVJdRVD3eJljrBbMpKJMIJI X-Received: by 2002:a65:4384:: with SMTP id m4-v6mr7293931pgp.265.1536847337073; Thu, 13 Sep 2018 07:02:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847337; cv=none; d=google.com; s=arc-20160816; b=qN2VgT2Sre/wYd1BMvD1wGG5BbhbPA8lW4lDe9p/HJGSJTVam7cx3kPrTUcP375a3e zj4k1hdD/C6ZxE9yIeclf6EoKPU9mNOGs79EYHia1zKtUeaCurKjRL9mDWhafxi5NqmR RCNqEch898F03LJlKogJ+U9f5l7uEnRJaQnquEhZIDg9TNo/fjc2f5CLtZIaoeh0qB35 xHER/dB+pf/V8qeYQLWwy3kcqxOLzo+BTjTu5+Ets6We4ihhwJjlHf3ZvndEuT/J6PUQ w5fbcM0BmJC/3tyU4HDaoI4S+IiEchH9VMEOBWhTdMG9b3L3WYdIRkUetd01ArmDbmvU s3mw== 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; bh=JYQup5A9a+qG/eC0yZpmPGLB1m8B24N/xAk4+rIIbss=; b=qL6jpRF71kVnQ3Oa16qF6YFiyvgigoM9aGrZNje3B4tUKpdbdENYRQyXA/6vd2cGLn oN3HYerwhsXNgKyGaFV6QWFlIt6Ix67pw9eZE0/nqWeuFTSLqnqz1aVmadyxgbElR2xJ FlTu+4fylrV05IEt9QpIkvvhH/XLcoSb5fMzJzYd82CgrUOj74xPYdZudISTcrV4CZiE G7trt/3J1Gbi4jcABvIVvpC1xxlbEDo2El1B9kRS11s0yfJgW8S74dDDL4WxOePrYNuB vhLVEup9K6VOiR1LyHWm0qeNZMIyzE5utpjhcN0fm7V8/M6Kin6fZ7oYrWBIsZGKDOVq pXlQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 35-v6si4235613pgz.453.2018.09.13.07.01.57; Thu, 13 Sep 2018 07:02:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731808AbeIMTLB (ORCPT + 99 others); Thu, 13 Sep 2018 15:11:01 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:35026 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730449AbeIMTLA (ORCPT ); Thu, 13 Sep 2018 15:11:00 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 07274D19; Thu, 13 Sep 2018 14:01:21 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , David Sterba , Sasha Levin Subject: [PATCH 4.18 138/197] btrfs: check-integrity: Fix NULL pointer dereference for degraded mount Date: Thu, 13 Sep 2018 15:31:27 +0200 Message-Id: <20180913131847.077236851@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Qu Wenruo [ Upstream commit 9912bbf6440ba0555e91d3306520da01872c7c1d ] Commit f8f84b2dfda5 ("btrfs: index check-integrity state hash by a dev_t") changed how btrfsic indexes device state. Now we need to access device->bdev->bd_dev, while for degraded mount it's completely possible to have device->bdev as NULL, thus it will trigger a NULL pointer dereference at mount time. Fix it by checking if the device is degraded before accessing device->bdev->bd_dev. There are a lot of other places accessing device->bdev->bd_dev, however the other call sites have either checked device->bdev, or the device->bdev is passed from btrfsic_map_block(), so it won't cause harm. Fixes: f8f84b2dfda5 ("btrfs: index check-integrity state hash by a dev_t") Signed-off-by: Qu Wenruo Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/check-integrity.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/fs/btrfs/check-integrity.c +++ b/fs/btrfs/check-integrity.c @@ -1539,7 +1539,12 @@ static int btrfsic_map_block(struct btrf } device = multi->stripes[0].dev; - block_ctx_out->dev = btrfsic_dev_state_lookup(device->bdev->bd_dev); + if (test_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state) || + !device->bdev || !device->name) + block_ctx_out->dev = NULL; + else + block_ctx_out->dev = btrfsic_dev_state_lookup( + device->bdev->bd_dev); block_ctx_out->dev_bytenr = multi->stripes[0].physical; block_ctx_out->start = bytenr; block_ctx_out->len = len;