public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Yihan Ding <dingyihan@uniontech.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	shuah@kernel.org, alan.maguire@oracle.com,
	paul.chaignon@gmail.com, linux-kernel@vger.kernel.org,
	Yihan Ding <dingyihan@uniontech.com>
Subject: [PATCH bpf v3 0/2] bpf: allow UTF-8 literals in bpf_bprintf_prepare()
Date: Thu, 16 Apr 2026 20:01:40 +0800	[thread overview]
Message-ID: <20260416120142.1420646-1-dingyihan@uniontech.com> (raw)

bpf_bprintf_prepare() currently rejects any non-ASCII byte in format
strings, so helpers such as bpf_trace_printk() fail to emit UTF-8
literal text even when those bytes are not part of a format specifier.

Keep plain text permissive while continuing to parse '%' sequences as
ASCII-only. Patch 1 updates snprintf_negative() at the same time so the
selftests stay consistent during bisection. Patch 2 then extends
trace_printk coverage for both the valid UTF-8 literal case and the
invalid non-ASCII-after-'%' case.

Changes in v3:
- drop Suggested-by trailers and move review credit into this changelog
- update test_snprintf_negative() in patch 1/2 so plain non-ASCII text is
  accepted while non-ASCII after '%' is still rejected, keeping
  ./test_progs -t snprintf aligned with the new behavior.
- clarify the trace_printk negative case with an explicit invalid format
  string and comment
- address Paul Chaignon's review feedback and keep the negative coverage
  requested earlier by Alan Maguire

Changes in v2:
- split the core change and selftest updates into two patches
- drop unnecessary isspace()/ispunct() casts
- add comments to clarify plain-text vs format-specifier handling
- add a negative selftest for non-ASCII bytes inside '%' sequences

Testing:
- Reproduced on x86_64 without the core fix: ASCII trace output works,
  while UTF-8 literal text in bpf_trace_printk() is rejected and
  produces no trace output
- Verified with tools/testing/selftests/bpf: ./test_progs -t trace_printk
- Verified with tools/testing/selftests/bpf: ./test_progs -t snprintf

Yihan Ding (2):
  bpf: allow UTF-8 literals in bpf_bprintf_prepare()
  selftests/bpf: cover UTF-8 trace_printk output

 kernel/bpf/helpers.c                          | 17 ++++++++++-
 .../selftests/bpf/prog_tests/snprintf.c       |  3 +-
 .../selftests/bpf/prog_tests/trace_printk.c   | 28 +++++++++++++++----
 .../selftests/bpf/progs/trace_printk.c        | 10 +++++++
 4 files changed, 50 insertions(+), 8 deletions(-)

-- 
2.20.1

             reply	other threads:[~2026-04-16 12:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-16 12:01 Yihan Ding [this message]
2026-04-16 12:01 ` [PATCH bpf v3 1/2] bpf: allow UTF-8 literals in bpf_bprintf_prepare() Yihan Ding
2026-04-16 13:03   ` sashiko-bot
2026-04-16 22:32   ` Paul Chaignon
2026-04-16 12:01 ` [PATCH bpf v3 2/2] selftests/bpf: cover UTF-8 trace_printk output Yihan Ding
2026-04-16 22:35   ` Paul Chaignon
2026-04-16 23:00 ` [PATCH bpf v3 0/2] bpf: allow UTF-8 literals in bpf_bprintf_prepare() patchwork-bot+netdevbpf

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=20260416120142.1420646-1-dingyihan@uniontech.com \
    --to=dingyihan@uniontech.com \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paul.chaignon@gmail.com \
    --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