Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3558049pxb; Mon, 24 Jan 2022 12:10:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxB81rf0YqCEXyNJyt/NYtdM2Oj2oWYio+qrRVfJz0GTmoo8ttyHOQCmEgsyMXWy1OBatkr X-Received: by 2002:a17:90a:cf8e:: with SMTP id i14mr3464833pju.237.1643055052405; Mon, 24 Jan 2022 12:10:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643055052; cv=none; d=google.com; s=arc-20160816; b=Edb/U8PDgEz2iurP3WuI+0jt+JyhZDkAFUSO7G3q6EP6mSqRqiX1+YA9qn/WunMB2m 4bNQjXHYwr0URSGLcYYRH0c+OQWHNCiQ5Q9zm85oXFZlrWoYAj8zGRG6ojeGy5pGtJX2 MOOKRWZLgU0Vio3T+E6vHeLsBGvXcIM1HZwvhruiipF5iIA+ou8dzCkNDQyuWE9AC6CO XBAQrpIudLqwCIR6Ti2Qxoro+Av5sBOtpBXbv4ZHoWhmxFTotcoOsdIXxz7KYj2wYOHR XRyTDDSkmgHUsdqYPWpuAo9lYjQ3LojnwhnEzxf/kO3zmZbajxcODAM81MHSO3elWWHl z+9Q== 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=ALeuOM/ObG/5L+SGBymqLdQ5r8CQrXtp3TK6rXTH0+k=; b=zE7qTWXn4CQyA9XqR6NIXPeTdn4GP3y/i7cWvplclOIaBRPP8jte76DzSoRXygQ9j8 v8grhbqpwrYRMV0DFS9uBH6AK5ozvcyravxJ/AlaZJk5vjZvzDmjV6aDCMzEb40kRcdV +y3JKyYBmbzxNinfx7zeSue/7T5RZjGe7LvVZiwopMrszUcc7uamZRHp6Fjr/LwpTTZW 0mOkQBGgWFGq+jaJVq8y+CGx5D4iM8HP3ovZO1Q7e0tcPKzP1qvMIfwDIpB8XST5RnDf mRGoEzcNM6TW1odeLdjgzvO6xYAE2Ty+PLxfpLCeI1R6NVIdOYYx5omItTufl07JSnvR pl6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yvSJW3QM; 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 f9si16563800pfc.87.2022.01.24.12.10.39; Mon, 24 Jan 2022 12:10:52 -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=yvSJW3QM; 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 S1345420AbiAXTMT (ORCPT + 99 others); Mon, 24 Jan 2022 14:12:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345282AbiAXTDN (ORCPT ); Mon, 24 Jan 2022 14:03:13 -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 E5CDAC06175A; Mon, 24 Jan 2022 10:59:11 -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 A347FB81238; Mon, 24 Jan 2022 18:59:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6E6AC340E7; Mon, 24 Jan 2022 18:59:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643050749; bh=1irUI/gODjLwvM/jMUYlUbBn28oVk1kyE3HGzfg2p/A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yvSJW3QMjDmDV4q5GrvTO/b2SDCrmhrhqbNSt6u/xwRS1P8/HUzbZJdYpBIz/MLgK vyjJ7aiPDCtMnf44wpI6ldMj+AWCi7bmkkd7hDwgyXh3NW+/qBQm1LU1k0lrYt1Bfo nuG38J4mtFLirzjcrnH25nejZ0xETAnqzU7BFnz0= 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.9 100/157] dm btree: add a defensive bounds check to insert_at() Date: Mon, 24 Jan 2022 19:43:10 +0100 Message-Id: <20220124183935.937971550@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183932.787526760@linuxfoundation.org> References: <20220124183932.787526760@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 386215245dfe2..85273da5da206 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