Skip to content

bpf: Reject %p% format string in bprintf-like helpers #9202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: bpf_base
Choose a base branch
from

Conversation

kernel-patches-daemon-bpf[bot]
Copy link

Pull request for series with
subject: bpf: Reject %p% format string in bprintf-like helpers
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=976278

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: ee88bdd
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=976278
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: e34a79b
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=976278
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: e34a79b
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=976278
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: e34a79b
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=976278
version: 1

pchaigno added 2 commits June 27, 2025 14:18
static const char fmt[] = "%p%";
    bpf_trace_printk(fmt, sizeof(fmt));

The above BPF program isn't rejected and causes a kernel warning at
runtime:

    Please remove unsupported %\x00 in format string
    WARNING: CPU: 1 PID: 7244 at lib/vsprintf.c:2680 format_decode+0x49c/0x5d0

This happens because bpf_bprintf_prepare skips over the second %,
detected as punctuation, while processing %p. This patch fixes it by
not skipping over punctuation. %\x00 is then processed in the next
iteration and rejected.

Reported-by: [email protected]
Fixes: 48cac3f ("bpf: Implement formatted output helpers with bstr_printf")
Signed-off-by: Paul Chaignon <[email protected]>
This patch adds a couple negative test cases with a trailing % at the
end of the format string.

Signed-off-by: Paul Chaignon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant