Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp30584733rwd; Thu, 6 Jul 2023 07:58:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlGJjut/zorUjeGLWQHJHtn5IRQFoPnh8Gl1PhV9kKC9cK1kzYFEPoKdGRIGUNM6aSXvEE2k X-Received: by 2002:a05:6a20:3951:b0:12f:acc9:286 with SMTP id r17-20020a056a20395100b0012facc90286mr3903312pzg.17.1688655537808; Thu, 06 Jul 2023 07:58:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688655537; cv=none; d=google.com; s=arc-20160816; b=fKvLYmUhf9tomuKNMXYZex41Ld1vX37EpISJZuYKhOrWNM0W/f/IW8CAuK32I3Jycx IuYtJjyJD/TNvRSDCeF8e5dOhcNS3xTanfDm26AZt6pYOl3q61pRT86Gf88O43j9elT5 ppiqtyBrAzq/ZmDY2ATCEYz4qOixIRDMxOjLHDihmdk4UMsrVwthNc5eHlXB7fUFqQIh y/zMg4hgXj2O8N0T59Qj3NmMK70bzpgfW/cfxgcfMs6V8N+TXS2SFNHNVT69Zd9V8na9 niejOX9AcmNDhU0IC4/je425uMP/n4MrWiIFWGCnRdvrslJViYIgbqf6PsLes28eI+e1 SZSw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=ejIi+uwVT2dUXIKE5URWLbXVMvpFqzn1dbEW+wUewCc=; fh=szE0ZYb7SgZU8wJoR0MXvkYbtWA7rzZls9jr6pQYSdU=; b=maO0IPDSxMY5qibXxQaO0c9RuDzAY9G1ESUbD+5i+ZSxrteKfcP+g0Q7LGWr30XfLZ HIpdAsc+A5wXGNXff9NiaX2G/47OOwFK94fTFQBPWHuWZBZH44DLrKU1Iz0d07K7i3vC Cu36MXh7MzIwesbJb2vc6OQTKWZwoc7TEsMi5FjTSytWxsxgrGj64mn5hE3wbyrdkwhc wkr91qXYSbMSqws6Kv0CfvTvkMMVBbosXEJE8uDd3LoujuDkICo1/sVid/2zFimn5bKS oAm+MgUu3tplWYz2umTp0Z1STggIdTvvYy+DO+4x8ZCw75uS3uxZNfFK1kLdnU/RuACk 4iYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bVdRnuRc; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g15-20020a056a000b8f00b0065ee6c40f91si1699030pfj.159.2023.07.06.07.58.39; Thu, 06 Jul 2023 07:58:57 -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=@kernel.org header.s=k20201202 header.b=bVdRnuRc; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233121AbjGFOWs (ORCPT + 99 others); Thu, 6 Jul 2023 10:22:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233108AbjGFOWq (ORCPT ); Thu, 6 Jul 2023 10:22:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E72751BEF; Thu, 6 Jul 2023 07:22:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3A7BE61947; Thu, 6 Jul 2023 14:22:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DABA8C433C7; Thu, 6 Jul 2023 14:22:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688653361; bh=yDBvfndKjEgluCr2OUU13EcTyPrXy62c+4pPDGslyiY=; h=From:To:Cc:Subject:Date:From; b=bVdRnuRcCDjTajpAmfb2BDudaol6XjWyAkkYusojS0frgOPH84s2OiotXP4VEMHtU f00LjcxBzHOEyuV8GbiXKPQOmuWhQUI9nxHCq2NED/ZiWuhUWS0B5B2yjno/GDzhG2 WIhJ9ZNtEY8HWKwmmSm+PG6c6uVYH6dyhGb5KEES2rmTckIvHfmKOti13bo1TNvnCY YVMOI9SW5anRK411UTtH9/OtepjdrYbd0z/+VndSD4cpmVQ627FM/tp1MCt7qm1Z+M JiSlsgpyICuoWWee8mNKya19IlCXrGZIq7jtuXfqsfcMINVUbea/wWboybEZG1SKp2 giredYerJAi6A== From: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= To: Andrii Nakryiko , Mykola Lysenko , bpf@vger.kernel.org, netdev@vger.kernel.org Cc: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Alexei Starovoitov , Daniel Borkmann , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next] selftests/bpf: Bump and validate MAX_SYMS Date: Thu, 6 Jul 2023 16:22:28 +0200 Message-Id: <20230706142228.1128452-1-bjorn@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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: Björn Töpel BPF tests that load /proc/kallsyms, e.g. bpf_cookie, will perform a buffer overrun if the number of syms on the system is larger than MAX_SYMS. Bump the MAX_SYMS to 400000, and add a runtime check that bails out if the maximum is reached. Signed-off-by: Björn Töpel --- tools/testing/selftests/bpf/trace_helpers.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c index 9b070cdf44ac..f83d9f65c65b 100644 --- a/tools/testing/selftests/bpf/trace_helpers.c +++ b/tools/testing/selftests/bpf/trace_helpers.c @@ -18,7 +18,7 @@ #define TRACEFS_PIPE "/sys/kernel/tracing/trace_pipe" #define DEBUGFS_PIPE "/sys/kernel/debug/tracing/trace_pipe" -#define MAX_SYMS 300000 +#define MAX_SYMS 400000 static struct ksym syms[MAX_SYMS]; static int sym_cnt; @@ -46,6 +46,9 @@ int load_kallsyms_refresh(void) break; if (!addr) continue; + if (i >= MAX_SYMS) + return -EFBIG; + syms[i].addr = (long) addr; syms[i].name = strdup(func); i++; base-commit: fd283ab196a867f8f65f36913e0fadd031fcb823 -- 2.39.2