Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2442050iof; Wed, 8 Jun 2022 05:10:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhWnm06gUCWVxyb0f/Fo3FSVdQj/pxdRqoCgcCmmLg5yHqBI+qHVhHkz8UXaG9TDkMUUFk X-Received: by 2002:a17:903:284:b0:168:4d1a:3ccc with SMTP id j4-20020a170903028400b001684d1a3cccmr5880788plr.78.1654690259222; Wed, 08 Jun 2022 05:10:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654690259; cv=none; d=google.com; s=arc-20160816; b=tKSO+F+7wwQqemaMxHhP7OgruTezeptkZL/n7UR0fm4lg0GCykt+dM0DKNqQ1U+8Nk aeg48cwuNchOkxCGgbUu0VedmMg9udPvKq6J3qxZ39UR2a1ORr4+qhf53Pe7ffhVlm4Z 9p00qjGj/WpOEYVSmMTglGj9hjyp7bdTMMZJ5CtCpi6kxVyyHbWwu65POnuWOtitL/n7 ejcSNQUmczK0fw+mGnk4FkbCenvAe1S2bhSB0YtTO78EqopNArnK9c8bmY9syJ3HS88u h/XdK4RKnq98g9FeIz9s4+mBq9o0F6nTjhwomWcM5lMwfM94McKxZMWOiAdyEwtu7D2e 3QHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=ISjpchBA+InWcFtEvOsf/1Hq9tdPTtMv6qgSC8YUAT0=; b=B4u5mkJ7BBOAcnEg0sCls0o1hFI+kCbmRpJOWCFjZyBQNs7ZnqDmUZbX7uHAq3REQV uQhbKjC8PcW9UzaoMtFR9tGCrn43JzQVxHSLbzA3w0j31IRRr6vAZGfnyUNtSoJsQlsQ 0eYtdBn58vrnwwYq5AidAmaMj0Np8n5iYStm5cm5M+TX7f+Zia5/FNyq2wJBDptoMcVH Z0PhZGeIKJ/j5cXYTg3jCLgct+amu4aYZnQzyC7qaIVBqWuXIdgx7fWOoqumst5oVaAH PsINYPwqY01LAbtE3cTEHk0bg03ROLrOJyWC7gCuyWqs+C2gQaU/qj0HPYHV0Vnc6C4f ZSjw== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d6-20020a636806000000b003fbc60e335asi28879804pgc.736.2022.06.08.05.10.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 05:10:59 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 051B21E300F; Wed, 8 Jun 2022 04:41:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238288AbiFHLkx (ORCPT + 99 others); Wed, 8 Jun 2022 07:40:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238277AbiFHLkw (ORCPT ); Wed, 8 Jun 2022 07:40:52 -0400 Received: from jabberwock.ucw.cz (jabberwock.ucw.cz [46.255.230.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E9401DFC6F; Wed, 8 Jun 2022 04:40:51 -0700 (PDT) Received: by jabberwock.ucw.cz (Postfix, from userid 1017) id 091A01C0BB4; Wed, 8 Jun 2022 13:40:50 +0200 (CEST) Date: Wed, 8 Jun 2022 13:40:49 +0200 From: Pavel Machek To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Yuntao Wang , Daniel Borkmann , Sasha Levin Subject: Re: [PATCH 5.10 136/452] bpf: Fix excessive memory allocation in stack_map_alloc() Message-ID: <20220608114049.GC9333@duo.ucw.cz> References: <20220607164908.521895282@linuxfoundation.org> <20220607164912.613808833@linuxfoundation.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="wxDdMuZNg1r63Hyj" Content-Disposition: inline In-Reply-To: <20220607164912.613808833@linuxfoundation.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 --wxDdMuZNg1r63Hyj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi! > 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. >=20 > [ Note, Daniel: >=20 > Commit b936ca643ade ("bpf: rework memlock-based memory accounting for map= s") > moved `cost +=3D n_buckets * (value_size + sizeof(struct stack_map_bucket= ))` > up and therefore before the bpf_map_area_alloc() allocation, sigh. In a l= ater > step commit c85d69135a91 ("bpf: move memory size checks to bpf_map_charge= _init()"), > and the overflow checks of `cost >=3D 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= =2E ] We don't have 370868107bf6 in 5.10. Can someone verify this is still right think to do for 5.10? Best regards, Pavel =09 > +++ b/kernel/bpf/stackmap.c > @@ -121,7 +121,6 @@ static struct bpf_map *stack_map_alloc(union bpf_attr= *attr) > return ERR_PTR(-E2BIG); > =20 > cost =3D n_buckets * sizeof(struct stack_map_bucket *) + sizeof(*smap); > - cost +=3D n_buckets * (value_size + sizeof(struct stack_map_bucket)); > err =3D bpf_map_charge_init(&mem, cost); > if (err) > return ERR_PTR(err); --=20 DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany --wxDdMuZNg1r63Hyj Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRPfPO7r0eAhk010v0w5/Bqldv68gUCYqCKwQAKCRAw5/Bqldv6 8gOoAKCas9XK10HZN7NVkNBIUOQbTy1WBwCgoAlWLuRiNvh4TR+vRWJWLu6ex8Q= =o2rh -----END PGP SIGNATURE----- --wxDdMuZNg1r63Hyj--