Message ID | 20221116072351.1168938-5-houtao@huaweicloud.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 05c1558bfcb63b95a9f530767c04c7db091560f2 |
Delegated to: | BPF |
Headers | show |
Series | libbpf: Fixes for ring buffer | expand |
diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c index 277e49137a95..3b65f04ec46e 100644 --- a/tools/lib/bpf/ringbuf.c +++ b/tools/lib/bpf/ringbuf.c @@ -490,6 +490,10 @@ void *user_ring_buffer__reserve(struct user_ring_buffer *rb, __u32 size) __u64 cons_pos, prod_pos; struct ringbuf_hdr *hdr; + /* The top two bits are used as special flags */ + if (size & (BPF_RINGBUF_BUSY_BIT | BPF_RINGBUF_DISCARD_BIT)) + return errno = E2BIG, NULL; + /* Synchronizes with smp_store_release() in __bpf_user_ringbuf_peek() in * the kernel. */