Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3547965pxb; Mon, 24 Jan 2022 11:58:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJwuWC6D9vhzV7yBlrfzRJddTlUlctNA01hODGqgJ+yvHn1EH7Qu9gq5ZcazEGRw8VWYWlI/ X-Received: by 2002:a05:6a00:9a1:b0:4c9:ff9:47e3 with SMTP id u33-20020a056a0009a100b004c90ff947e3mr6072201pfg.10.1643054282548; Mon, 24 Jan 2022 11:58:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643054282; cv=none; d=google.com; s=arc-20160816; b=jnfinjWTmk0NAgSeDcwuhkAhGePgKnitLl/GzsKbNy+TKgx6QC5dcmCYLKgf8e1J6Q 8aNvFhwIl05n0I56dG5TxDZl13tu0R++OGSylQ5WbnKFyio2clerXlIpVRKhk1keYHe7 vv8glAJJIFTWggb/OOG8JZb5BzgsEzmmPKoCqHxIkBazU57olz8A4l2K+3GsC7Tm4XVO 5AqbCM0APbOIZ3J3baFMB/xcEG2fk/nqwtK+fAJHI9r12SsS6FKtYSAY6rIpVI6KM5Nz K977r76KK14OHmerw1ebyMD/2ZiQre2yFZNtobFPkSYGbixNQyzWuazaxc9mqoBH8u8v dC/A== 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=4vCbM/d8DGIoUBQ3cVF8lwDeTW9+JS3+wl+lujhyU2o=; b=EIBrKafgyiTc9n6X8K+ujJMJIPhSC6cKzbHRW5sxSYZtZBQ3yQqykyjyt0DhtXWKBW c5e620+B2J5wBgZbTNDzxX+rDWhaggGMzr2q60xKCnhOw3m9xJ6bOrqpKueqEIpQpXYi wdbqJmJBNUwYRlJD43XzR33RmdRKYREJ6qTEjFytnqQsAw31sQV4nb6No55+ET71W8+u CVlYnsie8BiPUcDF8JjovxNESSlkKf/c7m+kL/1Ehfx6oZDrBaGGwp5M8YKoh5KWnYIk GAEudDWVyQ1nbSFKR6Y9DdErczcmaJUSFr6Nv8V1kndhCOg5Y6A+PzyX1KW+QMeAUOnO xiqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yt6IKtSj; 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 203si3666164pgc.449.2022.01.24.11.57.50; Mon, 24 Jan 2022 11:58:02 -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=yt6IKtSj; 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 S1344127AbiAXSxm (ORCPT + 99 others); Mon, 24 Jan 2022 13:53:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245480AbiAXSwI (ORCPT ); Mon, 24 Jan 2022 13:52:08 -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 ADD4BC061774; Mon, 24 Jan 2022 10:52:02 -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 757A4B81235; Mon, 24 Jan 2022 18:52:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 984A7C340E5; Mon, 24 Jan 2022 18:51:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643050320; bh=m3dT+BwIryTLHf0an/Okp1ItP323n1YSAxKneotYt5o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yt6IKtSjvrHGd9jDqe+YBcI7lBw7iModgcbS/gEZS++pN7ABEYTtBEXEbrUh4Z4F8 +b8VKlGw6Rrxi7AMIgXIuKy7dlp8Yysey4eAiHH2cS1jvO6tMdqpMlFpFYYcR7ygjV 2efcSFq5NLTDGhyUPZeqyW9CqYz4ZyeP5cy7PbO8= 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.4 079/114] dm btree: add a defensive bounds check to insert_at() Date: Mon, 24 Jan 2022 19:42:54 +0100 Message-Id: <20220124183929.535984756@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183927.095545464@linuxfoundation.org> References: <20220124183927.095545464@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 fa9039a53ae5c..23b1d22f693c1 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