public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Matteo Croce <mcroce@linux.microsoft.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>, bpf@vger.kernel.org
Cc: Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: [PATCH bpf-next v2 2/2] selftests/bpf: test maximum recursion depth for bpf_core_types_are_compat()
Date: Wed,  2 Feb 2022 22:13:28 +0100	[thread overview]
Message-ID: <20220202211328.176481-3-mcroce@linux.microsoft.com> (raw)
In-Reply-To: <20220202211328.176481-1-mcroce@linux.microsoft.com>

From: Matteo Croce <mcroce@microsoft.com>

bpf_core_types_are_compat() was limited to 2 recursion levels, which are
enough to parse a function prototype.
Add a test which checks the existence of a function prototype, so to
test the bpf_core_types_are_compat() code path.

Signed-off-by: Matteo Croce <mcroce@microsoft.com>
---
 .../selftests/bpf/bpf_testmod/bpf_testmod.c        |  3 +++
 tools/testing/selftests/bpf/progs/core_kern.c      | 14 ++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
index 595d32ab285a..a457071a7751 100644
--- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
+++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
@@ -13,6 +13,9 @@
 #define CREATE_TRACE_POINTS
 #include "bpf_testmod-events.h"
 
+typedef int (*func_proto_typedef)(long);
+func_proto_typedef funcp = NULL;
+
 DEFINE_PER_CPU(int, bpf_testmod_ksym_percpu) = 123;
 
 noinline void
diff --git a/tools/testing/selftests/bpf/progs/core_kern.c b/tools/testing/selftests/bpf/progs/core_kern.c
index 13499cc15c7d..bfea86b42563 100644
--- a/tools/testing/selftests/bpf/progs/core_kern.c
+++ b/tools/testing/selftests/bpf/progs/core_kern.c
@@ -101,4 +101,18 @@ int balancer_ingress(struct __sk_buff *ctx)
 	return 0;
 }
 
+typedef int (*func_proto_typedef___match)(long);
+typedef void (*func_proto_typedef___doesnt_match)(char*);
+
+int out[2];
+
+SEC("raw_tracepoint/sys_enter")
+int core_relo_recur_limit(void *ctx)
+{
+	out[0] = bpf_core_type_exists(func_proto_typedef___match);
+	out[1] = bpf_core_type_exists(func_proto_typedef___doesnt_match);
+
+	return 0;
+}
+
 char LICENSE[] SEC("license") = "GPL";
-- 
2.34.1


  parent reply	other threads:[~2022-02-02 21:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-02 21:13 [PATCH bpf-next v2 0/2] limit bpf_core_types_are_compat recursion Matteo Croce
2022-02-02 21:13 ` [PATCH bpf-next v2 1/2] bpf: limit bpf_core_types_are_compat() recursion Matteo Croce
2022-02-02 21:13 ` Matteo Croce [this message]
2022-02-03 17:36   ` [PATCH bpf-next v2 2/2] selftests/bpf: test maximum recursion depth for bpf_core_types_are_compat() Alexei Starovoitov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220202211328.176481-3-mcroce@linux.microsoft.com \
    --to=mcroce@linux.microsoft.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox