[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210330223748.399563-1-pctammela@mojatatu.com>
Date: Tue, 30 Mar 2021 19:37:46 -0300
From: Pedro Tammela <pctammela@...il.com>
To: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>, Joe Stringer <joe@...ium.io>,
Quentin Monnet <quentin@...valent.com>,
netdev@...r.kernel.org (open list:BPF (Safe dynamic programs and tools)),
bpf@...r.kernel.org (open list:BPF (Safe dynamic programs and tools)),
linux-kernel@...r.kernel.org (open list)
Cc: Pedro Tammela <pctammela@...atatu.com>
Subject: [PATCH bpf-next v2] bpf: check flags in 'bpf_ringbuf_discard()' and 'bpf_ringbuf_submit()'
The current code only checks flags in 'bpf_ringbuf_output()'.
Signed-off-by: Pedro Tammela <pctammela@...atatu.com>
---
include/uapi/linux/bpf.h | 8 ++++----
kernel/bpf/ringbuf.c | 13 +++++++++++--
tools/include/uapi/linux/bpf.h | 8 ++++----
3 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 100cb2e4c104..38b0b15f99f0 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -4073,7 +4073,7 @@ union bpf_attr {
* Valid pointer with *size* bytes of memory available; NULL,
* otherwise.
*
- * void bpf_ringbuf_submit(void *data, u64 flags)
+ * long bpf_ringbuf_submit(void *data, u64 flags)
* Description
* Submit reserved ring buffer sample, pointed to by *data*.
* If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
@@ -4083,9 +4083,9 @@ union bpf_attr {
* If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
* of new data availability is sent unconditionally.
* Return
- * Nothing. Always succeeds.
+ * 0 on success, or a negative error in case of failure.
*
- * void bpf_ringbuf_discard(void *data, u64 flags)
+ * long bpf_ringbuf_discard(void *data, u64 flags)
* Description
* Discard reserved ring buffer sample, pointed to by *data*.
* If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
@@ -4095,7 +4095,7 @@ union bpf_attr {
* If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
* of new data availability is sent unconditionally.
* Return
- * Nothing. Always succeeds.
+ * 0 on success, or a negative error in case of failure.
*
* u64 bpf_ringbuf_query(void *ringbuf, u64 flags)
* Description
diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c
index f25b719ac786..f76dafe2427e 100644
--- a/kernel/bpf/ringbuf.c
+++ b/kernel/bpf/ringbuf.c
@@ -397,26 +397,35 @@ static void bpf_ringbuf_commit(void *sample, u64 flags, bool discard)
BPF_CALL_2(bpf_ringbuf_submit, void *, sample, u64, flags)
{
+ if (unlikely(flags & ~(BPF_RB_NO_WAKEUP | BPF_RB_FORCE_WAKEUP)))
+ return -EINVAL;
+
bpf_ringbuf_commit(sample, flags, false /* discard */);
+
return 0;
}
const struct bpf_func_proto bpf_ringbuf_submit_proto = {
.func = bpf_ringbuf_submit,
- .ret_type = RET_VOID,
+ .ret_type = RET_INTEGER,
.arg1_type = ARG_PTR_TO_ALLOC_MEM,
.arg2_type = ARG_ANYTHING,
};
BPF_CALL_2(bpf_ringbuf_discard, void *, sample, u64, flags)
{
+
+ if (unlikely(flags & ~(BPF_RB_NO_WAKEUP | BPF_RB_FORCE_WAKEUP)))
+ return -EINVAL;
+
bpf_ringbuf_commit(sample, flags, true /* discard */);
+
return 0;
}
const struct bpf_func_proto bpf_ringbuf_discard_proto = {
.func = bpf_ringbuf_discard,
- .ret_type = RET_VOID,
+ .ret_type = RET_INTEGER,
.arg1_type = ARG_PTR_TO_ALLOC_MEM,
.arg2_type = ARG_ANYTHING,
};
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 3d6d324184c0..a32eefb786f9 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -4073,7 +4073,7 @@ union bpf_attr {
* Valid pointer with *size* bytes of memory available; NULL,
* otherwise.
*
- * void bpf_ringbuf_submit(void *data, u64 flags)
+ * long bpf_ringbuf_submit(void *data, u64 flags)
* Description
* Submit reserved ring buffer sample, pointed to by *data*.
* If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
@@ -4083,9 +4083,9 @@ union bpf_attr {
* If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
* of new data availability is sent unconditionally.
* Return
- * Nothing. Always succeeds.
+ * 0 on success, or a negative error in case of failure.
*
- * void bpf_ringbuf_discard(void *data, u64 flags)
+ * long bpf_ringbuf_discard(void *data, u64 flags)
* Description
* Discard reserved ring buffer sample, pointed to by *data*.
* If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
@@ -4095,7 +4095,7 @@ union bpf_attr {
* If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
* of new data availability is sent unconditionally.
* Return
- * Nothing. Always succeeds.
+ * 0 on success, or a negative error in case of failure.
*
* u64 bpf_ringbuf_query(void *ringbuf, u64 flags)
* Description
--
2.25.1
Powered by blists - more mailing lists