Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp125648iof; Sun, 5 Jun 2022 23:07:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTCcRmXmMlYpYZdZ8TyFpI0YWaIWHG+DAJYwSq3JEr3AnIik7sdVea41YgFDjCaY4Rj+OT X-Received: by 2002:a17:902:f650:b0:15f:3a10:a020 with SMTP id m16-20020a170902f65000b0015f3a10a020mr22464157plg.61.1654495668823; Sun, 05 Jun 2022 23:07:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654495668; cv=none; d=google.com; s=arc-20160816; b=OSb21ShCAJos5aG//thKoSTH81zZ24os/DwZCEyNwE74Wzd94afBkizBs3pzMk3c3g wp2Lr4mWEFc7BUThE1SCgf89tUhSFVbP6O5rdM30pb3CXj9dUJvYivkRoeS6kV4M3q/E 03CcCMZYGPE2/ixrtQjgtIlox+Nxz1MBkCskmzM13KWJkJe+1qoSdYW+OduvpBs1jwX3 qDu4trNGo6imyoa5XTSpY2IkonLQ2y017n6J7VCSdkWQnDHIbdHnxc5HZmigXh8kuJVp Av8LYk8UFRrtOB33gcJe0lai72YhD4/t0U1b3EvvXiZeU1w02A+nyN0zsXSWSSpfSpcc 0y+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=6dvXfxAa74Sf/4dMFppaOogGL1hj1QbzvU0U5SauO0Q=; b=VrntMWHFYqVgg/gNd4O6pYb10DBYRccj3d+AikNNneqZU5+DdvGPyJgH4zm1c4nNyK 5JLuvN8btdiDMmNeaFa5KgANCMG0vQEmuT+a9qFRqE9HO4CAgknlpqOqItn8XdOWHPWK MctsxBADd0R4MFGHcV4OTBakUHaXErhklEwZY87XrWvAgPLEUKD8f3Q+C6cnQyirQ75B HCD4mLRalNeARoxumqPwE6EJwPI4FJlsd/JrS1m5j32c+WQhaQIxje2GcA8UoXLd81Ix zIOUnISlDDU7DGbaaCvdA81Ai541hjnxCMIlGdSwDtthzmTP7GNslT5VrQlkUj/io+rn GMlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J2YG4QfC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l17-20020a170902e2d100b00162359521b5si17375768plc.514.2022.06.05.23.07.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 23:07:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J2YG4QfC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DFAFE31258B; Sun, 5 Jun 2022 21:57:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347016AbiFCSTw (ORCPT + 99 others); Fri, 3 Jun 2022 14:19:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348027AbiFCSGe (ORCPT ); Fri, 3 Jun 2022 14:06:34 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E1C15DBF0; Fri, 3 Jun 2022 10:59:41 -0700 (PDT) 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 sin.source.kernel.org (Postfix) with ESMTPS id 68B31CE2491; Fri, 3 Jun 2022 17:58:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E235C385A9; Fri, 3 Jun 2022 17:58:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654279136; bh=OjwbpKNPDfe7GTw3ryhR0CVtFhv3cYyjK+edEN1nmDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J2YG4QfCZYhO072rxNEHT0l77w/IqsfcywRY/TqfTwBFWNAIzjnaX4b1aL/bakUX7 Gqwbd3WWlOqR7nDkAugqtAfXLW33Gs5s6LkvO0DS0DLoXBrxu83xsk1F6YKdCBk8g1 b0wbs7uiZxQTJAL6j5IYFc8g50YtLv9gGkqtRFz0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yuntao Wang , Daniel Borkmann Subject: [PATCH 5.18 64/67] bpf: Fix excessive memory allocation in stack_map_alloc() Date: Fri, 3 Jun 2022 19:44:05 +0200 Message-Id: <20220603173822.558677557@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603173820.731531504@linuxfoundation.org> References: <20220603173820.731531504@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yuntao Wang commit b45043192b3e481304062938a6561da2ceea46a6 upstream. The 'n_buckets * (value_size + sizeof(struct stack_map_bucket))' part of the allocated memory for 'smap' is never used after the memlock accounting was removed, thus get rid of it. [ Note, Daniel: Commit b936ca643ade ("bpf: rework memlock-based memory accounting for maps") moved `cost += n_buckets * (value_size + sizeof(struct stack_map_bucket))` up and therefore before the bpf_map_area_alloc() allocation, sigh. In a later step commit c85d69135a91 ("bpf: move memory size checks to bpf_map_charge_init()"), and the overflow checks of `cost >= U32_MAX - PAGE_SIZE` moved into bpf_map_charge_init(). And then 370868107bf6 ("bpf: Eliminate rlimit-based memory accounting for stackmap maps") finally removed the bpf_map_charge_init(). Anyway, the original code did the allocation same way as /after/ this fix. ] Fixes: b936ca643ade ("bpf: rework memlock-based memory accounting for maps") Signed-off-by: Yuntao Wang Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20220407130423.798386-1-ytcoode@gmail.com Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/stackmap.c | 1 - 1 file changed, 1 deletion(-) --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -100,7 +100,6 @@ static struct bpf_map *stack_map_alloc(u return ERR_PTR(-E2BIG); cost = n_buckets * sizeof(struct stack_map_bucket *) + sizeof(*smap); - cost += n_buckets * (value_size + sizeof(struct stack_map_bucket)); smap = bpf_map_area_alloc(cost, bpf_map_attr_numa_node(attr)); if (!smap) return ERR_PTR(-ENOMEM);