Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp636057pxv; Thu, 15 Jul 2021 12:06:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZZHYQQIeSD6QuX/c0whXHq7ENkdirDBbj6epkcLTFw9tiHCmyR5mRrJ4+zKi0R9Zk5CB0 X-Received: by 2002:a17:906:8252:: with SMTP id f18mr7051178ejx.261.1626375984796; Thu, 15 Jul 2021 12:06:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626375984; cv=none; d=google.com; s=arc-20160816; b=VRH17d1jjCfBRlwq22Y3ubW6iXjlVkdgyQ78yREE2BwchHaJQdlvq0TQyDB/QbZch0 egHB36mzZHTr6ZI0CyoFn+B6AVd6Ew8GUpoqD3Lx4fhV1y6vCfNe7CBysw70T53ANqGQ AD0tdQVNJyA4RGpcljkxb47DOmg1agHnKifSQ8I3Rutad5KdRfMk2omOA/5FrXuIEZUc To1pL1dUPgQps0AsLOq+V5GIVsd9/t8uISyVlQDi4ZgVX6MbmUlYbr2OmDTudOJ/Lgwr kwEOAq/hthTfKHsnf636uXrsLNdDj4CZXt8htg/yxHMDEE1Oa1RX7HTXidUdPdaiI0Hi RMBg== 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=pjnvyr4L+mWGORd6EsEB4ArmSmRfYicXKudpvsTds+85U7vsli73GqoDX+aBSlS5NU 8/4G3YyMPeGdODjFAfKvPXPOyX9QUQFyi52/YUvZgb2pq7vYkmbGVHSf3uPJjkHdmqwy C5RtwXKoWwWXVkwyCRHYzvqKg5CtsJKLNiZpRB87jYVKr9zQ5qhYktw5WCpnGdXdrIe3 EdeUNvhJEf105cyP3B92LQ1Q/A7nUYfID45eBMv9XzY6jAkQhfIz3Da5UD3NRxwPzsHW OBABCSzSOeIbC4tWlteloxkeSMWR5b4O01/VIcc4wtv+tqeYfdaZRWL+LhoJpSFUfxOZ obyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aFHwMr3K; 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 lh10si917255ejb.419.2021.07.15.12.06.00; Thu, 15 Jul 2021 12:06:24 -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=aFHwMr3K; 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 S240580AbhGOTHI (ORCPT + 99 others); Thu, 15 Jul 2021 15:07:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:33068 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241393AbhGOS4x (ORCPT ); Thu, 15 Jul 2021 14:56:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9C13E613E0; Thu, 15 Jul 2021 18:53:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375240; bh=C1ShubNXVTEITTM499ROiCEtSal1Awt21Bbup50aTP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aFHwMr3Ksi4Xe51tU4ugRubvVTzBxF+CkCJ0LOxyB5LwNhNM7AKioqf6brXnFj/QU 9Z9nQxm5hycxekDyq1tvl85Lu1OoAtIkSGuOg8PVB6B/YcMjfAhyZKuf6Xj1d1e4Y+ XpM1eYv2lTYwMXg/sOUJ5J2dgFwADgIhxXMo8qvg= 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.10 197/215] dm btree remove: assign new_root only when removal succeeds Date: Thu, 15 Jul 2021 20:39:29 +0200 Message-Id: <20210715182633.995041761@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182558.381078833@linuxfoundation.org> References: <20210715182558.381078833@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;