Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp712169pxv; Thu, 15 Jul 2021 14:10:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFpkVAt7ZvuEdG4gQZCw3BQpvLvo57IkxXKMh1J9KDwFOpDg2BsgNZDnsWVbELJK8qdjM+ X-Received: by 2002:a17:906:cc15:: with SMTP id ml21mr7930990ejb.49.1626383428871; Thu, 15 Jul 2021 14:10:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626383428; cv=none; d=google.com; s=arc-20160816; b=PzRYJMt+ncWciCvbUPVh2gto53HMAarAY3esw8Vb+Haiaa9iWitutIf4tZpuV6tbHO 95Gfg48nh2VAonOU5elJnLWcn5oaBz6e26DBFOaEUpghStDr2t+hRA05nJh5ybQJxz+h +dEW6Ivuwu9K8AJ+UBcJRhK5NBsJl8LLbyhGyCdG2aa6S+tuVbssEIIwTMYo2JAkMoqg 7DMT5JPoyFTFJGtvkeKlYWu84OOxtysd/y9ivxOR1LSLe9k2UvU6gbsA0fCesHbvpgJJ TgNabOZYdBrN/LzBKu1uf7SykqDo0rk9uAl4XPTFeurx68lkQY1Uc+01VjTEWtcM7uLD 2zkg== 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=dLpOs0JUgz/1o7JNepUxat8GGH9u8w3iuknufJkHOr1RMnTwISXNrDc08AYqrfLTGM 3i/UR19HRF9WpsUscSamzwuEkrDmJMCkw2ku+9/x2x1rbPvy+VLcj6wnu4JrICGdEM5S 6QQfwhprw9FNNKa+O8KbpSDysxa5/IgWUKJ3hgoDjuqdTQINRyjPvXEwrw2Ok24ICPpw aLCdDZCNtGgfCnJkAffltKk9w6qfLI9tWahXiRKVfuF6cdOB3tBt4m9ikII7aY3uG3xs T8AEv9qah9zO5nHdhmprBbyfm2iMaHRJ1ditEV5cgadpiCNUj0fm8RcXotgtOwhBNfO/ fvnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=C1kqboXu; 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 gf2si9962793ejb.500.2021.07.15.14.10.06; Thu, 15 Jul 2021 14:10:28 -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=C1kqboXu; 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 S244973AbhGOTWT (ORCPT + 99 others); Thu, 15 Jul 2021 15:22:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:38862 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242162AbhGOTFv (ORCPT ); Thu, 15 Jul 2021 15:05:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A4AAE601FE; Thu, 15 Jul 2021 19:02:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375741; bh=C1ShubNXVTEITTM499ROiCEtSal1Awt21Bbup50aTP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C1kqboXutq3HjRjAMsByt+ZFgH7FMBj5C6Mu70t0uL1fAOoPe+W7cNNk8OaDxujo4 uRYSQmn7zhmUpfqMLHjOsAtAWPIpnVk3jKmkFMEWHtsPk++7XWHjFYmxHgPJDY4K6q QHoJisUqvlr38WWVjoLCBiCJufjTGHInIydDzzAA= 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.12 217/242] dm btree remove: assign new_root only when removal succeeds Date: Thu, 15 Jul 2021 20:39:39 +0200 Message-Id: <20210715182631.301736460@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182551.731989182@linuxfoundation.org> References: <20210715182551.731989182@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;