From: Ilya Shchipletsov <rabbelkin@mail.ru>
To: bpf@vger.kernel.org
Cc: Ilya Shchipletsov <rabbelkin@mail.ru>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>,
Florent Revest <revest@chromium.org>,
Nikita Marushkin <hfggklm@gmail.com>,
lvc-project@linuxtesting.org, linux-kernel@vger.kernel.org
Subject: [PATCH bpf v2 2/2] selftests/bpf: Add test cases for various pointer specifiers
Date: Mon, 28 Oct 2024 19:53:41 +0000 [thread overview]
Message-ID: <20241028195343.2104-3-rabbelkin@mail.ru> (raw)
In-Reply-To: <20241028195343.2104-1-rabbelkin@mail.ru>
Extend snprintf negative tests to cover pointer specifiers to prevent possible
invalid handling of %p% from happening again.
./test_progs -t snprintf
#302/1 snprintf/snprintf_positive:OK
#302/2 snprintf/snprintf_negative:OK
#302 snprintf:OK
#303 snprintf_btf:OK
Summary: 2/2 PASSED, 0 SKIPPED, 0 FAILED
Co-developed-by: Nikita Marushkin <hfggklm@gmail.com>
Signed-off-by: Nikita Marushkin <hfggklm@gmail.com>
Signed-off-by: Ilya Shchipletsov <rabbelkin@mail.ru>
---
tools/testing/selftests/bpf/prog_tests/snprintf.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/snprintf.c b/tools/testing/selftests/bpf/prog_tests/snprintf.c
index 4be6fdb78c6a..b5b6371e09bb 100644
--- a/tools/testing/selftests/bpf/prog_tests/snprintf.c
+++ b/tools/testing/selftests/bpf/prog_tests/snprintf.c
@@ -116,6 +116,21 @@ static void test_snprintf_negative(void)
ASSERT_ERR(load_single_snprintf("%llc"), "invalid specifier 7");
ASSERT_ERR(load_single_snprintf("\x80"), "non ascii character");
ASSERT_ERR(load_single_snprintf("\x1"), "non printable character");
+
+ ASSERT_OK(load_single_snprintf("valid %p"), "valid usage");
+
+ ASSERT_ERR(load_single_snprintf("%p%"), "too many specifiers 1");
+ ASSERT_ERR(load_single_snprintf("%pK%"), "too many specifiers 2");
+ ASSERT_ERR(load_single_snprintf("%px%"), "too many specifiers 3");
+ ASSERT_ERR(load_single_snprintf("%ps%"), "too many specifiers 4");
+ ASSERT_ERR(load_single_snprintf("%pS%"), "too many specifiers 5");
+ ASSERT_ERR(load_single_snprintf("%pB%"), "too many specifiers 6");
+ ASSERT_ERR(load_single_snprintf("%pi4%"), "too many specifiers 7");
+ ASSERT_ERR(load_single_snprintf("%pI4%"), "too many specifiers 8");
+ ASSERT_ERR(load_single_snprintf("%pi6%"), "too many specifiers 9");
+ ASSERT_ERR(load_single_snprintf("%pI6%"), "too many specifiers 10");
+ ASSERT_ERR(load_single_snprintf("%pks%"), "too many specifiers 11");
+ ASSERT_ERR(load_single_snprintf("%pus%"), "too many specifiers 12");
}
void test_snprintf(void)
--
2.43.0
next prev parent reply other threads:[~2024-10-28 19:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-28 19:53 [PATCH bpf v2 0/2] bpf: enhance validation of pointer formatting Ilya Shchipletsov
2024-10-28 19:53 ` [PATCH bpf v2 1/2] bpf: fix %p% runtime check in bpf_bprintf_prepare Ilya Shchipletsov
2024-10-29 6:18 ` Yonghong Song
2024-10-31 16:17 ` Florent Revest
2024-11-06 8:42 ` Fedor Pchelkin
2024-10-28 19:53 ` Ilya Shchipletsov [this message]
2024-10-29 6:19 ` [PATCH bpf v2 2/2] selftests/bpf: Add test cases for various pointer specifiers Yonghong Song
2024-10-31 16:18 ` Florent Revest
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=20241028195343.2104-3-rabbelkin@mail.ru \
--to=rabbelkin@mail.ru \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=hfggklm@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=martin.lau@linux.dev \
--cc=revest@chromium.org \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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
all inboxes | Powered by JetHome®