Skip to content

bpf: fix out-of-bounds write in bpf_bprintf_prepare with %pI4/%pI6#11476

Closed
kernel-patches-daemon-bpf[bot] wants to merge 2 commits intobpf-next_basefrom
series/1069273=>bpf-next
Closed

bpf: fix out-of-bounds write in bpf_bprintf_prepare with %pI4/%pI6#11476
kernel-patches-daemon-bpf[bot] wants to merge 2 commits intobpf-next_basefrom
series/1069273=>bpf-next

Conversation

@kernel-patches-daemon-bpf
Copy link
Copy Markdown

Pull request for series with
subject: bpf: fix out-of-bounds write in bpf_bprintf_prepare with %pI4/%pI6
version: 3
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1069273

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 4a4fedb
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1069273
version: 3

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 350de5b
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1069273
version: 3

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 4b21ea5
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1069273
version: 3

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 21337b5
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1069273
version: 3

In bpf_bprintf_prepare(), the bounds check for %pI4 and %pI6 format
specifiers uses sizeof_cur_ip (4 for IPv4, 16 for IPv6), which is the
raw byte count of the IP address. However, snprintf() returns the
length of the formatted string, not the raw bytes. For IPv4 this can
be up to 15 characters (255.255.255.255) and for IPv6 up to 39.

tmp_buf is then advanced by (err + 1) using the full string length,
which can push tmp_buf past tmp_buf_end. The next iteration's bounds
check underflows due to unsigned arithmetic and passes, allowing a
write past the end of the per-CPU bin_args buffer.

Fix this by checking against the maximum formatted string size:
16 bytes for IPv4 and 40 bytes for IPv6.

Fixes: 48cac3f ("bpf: Implement formatted output helpers with bstr_printf")
Signed-off-by: Ibrahim Zein <zeroxjacks@gmail.com>
@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=1069273 expired. Closing PR.

@kernel-patches-daemon-bpf kernel-patches-daemon-bpf Bot deleted the series/1069273=>bpf-next branch March 23, 2026 20:32
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