diff options
| author | Kumar Kartikeya Dwivedi <memxor@gmail.com> | 2026-08-23 21:32:00 +0200 |
|---|---|---|
| committer | Daniel Borkmann <daniel@iogearbox.net> | 2026-08-25 17:00:05 +0200 |
| commit | ea0b60fae724aa1147d4a07eda5131d3a9a9977e (patch) | |
| tree | 60aff849e1f145ade14448769207e71c1a56a6a3 /kernel | |
| parent | ce36e38beb6863664994f5676122359c8d323203 (diff) | |
bpf: Reject oversized stream read buffers
BPF_PROG_STREAM_READ_BY_FD exposes stream_buf_len as a u32, but the
internal stream reader accepts an int. Values above INT_MAX therefore
become negative before bpf_stream_read(), producing negative consumption
lengths. The generic usercopy size check prevents the oversized copy, but
emits a warning and reports EFAULT for an unchecked argument.
Change bpf_prog_stream_read() to accept u32 and reject values that the
signed reader cannot represent.
Fixes: 5ab154f1463a ("bpf: Introduce BPF standard streams")
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20260823193202.2389715-2-memxor@gmail.com
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/bpf/stream.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/kernel/bpf/stream.c b/kernel/bpf/stream.c index 7a5c3ac8676b..2b80a0599865 100644 --- a/kernel/bpf/stream.c +++ b/kernel/bpf/stream.c @@ -203,13 +203,15 @@ static int bpf_stream_read(struct bpf_stream *stream, void __user *buf, int len) return ret ? ret : len - rem_len; } -int bpf_prog_stream_read(struct bpf_prog *prog, enum bpf_stream_id stream_id, void __user *buf, int len) +int bpf_prog_stream_read(struct bpf_prog *prog, enum bpf_stream_id stream_id, void __user *buf, u32 len) { struct bpf_stream *stream; stream = bpf_stream_get(stream_id, prog->aux); if (!stream) return -ENOENT; + if (len > INT_MAX) + return -EINVAL; return bpf_stream_read(stream, buf, len); } |
