From: Paul Chaignon <paul.chaignon@gmail.com>
To: Yihan Ding <dingyihan@uniontech.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, shuah@kernel.org,
linux-kernel@vger.kernel.org, alan.maguire@oracle.com,
kernel@uniontech.com
Subject: Re: [PATCH bpf v2 1/2] bpf: allow UTF-8 literals in bpf_bprintf_prepare()
Date: Wed, 15 Apr 2026 12:49:15 +0200 [thread overview]
Message-ID: <ad9tK74n_7J4FGtq@mail.gmail.com> (raw)
In-Reply-To: <ad9sKyzvsYqgu_yY@mail.gmail.com>
On Wed, Apr 15, 2026 at 12:45:02PM +0200, Paul Chaignon wrote:
> On Wed, Apr 15, 2026 at 11:21:25AM +0800, Yihan Ding wrote:
> > bpf_bprintf_prepare() only needs ASCII parsing for conversion
> > specifiers. Plain text can safely carry bytes >= 0x80, so allow
> > UTF-8 literals outside '%' sequences while keeping ASCII control
> > bytes rejected and format specifiers ASCII-only.
> >
> > This keeps existing parsing rules for format directives unchanged,
> > while allowing helpers such as bpf_trace_printk() to emit UTF-8
> > literal text.
> >
> > Fixes: 48cac3f4a96d ("bpf: Implement formatted output helpers with bstr_printf")
> > Suggested-by: Paul Chaignon <paul.chaignon@gmail.com>
>
> I don't think this tag is appropriate here. If you want to give credit
> for changes made after reviews, you can do so in the Changelogs of the
> cover letter :)
>
> > Signed-off-by: Yihan Ding <dingyihan@uniontech.com>
> > ---
> > kernel/bpf/helpers.c | 16 +++++++++++++++-
> > 1 file changed, 15 insertions(+), 1 deletion(-)
> >
> > diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> > index 6eb6c82ed2ee..6319b39c92f9 100644
> > --- a/kernel/bpf/helpers.c
> > +++ b/kernel/bpf/helpers.c
> > @@ -845,7 +845,13 @@ int bpf_bprintf_prepare(const char *fmt, u32 fmt_size, const u64 *raw_args,
> > data->buf = buffers->buf;
> >
> > for (i = 0; i < fmt_size; i++) {
> > - if ((!isprint(fmt[i]) && !isspace(fmt[i])) || !isascii(fmt[i])) {
> > + unsigned char c = fmt[i];
> > +
> > + /*
> > + * Permit bytes >= 0x80 in plain text so UTF-8 literals can pass
> > + * through unchanged, while still rejecting ASCII control bytes.
> > + */
> > + if (isascii(c) && !isprint(c) && !isspace(c)) {
> > err = -EINVAL;
> > goto out;
> > }
> > @@ -867,6 +873,14 @@ int bpf_bprintf_prepare(const char *fmt, u32 fmt_size, const u64 *raw_args,
> > * always access fmt[i + 1], in the worst case it will be a 0
> > */
> > i++;
> > + /*
> > + * The format parser below only understands ASCII conversion
> > + * specifiers and modifiers, so reject non-ASCII after '%'.
> > + */
> > + if (!isascii((unsigned char)fmt[i])) {
> > + err = -EINVAL;
> > + goto out;
> > + }
>
> Acked-by: Paul Chaignon <paul.chaignon@gmail.com>
Actually, this patch will require changes to fixup the existing
test_snprintf_negative() selftest that is currently failing. That fixup
needs to be in this commit to not break selftests during bisections.
>
> >
> > /* skip optional "[0 +-][num]" width formatting field */
> > while (fmt[i] == '0' || fmt[i] == '+' || fmt[i] == '-' ||
> > --
> > 2.20.1
next prev parent reply other threads:[~2026-04-15 10:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-15 3:21 [PATCH bpf v2 0/2] bpf: allow UTF-8 literals in bpf_bprintf_prepare() Yihan Ding
2026-04-15 3:21 ` [PATCH bpf v2 1/2] " Yihan Ding
2026-04-15 10:44 ` Paul Chaignon
2026-04-15 10:49 ` Paul Chaignon [this message]
2026-04-15 3:21 ` [PATCH bpf v2 2/2] selftests/bpf: cover UTF-8 trace_printk output Yihan Ding
2026-04-15 10:46 ` Paul Chaignon
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=ad9tK74n_7J4FGtq@mail.gmail.com \
--to=paul.chaignon@gmail.com \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dingyihan@uniontech.com \
--cc=kernel@uniontech.com \
--cc=linux-kernel@vger.kernel.org \
--cc=shuah@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