Skip to content

bpf: allow UTF-8 literals in bpf_bprintf_prepare()

Yihan Ding bpf lkml 3 versions – Applied

Status from this message: This series was applied to bpf/bpf.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest2 patches 2 repliesApplied 2/2
  2. v22 patches 3 repliesSuperseded
  3. v11 patch 2 repliesSuperseded

Changes in v3 from the cover letter

- 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

Patches in v3 All 2 applied

#Subject and filesSizeRepliesApplied
1/2bpf: allow UTF-8 literals in bpf_bprintf_prepare()kernel/bpf/helpers.c tools/testing/selftests/bpf/prog_tests/snprintf.c+18 -21 replyApplied
2/2selftests/bpf: cover UTF-8 trace_printk outputtools/testing/selftests/bpf/prog_tests/trace_printk.c tools/testing/selftests/bpf/progs/trace_printk.c+32 -61 replyApplied

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchPaul Chaignon
1/2A-b
2/2A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH bpf v3 0/2] bpf: allow UTF-8 literals in bpf_bprintf_prepare()

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(-)
Signature · 1 line
2.20.1