Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp663805pxv; Thu, 15 Jul 2021 12:51:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxj6Sy8YfKuatT3QMjrcel/XTkj/kWJ6ANrHP06ZNLQ/ovoKjNIKL+KQXVK5RvP06mW98m/ X-Received: by 2002:a05:6402:31bb:: with SMTP id dj27mr9023351edb.375.1626378674076; Thu, 15 Jul 2021 12:51:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626378674; cv=none; d=google.com; s=arc-20160816; b=YmrAVS0yiHbKA8k0v71OaGHDqrdFcEoiKUpJyh8dByPjOC53EHd1eLtiNKQzdqx+fP QJVKwmvFE0yev+GUAdJxDv0yHF/g+cxrTbn0Y1tNKiMJtZHLBLqqAXYf07UULw768LYz IlXvEioh8jeUqNSVanAQZ6NkMz7Ur90HiGA9L1ETsGnNj9u85vp/V2IK51ggCrsVsr3D aL7gyUN/F7zocViYCltsdLVi4C2o0yyld9u9htaLJ7YbQDKjD9qRo6XKtUqvW8GsxENd VCtQaMltO2PrG7cGJSNKZdGUB4HxUGkMLfMXwMMOCiH+KwyhrMuMLf1tZF2PnCUMWFxr tVgw== 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=mmYUGSEGkcOM1v1/QWCOvNHBCRygB+lTaYJERlMFMH0=; b=gfExZlVsY2wa2dL+XzQAiv0YJirQRi6ME8CAfX214qKrfmDrr1FuB97x8k/sNrXfW4 1T84BJoiS60KNTyyAELt/tT1fA4UaWrkTBqDBTqUpq0oBQwf7acLXRPtKBS39PZ//Kme mMSr45q4x3/UOjm6kK3DUk3vW4aydLX4u6bT2Xu4at9GJg1TxtaxJ5518rcjcTmcqyre wLK+00y0GCXhAPHOlJWWRE1t09O4kkZoFPkpCZg2AbB9WtKyhffEzcW1YP1ArQrcx+8v IC2AaKRvZWRXUXtJwbNgrQ8Zc48CeDOsR4GOHIhHLTUaYLrDjWuO4QzebJpe7zQVD/Q1 nLfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BV693sN6; 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 z19si4349637edb.235.2021.07.15.12.50.51; Thu, 15 Jul 2021 12:51:14 -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=@linuxfoundation.org header.s=korg header.b=BV693sN6; 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 S240869AbhGOTr6 (ORCPT + 99 others); Thu, 15 Jul 2021 15:47:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:58178 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242879AbhGOTRN (ORCPT ); Thu, 15 Jul 2021 15:17:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5B966613F3; Thu, 15 Jul 2021 19:12:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626376369; bh=C1ShubNXVTEITTM499ROiCEtSal1Awt21Bbup50aTP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BV693sN6JYoMGOafVLvX8F38yXnGolt7F3GXzvZCqinCiG+nw0ZTwOPlJSDy15lqL Kxsfn0hojUdAfe6G8Fv3NPYUdMfBFuPPh+krLoSvbBkxivcfJc7gREZbqzYKwyhqSc xD8x8hFDj42I77WKFROhp+Zl/ApoU7qaO8HguEUI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hou Tao , Mike Snitzer Subject: [PATCH 5.13 241/266] dm btree remove: assign new_root only when removal succeeds Date: Thu, 15 Jul 2021 20:39:56 +0200 Message-Id: <20210715182651.114971217@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182613.933608881@linuxfoundation.org> References: <20210715182613.933608881@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: Hou Tao commit b6e58b5466b2959f83034bead2e2e1395cca8aeb upstream. remove_raw() in dm_btree_remove() may fail due to IO read error (e.g. read the content of origin block fails during shadowing), and the value of shadow_spine::root is uninitialized, but the uninitialized value is still assign to new_root in the end of dm_btree_remove(). For dm-thin, the value of pmd->details_root or pmd->root will become an uninitialized value, so if trying to read details_info tree again out-of-bound memory may occur as showed below: general protection fault, probably for non-canonical address 0x3fdcb14c8d7520 CPU: 4 PID: 515 Comm: dmsetup Not tainted 5.13.0-rc6 Hardware name: QEMU Standard PC RIP: 0010:metadata_ll_load_ie+0x14/0x30 Call Trace: sm_metadata_count_is_more_than_one+0xb9/0xe0 dm_tm_shadow_block+0x52/0x1c0 shadow_step+0x59/0xf0 remove_raw+0xb2/0x170 dm_btree_remove+0xf4/0x1c0 dm_pool_delete_thin_device+0xc3/0x140 pool_message+0x218/0x2b0 target_message+0x251/0x290 ctl_ioctl+0x1c4/0x4d0 dm_ctl_ioctl+0xe/0x20 __x64_sys_ioctl+0x7b/0xb0 do_syscall_64+0x40/0xb0 entry_SYSCALL_64_after_hwframe+0x44/0xae Fixing it by only assign new_root when removal succeeds Signed-off-by: Hou Tao Cc: stable@vger.kernel.org Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/persistent-data/dm-btree-remove.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/md/persistent-data/dm-btree-remove.c +++ b/drivers/md/persistent-data/dm-btree-remove.c @@ -549,7 +549,8 @@ int dm_btree_remove(struct dm_btree_info delete_at(n, index); } - *new_root = shadow_root(&spine); + if (!r) + *new_root = shadow_root(&spine); exit_shadow_spine(&spine); return r;