Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1378620rwd; Thu, 8 Jun 2023 17:30:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7v3g6rGQjMk3poZtXC+7oFSYI8jxlfep22qMOUfgt6NmQTp6SKwPmZE1mnlD7kHDpqYXFh X-Received: by 2002:a17:90a:890a:b0:256:3f7e:e485 with SMTP id u10-20020a17090a890a00b002563f7ee485mr8920442pjn.44.1686270627823; Thu, 08 Jun 2023 17:30:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1686270627; cv=pass; d=google.com; s=arc-20160816; b=ASmU1aZShSp8G6DGkF57ZWsNkKUHY5h5ODZiWeVihqhAPsaR5QeenggYLnWyYyHX8w su3cOla1DdD4PrAAhGc6ASbgJxmOqSD8dfK1CiWlvlTciWA9ogLlWOAjkteOIVefthzL 4DyoF4dW7p9VP7QTSNbeRt0XpOHRl7+I+Ta2JNaunpCf5AlZQ+P/4ZWt3xR5BbphLuHl af373GpjVKUG1OcHUTnpO0MLCP4lxu2AhqFeaiyXRspHAMRU783X08ILk5iTLC2LudVg UXbLr5tIiDqRqRyU6psPiA3bDoK+j0rau9SuU6TPtbL+i3U99d4pPkuyIQV0LmK05JgN nebw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=F8KPdDJs/fafqK8befrWeYqM6/tlnupScz2H0Ba6c8I=; b=j+yxud3x8W0gE8rxS/zgnK8nQVSlQmT4l0cA+K0h4azXKyItFtHTqOdl+/2UwR/iIS pHgJ4cWsXRlQuZhxVPWSxWIXHUriolOwEE/Lfi9t/N7ysR8t+ar6ucV+RFaV0hubnkFy EJUXqXuj+8oy9fIceoQmSPiP1WF3J6a06PQbkcncbI7dQJlClwSoEexVgtNhmVjpLeGm nGRArHbqlb+3Q1CVndA28lGKfdDcsrboAeAx5uYWYgf0Gimok4Keet3R3d10KB3WDrvb uUALG9dBinrj2lKybE11CM7fR+bUNeK6f5zBuwRK8DSnATjTzvRPVhrq+ATXnlrcVDdd Wjeg== ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@templeofstupid.com header.s=dreamhost header.b=qVzIX9Ve; arc=pass (i=1); 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a23-20020a17090abe1700b002528f40700dsi3371969pjs.153.2023.06.08.17.30.13; Thu, 08 Jun 2023 17:30:27 -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=fail header.i=@templeofstupid.com header.s=dreamhost header.b=qVzIX9Ve; arc=pass (i=1); 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237619AbjFIALh (ORCPT + 99 others); Thu, 8 Jun 2023 20:11:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229981AbjFIALf (ORCPT ); Thu, 8 Jun 2023 20:11:35 -0400 Received: from grey.apple.relay.mailchannels.net (grey.apple.relay.mailchannels.net [23.83.208.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD7D91706 for ; Thu, 8 Jun 2023 17:11:34 -0700 (PDT) X-Sender-Id: dreamhost|x-authsender|kjlx@templeofstupid.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 1249B141412 for ; Fri, 9 Jun 2023 00:11:34 +0000 (UTC) Received: from pdx1-sub0-mail-a313.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id A1535141EAA for ; Fri, 9 Jun 2023 00:11:33 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1686269493; a=rsa-sha256; cv=none; b=zXRgaR82G2lkyJ2cW88PyKLu7UkP3x4W5Q1+TraOxDhMYkmCnAP9RKolodvBJ0IuVQSD92 Gm6qKLxswUZ0z+9yqfVuUUMf9P2uBKhN7HzpJ8wkqO1IgJtHn7WYIR4ZaPLeUzapVqM9F6 DvFNwiEbbzGWi+HakoCWNOzHpCYtLQWwyoLQTyfOPyjUCvBe5sFw2ffkAUK0GP4wBGOquo XglTcwnR3KYsdVzrsTo/Qi1P4+mbxfEG6HC58wZ+TURwQXNehNbD8j/G5X1P1FB0VJGX8O 2XRl3iO4gCOpc3NJmjtAl05bEe6KT/FTb/oYuVX/DaPK87FxonkW9g0G83Rkjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1686269493; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=F8KPdDJs/fafqK8befrWeYqM6/tlnupScz2H0Ba6c8I=; b=pNBIg1SVrp5ApxMJi3cXhWmLWWa1EQRWfsTW/B6A/bLcACJO91o2KoZD34ZQtGLOnVEyda ozetTw8AJbAySBEBgo2hizecLOplJebFXS5q5ywlF2BEVm99TmwiQC3vLnQFImAr7RAZkx gjwBgNAS0QNbeI8PTHNt4suaks45ag3MUl+uRTmG+tsnrXVUkKskb0FzDN0rX5T3f+PAba KwR1QTtTFPXJtXZZd7dNQ/bnglO+SwutT5nZBE79LaJTmWiZ8zulpzDUXg4iJxcGTPTBeA /PM5z1gs3/Sv25k6ldFXeNAxHUUxFceDxses6pdSC5JqhV3NQG8eq8UMaZ4tUg== ARC-Authentication-Results: i=1; rspamd-6f5cfd578c-f2pt8; auth=pass smtp.auth=dreamhost smtp.mailfrom=kjlx@templeofstupid.com X-Sender-Id: dreamhost|x-authsender|kjlx@templeofstupid.com X-MC-Relay: Good X-MailChannels-SenderId: dreamhost|x-authsender|kjlx@templeofstupid.com X-MailChannels-Auth-Id: dreamhost X-Wipe-Power: 6c3660031629f650_1686269493890_955765820 X-MC-Loop-Signature: 1686269493890:925410726 X-MC-Ingress-Time: 1686269493889 Received: from pdx1-sub0-mail-a313.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.127.59.22 (trex/6.8.1); Fri, 09 Jun 2023 00:11:33 +0000 Received: from kmjvbox (c-73-93-64-36.hsd1.ca.comcast.net [73.93.64.36]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kjlx@templeofstupid.com) by pdx1-sub0-mail-a313.dreamhost.com (Postfix) with ESMTPSA id 4QchMS6BFMz1pQ for ; Thu, 8 Jun 2023 17:11:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=templeofstupid.com; s=dreamhost; t=1686269492; bh=F8KPdDJs/fafqK8befrWeYqM6/tlnupScz2H0Ba6c8I=; h=Date:From:To:Cc:Subject:Content-Type; b=qVzIX9VesNFlL8xB712fCTbGsLi9rI2jI1DX5TdbS6CrxTdRRv9ANQSv2kARsBEph 4a9nkcq5WkqySs7iXyVDSKtZDMg9VNW63YrkPY/JoCjmhjUz0tPlfCHQXe872HSpzN G9Kez1ZTlvoiV4boKKxid0qGi6Naxgp2hfuSZ6AE= Received: from johansen (uid 1000) (envelope-from kjlx@templeofstupid.com) id e0042 by kmjvbox (DragonFly Mail Agent v0.12); Thu, 08 Jun 2023 17:11:31 -0700 Date: Thu, 8 Jun 2023 17:11:31 -0700 From: Krister Johansen To: bpf@vger.kernel.org Cc: Alexei Starovoitov , 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 , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf v3 2/2] selftests/bpf: add a test for subprogram extables Message-ID: <9e3041e182a75f558f1132f915ddf2ee7e859c6e.1686268304.git.kjlx@templeofstupid.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,URIBL_BLOCKED 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 In certain situations a program with subprograms may have a NULL extable entry. This should not happen, and when it does, it turns a single trap into multiple. Add a test case for further debugging and to prevent regressions. N.b: without any other patches this can panic or oops a kernel. Signed-off-by: Krister Johansen --- .../bpf/prog_tests/subprogs_extable.c | 31 +++++++++++++ .../bpf/progs/test_subprogs_extable.c | 46 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/subprogs_extable.c create mode 100644 tools/testing/selftests/bpf/progs/test_subprogs_extable.c diff --git a/tools/testing/selftests/bpf/prog_tests/subprogs_extable.c b/tools/testing/selftests/bpf/prog_tests/subprogs_extable.c new file mode 100644 index 000000000000..2201988274a4 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/subprogs_extable.c @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include "test_subprogs_extable.skel.h" + +void test_subprogs_extable(void) +{ + const int READ_SZ = 456; + struct test_subprogs_extable *skel; + int err; + + skel = test_subprogs_extable__open(); + if (!ASSERT_OK_PTR(skel, "skel_open")) + return; + + err = test_subprogs_extable__load(skel); + if (!ASSERT_OK(err, "skel_load")) + goto cleanup; + + err = test_subprogs_extable__attach(skel); + if (!ASSERT_OK(err, "skel_attach")) + goto cleanup; + + /* trigger tracepoint */ + ASSERT_OK(trigger_module_test_read(READ_SZ), "trigger_read"); + + test_subprogs_extable__detach(skel); + +cleanup: + test_subprogs_extable__destroy(skel); +} diff --git a/tools/testing/selftests/bpf/progs/test_subprogs_extable.c b/tools/testing/selftests/bpf/progs/test_subprogs_extable.c new file mode 100644 index 000000000000..c3ff66bf4cbe --- /dev/null +++ b/tools/testing/selftests/bpf/progs/test_subprogs_extable.c @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include "vmlinux.h" +#include +#include + +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 8); + __type(key, __u32); + __type(value, __u64); +} test_array SEC(".maps"); + +static __u64 test_cb(struct bpf_map *map, __u32 *key, __u64 *val, void *data) +{ + return 1; +} + +SEC("fexit/bpf_testmod_return_ptr") +int BPF_PROG(handle_fexit_ret_subprogs, int arg, struct file *ret) +{ + *(volatile long *)ret; + *(volatile int *)&ret->f_mode; + bpf_for_each_map_elem(&test_array, test_cb, NULL, 0); + return 0; +} + +SEC("fexit/bpf_testmod_return_ptr") +int BPF_PROG(handle_fexit_ret_subprogs2, int arg, struct file *ret) +{ + *(volatile long *)ret; + *(volatile int *)&ret->f_mode; + bpf_for_each_map_elem(&test_array, test_cb, NULL, 0); + return 0; +} + +SEC("fexit/bpf_testmod_return_ptr") +int BPF_PROG(handle_fexit_ret_subprogs3, int arg, struct file *ret) +{ + *(volatile long *)ret; + *(volatile int *)&ret->f_mode; + bpf_for_each_map_elem(&test_array, test_cb, NULL, 0); + return 0; +} + +char _license[] SEC("license") = "GPL"; -- 2.25.1