bpf: roll back stream capacity when allocation fails - #13317
bpf: roll back stream capacity when allocation fails#13317kernel-patches-daemon-bpf[bot] wants to merge 5 commits into
Conversation
|
Upstream branch: d82ebfc |
AI reviewed your patch. Please fix the bug or email reply why it's not a bug. In-Reply-To-Subject: |
|
Forwarding comment 5301480050 via email |
a5710c4 to
233ffc0
Compare
|
Upstream branch: ce7c9f6 |
8383c25 to
1deee23
Compare
233ffc0 to
5d19d61
Compare
|
Upstream branch: c93cbdb |
1deee23 to
7cb6d1c
Compare
5d19d61 to
7b509dc
Compare
|
Upstream branch: c93cbdb |
7cb6d1c to
4070ae8
Compare
7b509dc to
93097fe
Compare
|
Upstream branch: 8eb1892 |
4070ae8 to
c7fc1a6
Compare
93097fe to
b51acce
Compare
|
Upstream branch: d99bda7 |
c7fc1a6 to
ed81826
Compare
b51acce to
b27c6f9
Compare
|
Upstream branch: 34e0eb7 |
ed81826 to
d43d8fb
Compare
b27c6f9 to
5d621a7
Compare
|
Upstream branch: 5fe7007 |
d43d8fb to
6db1acf
Compare
5d621a7 to
81e4232
Compare
|
Upstream branch: 77877bf |
6db1acf to
0704c8d
Compare
81e4232 to
f0e6afe
Compare
|
Upstream branch: adb7719 |
0704c8d to
8826bcd
Compare
f0e6afe to
7ac20a0
Compare
|
Upstream branch: 6b0835a |
8826bcd to
20a9ad5
Compare
7ac20a0 to
fd7f5fa
Compare
|
Upstream branch: 6ab6a94 |
20a9ad5 to
5b0dbc2
Compare
fd7f5fa to
23ff631
Compare
bpf_stream_push_str() accounts the string length before allocating a stream element. If the allocation fails, the length remains charged even though no element is queued and therefore cannot be released by a reader. Repeated failures can exhaust the stream capacity permanently until the BPF program is freed. Refactor bpf_stream_release_capacity() to take a length so the consume and release sides are symmetric, and use it to roll back the charge when creating the stream element fails. Fixes: 5ab154f ("bpf: Introduce BPF standard streams") Signed-off-by: Jianlin Shi <shijianlin11@foxmail.com>
bpf_stream_stage_printk() increments ss->len before pushing the formatted string to the staging log. If element allocation fails, ss->len remains inflated and bpf_stream_stage_commit() permanently charges the stream capacity for data that was never queued. Only account the string length after a successful push, and use vscnprintf() so the staged length is the truncated payload without the trailing NUL. Fixes: 5ab154f ("bpf: Introduce BPF standard streams") Signed-off-by: Jianlin Shi <shijianlin11@foxmail.com>
bpf_stream_read() pops and frees stream elements after a successful copy_to_user(). If a later copy_to_user() fails, it currently restores only the current element's consumed_len and returns -EFAULT, hiding bytes already delivered to userspace and making the consumed data unrecoverable on retry. On a short copy, keep the successfully copied prefix of the current element and return the number of bytes copied. Return -EFAULT only when no bytes were copied for the call. Fixes: 5ab154f ("bpf: Introduce BPF standard streams") Signed-off-by: Jianlin Shi <shijianlin11@foxmail.com>
|
Upstream branch: 3d9393f |
bstr_printf() returns the would-be length excluding the trailing NUL. When that value is >= MAX_BPRINTF_BUF the message was truncated, but bpf_stream_push_str() still tried to allocate with the inflated length and failed with -ENOMEM. The boundary case of exactly MAX_BPRINTF_BUF could also copy the trailing NUL into the stream element. Reject such lengths with -E2BIG before charging stream capacity, and tighten bpf_stream_elem_alloc() to accept only payloads strictly shorter than the bprintf buffer. Fixes: 5ab154f ("bpf: Introduce BPF standard streams") Signed-off-by: Jianlin Shi <shijianlin11@foxmail.com>
Add coverage for the stream fixes requested on the capacity rollback series: - oversized bpf_stream_printk() returns -E2BIG and does not leak capacity for a subsequent successful write; - bpf_prog_stream_read() returns the successfully copied prefix when the userspace buffer straddles an unmapped page. Signed-off-by: Jianlin Shi <shijianlin11@foxmail.com>
5b0dbc2 to
b6a15fe
Compare
Pull request for series with
subject: bpf: roll back stream capacity when allocation fails
version: 3
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1146425