From: Yonghong Song <yonghong.song@linux.dev>
To: Ilya Shchipletsov <rabbelkin@mail.ru>, bpf@vger.kernel.org
Cc: 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>,
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: Re: [PATCH bpf v2 1/2] bpf: fix %p% runtime check in bpf_bprintf_prepare
Date: Mon, 28 Oct 2024 23:18:40 -0700 [thread overview]
Message-ID: <f4c533a8-0d5e-476a-96cb-e76b67a4d62c@linux.dev> (raw)
In-Reply-To: <20241028195343.2104-2-rabbelkin@mail.ru>
On 10/28/24 12:53 PM, Ilya Shchipletsov wrote:
> Fuzzing reports a warning in format_decode()
>
> Please remove unsupported %� in format string
> WARNING: CPU: 0 PID: 5091 at lib/vsprintf.c:2680 format_decode+0x1193/0x1bb0 lib/vsprintf.c:2680
> Modules linked in:
> CPU: 0 PID: 5091 Comm: syz-executor879 Not tainted 6.10.0-rc1-syzkaller-00021-ge0cce98fe279 #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/02/2024
> RIP: 0010:format_decode+0x1193/0x1bb0 lib/vsprintf.c:2680
> Call Trace:
> <TASK>
> bstr_printf+0x137/0x1210 lib/vsprintf.c:3253
> ____bpf_trace_printk kernel/trace/bpf_trace.c:390 [inline]
> bpf_trace_printk+0x1a1/0x230 kernel/trace/bpf_trace.c:375
> bpf_prog_21da1b68f62e1237+0x36/0x41
> bpf_dispatcher_nop_func include/linux/bpf.h:1243 [inline]
> __bpf_prog_run include/linux/filter.h:691 [inline]
> bpf_prog_run include/linux/filter.h:698 [inline]
> bpf_test_run+0x40b/0x910 net/bpf/test_run.c:425
> bpf_prog_test_run_skb+0xafa/0x13a0 net/bpf/test_run.c:1066
> bpf_prog_test_run+0x33c/0x3b0 kernel/bpf/syscall.c:4291
> __sys_bpf+0x48d/0x810 kernel/bpf/syscall.c:5705
> __do_sys_bpf kernel/bpf/syscall.c:5794 [inline]
> __se_sys_bpf kernel/bpf/syscall.c:5792 [inline]
> __x64_sys_bpf+0x7c/0x90 kernel/bpf/syscall.c:5792
> do_syscall_x64 arch/x86/entry/common.c:52 [inline]
> do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
> entry_SYSCALL_64_after_hwframe+0x77/0x7f
>
> The problem occurs when trying to pass %p% at the end of format string,
> which would result in skipping last % and passing invalid format string
> down to format_decode() that would cause warning because of invalid
> character after %.
>
> Fix issue by advancing pointer only if next char is format modifier.
> If next char is null/space/punct, then just accept formatting as is,
> without advancing the pointer.
>
> Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
>
> Reported-by: syzbot+e2c932aec5c8a6e1d31c@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=e2c932aec5c8a6e1d31c
> Fixes: 48cac3f4a96d ("bpf: Implement formatted output helpers with bstr_printf")
> Co-developed-by: Nikita Marushkin <hfggklm@gmail.com>
> Signed-off-by: Nikita Marushkin <hfggklm@gmail.com>
> Signed-off-by: Ilya Shchipletsov <rabbelkin@mail.ru>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
next prev parent reply other threads:[~2024-10-29 6:18 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 [this message]
2024-10-31 16:17 ` Florent Revest
2024-11-06 8:42 ` Fedor Pchelkin
2024-10-28 19:53 ` [PATCH bpf v2 2/2] selftests/bpf: Add test cases for various pointer specifiers Ilya Shchipletsov
2024-10-29 6:19 ` 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=f4c533a8-0d5e-476a-96cb-e76b67a4d62c@linux.dev \
--to=yonghong.song@linux.dev \
--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=rabbelkin@mail.ru \
--cc=revest@chromium.org \
--cc=sdf@fomichev.me \
--cc=song@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.