Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2814540rwl; Sun, 9 Apr 2023 01:45:44 -0700 (PDT) X-Google-Smtp-Source: AKy350ajOhAVen73IffMfPueGufBapFfR7DqRCZ2KRatZoao1C9WRJDx8fa7btJvQeSVHDgEelHQ X-Received: by 2002:aa7:ca41:0:b0:502:67b6:9734 with SMTP id j1-20020aa7ca41000000b0050267b69734mr7134488edt.6.1681029944438; Sun, 09 Apr 2023 01:45:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681029944; cv=none; d=google.com; s=arc-20160816; b=S3j5bY7NmV303YGmW6iQJX28fZC5KkKe+KnN/JwgRkKIIyOQbuoqTxK9WCMcBVlLUP 9qK7LD8MtB72MkmgvlSKSHd6oa/0FrUBlg0I6HL8RmOtVexTjmJ7H1Qm+2EgRHd1kvBY X53QqJ/SgDs7PLM/KcgB08UXdEIOrxAoxaYBlqpvumsw5JXxHN+l2lTUdxK8H50QFL7d 8R8zr5F96d2IhvK66a1y4l/xYeEHpTbHhOiqKSulf6s6tjDsYCV1eXYlL1LqAU9eDJVA RB0Ox7v84QtWaNEMv2/cfc9FsMZYlx5UXxSghejz368juDD5j1cvbkKTcUZI/jL8SljA yO9Q== 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:date :subject:cc:to:from:message-id:dkim-signature; bh=1BlGx1afgSOPlmGiINyQ3UClfYQu3kEy3LXJFKQ8+FY=; b=OWEPEh5f8eO3l8dg6g6rZjvYvNQ7aXHCb2nlIF9XIv3DxIe0lGvJipSpyWKUBG4R5/ ejjois/XN/yx2cQDy0Z1qGYPoBx9i1/fhPRBpMys28MZC1ZO1wDzHChk+fl3XdplaQ/q HViGiElcmvAAuUzf0z9RsTUvDXGvG9h0GXQIiPHQruyVnWc8aDm7hNxvuDLlT9i7V8/8 EQ76zfIMNVH64NaEbIe3zvFZSm6HH0Qn9Hg9xm/irGe3V6qYRy2/ZSeghUKOATGiYEeN Au2/dKfcW5Go2vTXwlpKSrtD4HOlbM3UP4VrmDdjvM3lPxJRSVFSRnOIqNaIqNgdG790 hfUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=vj+wv2OO; 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=foxmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r16-20020aa7c150000000b005049b97a576si951713edp.526.2023.04.09.01.45.09; Sun, 09 Apr 2023 01:45:44 -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=@foxmail.com header.s=s201512 header.b=vj+wv2OO; 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=foxmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229469AbjDIIPk (ORCPT + 99 others); Sun, 9 Apr 2023 04:15:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbjDIIPi (ORCPT ); Sun, 9 Apr 2023 04:15:38 -0400 X-Greylist: delayed 5819 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 09 Apr 2023 01:15:34 PDT Received: from out203-205-251-72.mail.qq.com (out203-205-251-72.mail.qq.com [203.205.251.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C44F59E8 for ; Sun, 9 Apr 2023 01:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1681028131; bh=1BlGx1afgSOPlmGiINyQ3UClfYQu3kEy3LXJFKQ8+FY=; h=From:To:Cc:Subject:Date; b=vj+wv2OOTHRB2r6v3wAsU59CxRx6YlWLk7RhabfXcziok9iht3Ti8bFHE+7cbAauY 1G8T7Wa290WaEhFyFoP/tH8jK42JfQzDo0ONUA3M56gLyaMqKVIgEVtDcvYBrEFrNv lnoZPhVi4ygpwLekuUp4hFLJ4yFrLYXnjwIufho0= Received: from rtoax.. ([111.199.190.121]) by newxmesmtplogicsvrszb9-0.qq.com (NewEsmtp) with SMTP id 3DB170ED; Sun, 09 Apr 2023 16:15:27 +0800 X-QQ-mid: xmsmtpt1681028127ta0a5h3cn Message-ID: X-QQ-XMAILINFO: Mi0NhBPPe/4R2b23CkWNOcjl6/zGeo8g7OI8JOhvvNufzVBxQ0jK6neRCgu1m5 aBnJqPQx16B8w2KUDIsUycPw/kqP+Zm8ZL4x6kXtwmon0hzTcQ1RI2oAEc0bJ5KdwFRRu+0dlkEo txb/5ZSo7AWb7j9O3jgNMMUHK22+83SvlRZ0djb05mP2txPDS/YcGvlr/8aLHEaljN25aUtdBM7t ltlZVinkp4vcedUcCPsRfk1aSgYoJtLinSQmLB09/0RKM3ZJYXpuY1XJiXu4DKbtuIYQrqvceal/ D6MCY8Ir3GLHImrbvdZnzNXtUoQQOpyxlmJM91me/zteJVt8uYnhSsEvYlB8snxXWEZyX1Ijcwbi B2EQPW+GWob2hme/A5+2HYyHVXVCrXaFD4thxhY+k/eSUXER5TlLgdKRgaye0ZIoTylhQGho9HRw cftPcqzFQRpiM3OBt7trUa5sEnfo5Z/ufymc+uzcyrQgERSY3VOH4E6dSA5cJAMcsQX4M9nUN7Dg XOYp6x3evulsK3uhcc1r1zBRyFi/TJjCVENFY6wU3ZCpBWJ3rmCn6erq2IK64FVrrrf7vldwv/r2 P68uCwlEQGLc/so809fCD3GSh37P0kWIus5dPAIdDMBkVf3UazfwwdotVd2YY5iL5vOFtBxUTfj5 q4DPpluLl5acQ67ZcG/TahwibDVyiQAKKLb64GDt6iu/JpcBwcmCi7oh5yFOlqlEr8lzz0+ovyhH EpHWM7hkewFeoZAeHCc19Vhi47Vm8chNOd43rIz8WBMktSjVG2X62i1Aek8BLnKRtXkUNG1CaANH vydtQ5HnxMdHeMFcmD/Q0Cfeuz2FEthh7sB4naa5n3j5TgpKVY5pjuGl2hBQLl1pAGhW38FhAXx5 vRc5voteBdRR/ZHv3cY7cKi5RQThSTojAOQRFcNJEedX5pwSOK9S/kvWaeMv19hhuElGhyth8+ld yZAG19VhsFpNqeYNwc+LzKwzW3szYEmCm8goERRJ2C6UI++iXBQA== From: Rong Tao To: ast@kernel.org Cc: rongtao@cestc.cn, Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , Nick Terrell , bpf@vger.kernel.org (open list:BPF [GENERAL] (Safe Dynamic Programs and Tools)), linux-kselftest@vger.kernel.org (open list:KERNEL SELFTEST FRAMEWORK), linux-kernel@vger.kernel.org (open list) Subject: [PATCH bpf-next] selftests/bpf: trace_helpers.c: Fix segfault Date: Sun, 9 Apr 2023 16:15:25 +0800 X-OQ-MSGID: <20230409081525.182264-1-rtoax@foxmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HELO_DYNAMIC_IPADDR, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,RDNS_DYNAMIC,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: *** 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: Rong Tao When the number of symbols is greater than MAX_SYMS (300000), the access array struct ksym syms[MAX_SYMS] goes out of bounds, which will result in a segfault. Resolve this issue by judging the maximum number and exiting the loop, and increasing the default size appropriately. (6.2.9 = 329839 below) $ cat /proc/kallsyms | wc -l 329839 GDB debugging: $ cd linux/samples/bpf $ sudo gdb ./sampleip ... (gdb) r ... Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7e2debf in malloc () from /lib64/libc.so.6 Missing separate debuginfos, use: dnf debuginfo-install elfutils-libelf-0.189-1.fc37.x86_64 glibc-2.36-9.fc37.x86_64 libzstd-1.5.4-1.fc37.x86_64 zlib-1.2.12-5.fc37.x86_64 (gdb) bt #0 0x00007ffff7e2debf in malloc () from /lib64/libc.so.6 #1 0x00007ffff7e33f8e in strdup () from /lib64/libc.so.6 #2 0x0000000000403fb0 in load_kallsyms_refresh() from trace_helpers.c #3 0x00000000004038b2 in main () Signed-off-by: Rong Tao --- tools/testing/selftests/bpf/trace_helpers.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c index 09a16a77bae4..a9d589c560d2 100644 --- a/tools/testing/selftests/bpf/trace_helpers.c +++ b/tools/testing/selftests/bpf/trace_helpers.c @@ -14,7 +14,7 @@ #define DEBUGFS "/sys/kernel/debug/tracing/" -#define MAX_SYMS 300000 +#define MAX_SYMS 400000 static struct ksym syms[MAX_SYMS]; static int sym_cnt; @@ -44,7 +44,8 @@ int load_kallsyms_refresh(void) continue; syms[i].addr = (long) addr; syms[i].name = strdup(func); - i++; + if (++i >= MAX_SYMS) + break; } fclose(f); sym_cnt = i; -- 2.39.2