Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3579841pxb; Mon, 24 Jan 2022 12:42:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJzrwuyMNi0C6Nlj7pIXb8k2eH8Q+6qvX2NoAQt2ZdvY7D6nyW90A0lLFwLZ6ZyIPSTLRNoJ X-Received: by 2002:a17:902:bb87:b0:148:a2f7:9d8e with SMTP id m7-20020a170902bb8700b00148a2f79d8emr15579039pls.173.1643056873601; Mon, 24 Jan 2022 12:41:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643056873; cv=none; d=google.com; s=arc-20160816; b=E66kL4i4rgcHho84xSaFaXj+aurTGXO97Ol2HEqrgP4mU2VahGcUMlQiuLlQCLzjT2 O3c190jfi/Ek5g0mfzRYP4OvlPoejk72MpBhCmHwmU0Z4MW1+lOw0CM346Q9QuVDy7hV KakOlxr955K9aP3n44kS+rJc7D6c8UzLloBAXKxDKTI0xkjwrCjaTZlf1ZOqsAsIimaV P3PNXiMqhdKMcQADiLHRP0s78J/re5IC0NvqIdMTD/5hN7pLMtzi36V84hqtnN/mlXyf pyytr/c9v39WhQ5TgsOA1dpsaIlAhkdyimEOJnM3yKf9pL+/dryuCYkuHiF946vQNsAw MDPw== 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=Zhc1J1WrLHvjuGHXD4pVnBIkVt/tvXgcdXv0f1m+ystXqsuVUzWqtK0z/oPZMXcigl cR4U14m9HddyEkq4CyxIbyQ3Pb4LCFQDe9n2gkfjZ3yZNAMBstqygVeaftxVB6bdBbwX KIPQO6gWTi/BpjYMdXophBEQKhL7dvXSDZUfc7HXd0bLxlhiBx9LQo+VikcMrepIcp9Q jq0zOQHTDOSMHHkA3HdhYLZBRZvrg6FfDzrDlTYZpVevDa5sNA7LByBnKkPTk5Gzz03S bnrl71rrjr/2mxY5Grh7ImG4c3dvg8TJZyMYfStdPUW7f2rpsQb/BG/ty/bwuXZInGqH Cwuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VlIFFoP6; 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 k68si12433053pgk.113.2022.01.24.12.41.00; Mon, 24 Jan 2022 12:41:13 -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=VlIFFoP6; 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 S1358525AbiAXTzX (ORCPT + 99 others); Mon, 24 Jan 2022 14:55:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354104AbiAXTlC (ORCPT ); Mon, 24 Jan 2022 14:41:02 -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 C4B50C061744; Mon, 24 Jan 2022 11:20:48 -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 80064B811F9; Mon, 24 Jan 2022 19:20:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADFE2C340E5; Mon, 24 Jan 2022 19:20:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052046; bh=Up/mfvhONYj+Dx9dzEmZmji4FSEdxlZp4ge0yxhkITo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VlIFFoP6TC+0d/VNDowc/Gitn5lT6Ggb08ub/tzCLHoeCBQ3Nx2sJKArtjZuFp0jI 9xMTtbEJCnWmuejV8m3RMWnLxFz/g8WF/uLeBWeQutXHcrgYqccL8uzAKv/UqTvtPL bq9SepZYsarGKfr+AYV3M2Lo49mODTw4MMnsY1Bs= 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.19 170/239] dm btree: add a defensive bounds check to insert_at() Date: Mon, 24 Jan 2022 19:43:28 +0100 Message-Id: <20220124183948.506574080@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183943.102762895@linuxfoundation.org> References: <20220124183943.102762895@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