Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3570958pxb; Mon, 24 Jan 2022 12:29:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJz31ozSum33U0ekd5NWvgfPf3ztJ9kPHcfe4ZH0GPyO6EJqR4iYZbLuez0+GQdUblONUlbY X-Received: by 2002:a63:2362:: with SMTP id u34mr12954825pgm.441.1643056180332; Mon, 24 Jan 2022 12:29:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643056180; cv=none; d=google.com; s=arc-20160816; b=E3R8JgUTtfl6zrTtXe02tCsGp3khKKiL6D1TdD2V8bHnQqPAOEv3cxiVv6kU0UepNL ajFEnoLssqwErv2wdj14TRZZEUYRizR3jxco3D7tth6OM5wTq0dEFGuEc0nS1qlr3q7e cnxNkNlzUVNH2c1M4VZD92R9c4OhRApscOgiN05EzsdOtJldtW4d5woFyEC3cUuNVyF1 wkec9M8jHm7gvu7jGWQa36cbDQnMOrBKPuLwIPcMuEXS2lqDSFvp5Kx1R3PcXFh7lTfe PxW3PrdBv6hbS4qTORqz4O1kOvYMK9ctpOFSKpzBMImJJtVd1PtYEIRnTKDmwVOIlpCL BJig== 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=kgrCSehFgLZ8gAxZZMSZoA8MjJJlep4v6YwILrgEEBw=; b=GoWk8XmFzO0PHETJ0iXMpjDR2s4aRJbwP2u32zjIzvb4i68CRDi2IgD2vh8PQlFiC/ LANMPWLrgjg7cz/JG70y5Pnb2Eaw1b9TKnTUzBsBmV1+zp0/9qZw1bSWxiy2zF0pl9q/ fYPnrl/VPN2D8c2gZa2qLWz+3rKvuR52HZmQQ+Cn9VXlExMVo01qL1HtJTtXut6zJ3Dn pDg2RRIwERhDHSls3sT6cUODjAmqNuG3D0EGIKmhTo0eiiYjDGLSTHUTObs6zUZ+OGZH Zrs03Yau+ZLl2vWZE/dRe57DA1/aECSwQAu1OpcpJQnA/vXvkCa+vOnz1V6LGCUL18Lb n0sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="EauCXh/n"; 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 s5si14785019pfk.321.2022.01.24.12.29.28; Mon, 24 Jan 2022 12:29:40 -0800 (PST) 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="EauCXh/n"; 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 S1345170AbiAXTb3 (ORCPT + 99 others); Mon, 24 Jan 2022 14:31:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234647AbiAXTWz (ORCPT ); Mon, 24 Jan 2022 14:22:55 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5492C0617A3; Mon, 24 Jan 2022 11:08:50 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 393DBB8121B; Mon, 24 Jan 2022 19:08:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B553C340E5; Mon, 24 Jan 2022 19:08:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643051328; bh=Up/mfvhONYj+Dx9dzEmZmji4FSEdxlZp4ge0yxhkITo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EauCXh/nTNBo4+fQX1diuH2ER1B3vVE9Nn06vTRGRzJAQ46ZCqHS6IaqKTk/3iae1 WMuDRoq6ST2ly5LsRU8noGD7iYWYZfi4A+QT9wzNBhvh0lx15IYrRveq7rt7/m/LkY zQwVfhwu8NJtWjlNw6f4DJ4ssu8CceivmMyw+Wng= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joe Thornber , Mike Snitzer , Sasha Levin Subject: [PATCH 4.14 126/186] dm btree: add a defensive bounds check to insert_at() Date: Mon, 24 Jan 2022 19:43:21 +0100 Message-Id: <20220124183941.163191458@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183937.101330125@linuxfoundation.org> References: <20220124183937.101330125@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: Joe Thornber [ Upstream commit 85bca3c05b6cca31625437eedf2060e846c4bbad ] Corrupt metadata could trigger an out of bounds write. Signed-off-by: Joe Thornber Signed-off-by: Mike Snitzer Signed-off-by: Sasha Levin --- drivers/md/persistent-data/dm-btree.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/md/persistent-data/dm-btree.c b/drivers/md/persistent-data/dm-btree.c index 8aae0624a2971..6383afb88f319 100644 --- a/drivers/md/persistent-data/dm-btree.c +++ b/drivers/md/persistent-data/dm-btree.c @@ -83,14 +83,16 @@ void inc_children(struct dm_transaction_manager *tm, struct btree_node *n, } static int insert_at(size_t value_size, struct btree_node *node, unsigned index, - uint64_t key, void *value) - __dm_written_to_disk(value) + uint64_t key, void *value) + __dm_written_to_disk(value) { uint32_t nr_entries = le32_to_cpu(node->header.nr_entries); + uint32_t max_entries = le32_to_cpu(node->header.max_entries); __le64 key_le = cpu_to_le64(key); if (index > nr_entries || - index >= le32_to_cpu(node->header.max_entries)) { + index >= max_entries || + nr_entries >= max_entries) { DMERR("too many entries in btree node for insert"); __dm_unbless_for_disk(value); return -ENOMEM; -- 2.34.1