Message ID | 20230706142228.1128452-1-bjorn@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp2624622vqx; Thu, 6 Jul 2023 08:04:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlHE4cYM1HklgRSmouDmhQth7Ra2SNhiioSiamxnLoU9Xq8KB+bsFTs3dtMP6+XVmZ4qB/i9 X-Received: by 2002:a17:902:d2c1:b0:1b8:6245:1235 with SMTP id n1-20020a170902d2c100b001b862451235mr8475937plc.13.1688655870446; Thu, 06 Jul 2023 08:04:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688655870; cv=none; d=google.com; s=arc-20160816; b=cunv8qj/RSnLQltSCZowK1aoOJXW9io2wb8n9bRqp+Mzd5RbmY7fMMZLQrmOS+t3/W 6D7bPh1/2S+xmOYQseitBB/nz38LBif9WF0oMJZ7R1a8P1rvZU13y2TLCYUMrbn0pr0p LPsiHmKRboVLwSBEP5beslsCq1bE1qCTCFAx0AiXHLRXm++4BYjpCIrx783JpgR+xtOD MQqlV4+pzHcKFtTAmcmN06klypRWEpK9R1PM30GzW2kScOzxFTMJMaM9J0gfPSmailyv o02hYGn1U8TNQhtQ786CfG3U8VeSWLR1sVhHsWY3KbBTgfatrlQH9mifvleZCKue9W25 ziqw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p5-20020a634f45000000b0054ff42d3833si1689433pgl.336.2023.07.06.08.04.12; Thu, 06 Jul 2023 08:04:30 -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 S233122AbjGFOWs (ORCPT <rfc822;hadasmailinglist@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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?b?QmrDtnJuIFTDtnBlbA==?= <bjorn@kernel.org> To: Andrii Nakryiko <andrii@kernel.org>, Mykola Lysenko <mykolal@fb.com>, bpf@vger.kernel.org, netdev@vger.kernel.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= <bjorn@rivosinc.com>, Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770684017959754475?= X-GMAIL-MSGID: =?utf-8?q?1770684017959754475?= |
Series |
[bpf-next] selftests/bpf: Bump and validate MAX_SYMS
|
|
Commit Message
Björn Töpel
July 6, 2023, 2:22 p.m. UTC
From: Björn Töpel <bjorn@rivosinc.com> 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 <bjorn@rivosinc.com> --- tools/testing/selftests/bpf/trace_helpers.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) base-commit: fd283ab196a867f8f65f36913e0fadd031fcb823
Comments
On 07/06, Björn Töpel wrote: > From: Björn Töpel <bjorn@rivosinc.com> > > 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 <bjorn@rivosinc.com> Acked-by: Stanislav Fomichev <sdf@google.com> OTOH, should be easy to convert this to malloc/realloc? That should fix it once and for all and avoid future need to bump the limit? > --- > 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 >
Hello: This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <andrii@kernel.org>: On Thu, 6 Jul 2023 16:22:28 +0200 you wrote: > From: Björn Töpel <bjorn@rivosinc.com> > > 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. > > [...] Here is the summary with links: - [bpf-next] selftests/bpf: Bump and validate MAX_SYMS https://git.kernel.org/bpf/bpf-next/c/e76a014334a6 You are awesome, thank you!
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++;