Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2941851iog; Mon, 20 Jun 2022 07:58:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tnXg6DLkxWEAOdmRD+LmUNPDkUjYO73z/vvVKULDSgmjlP88TjayOckVlAm3UNHYrcCz1d X-Received: by 2002:a17:902:e5ca:b0:167:4e08:a63a with SMTP id u10-20020a170902e5ca00b001674e08a63amr24680671plf.69.1655737103462; Mon, 20 Jun 2022 07:58:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655737103; cv=none; d=google.com; s=arc-20160816; b=Ugjkvk/2osuadG7LS6qJGguUAJzX8oz0YRUawpfj+SgJddmrCLxOpAbman/PiR2oq3 vcFR0cw42mQWUxOmYN5jBNUSlE7VS2WwtsByQB+j0fAuNsnSkwzDuFUioloUzhstZpiT Ko9ZPHwmf5p53BaBXEZx+iPtZZ5Qn5hifwwIUQEpxnTrS/nCqUkx7wdo5sG4j0L5HS8u 6vzpfR1VHBN8RpZuM9hEwZNs9UfL9O2ZUNAqHoNNBNcqOKopa9pMNZyLRC2ZIwDxTYKA NqmXRZPYpwToD+5VbLb+KZ3iOfaLpa/T1X/4KQDq0r5W3xDcCbvEfoxKLTyN+GEknJ7p oZLQ== 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=ha38ONjWKBb5l/s6gqv8mhdg895QE/n+RrcmauAhFtU=; b=a01Yfyaw/BXAwz2HwVgUVAVLikA7PCNP5Kdi2fxXgl38mh+hkWeJ/4+8Dr4W9n7+qV tkFCuqrF/wiTvEBTB1CwXQLaXT8rc8TM5pwibDTPnqrBAvGzk1KdNKsSPc9iBUxlSKyR bWAVzmC6D3PqgLNcQaKVtjPLKqS7lxCorKjmYqQUd4LGWwFr7I6d7a2k93tTlJclGvLe vNsFl/UbeFTxnCGcEPGEh9U7MlL4jRhW48claFwG6EPga8KhxLhhbln//zJueJcD5Ych BNXEFHHBAPIMvmLmYiB1gSZpmPQ1B/9MusaG9xIQjq5NpJmwVFH+nRbuUMeIS85yzm04 xdXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A07hZQ+C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d20-20020a63d714000000b00401b314515fsi12695508pgg.258.2022.06.20.07.58.11; Mon, 20 Jun 2022 07:58:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A07hZQ+C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1350817AbiFTOMo (ORCPT + 99 others); Mon, 20 Jun 2022 10:12:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347118AbiFTOC3 (ORCPT ); Mon, 20 Jun 2022 10:02:29 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEEA13CA60; Mon, 20 Jun 2022 06:26:57 -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 ams.source.kernel.org (Postfix) with ESMTPS id B19BEB811C3; Mon, 20 Jun 2022 13:11:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 031FEC385A5; Mon, 20 Jun 2022 13:11:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655730670; bh=olGKnJi4hX2P6Qx9ZW0XwLZQztWNba/bvqtQILWDJq0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A07hZQ+CPmtfRMExGd2Y7yQKuGkRaHktx4UUc8H0DDpOBR5sE7Rr6nsjQCXqk0NVb oZbK5m3Kx/90x1LiJ4mG39MTDbXLpgkFEIxTisksnHKKWukWRxhXNGHnxbW22ilqL3 +WkvIDHK/mAh1i23GwecqpYvhjKW6GSy/AHDdfzU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yuntao Wang Subject: [PATCH 5.4 002/240] bpf: Fix incorrect memory charge cost calculation in stack_map_alloc() Date: Mon, 20 Jun 2022 14:48:23 +0200 Message-Id: <20220620124737.873774107@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220620124737.799371052@linuxfoundation.org> References: <20220620124737.799371052@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=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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. This is a backport of the original upstream patch for 5.4/5.10. The original upstream patch has been applied to 5.4/5.10 branches, which simply removed the line: cost += n_buckets * (value_size + sizeof(struct stack_map_bucket)); This is correct for upstream branch but incorrect for 5.4/5.10 branches, as the 5.4/5.10 branches do not have the commit 370868107bf6 ("bpf: Eliminate rlimit-based memory accounting for stackmap maps"), so the bpf_map_charge_init() function has not been removed. Currently the bpf_map_charge_init() function in 5.4/5.10 branches takes a wrong memory charge cost, the attr->max_entries * (sizeof(struct stack_map_bucket) + (u64)value_size)) part is missing, let's fix it. Cc: # 5.4.y Cc: # 5.10.y Signed-off-by: Yuntao Wang Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/stackmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -117,7 +117,8 @@ static struct bpf_map *stack_map_alloc(u return ERR_PTR(-E2BIG); cost = n_buckets * sizeof(struct stack_map_bucket *) + sizeof(*smap); - err = bpf_map_charge_init(&mem, cost); + err = bpf_map_charge_init(&mem, cost + attr->max_entries * + (sizeof(struct stack_map_bucket) + (u64)value_size)); if (err) return ERR_PTR(err);