Thread (14 messages) flat view 14 messages, 3 authors, 2020-11-26

Re: [PATCH v2 2/5] bpf: Add a bpf_sock_from_file helper

From: KP Singh <hidden>
Date: 2020-11-19 21:51:34
Also in: bpf, lkml

On Thu, Nov 19, 2020 at 5:27 PM Florent Revest [off-list ref] wrote:
From: Florent Revest <redacted>

While eBPF programs can check whether a file is a socket by file->f_op
== &socket_file_ops, they cannot convert the void private_data pointer
to a struct socket BTF pointer. In order to do this a new helper
wrapping sock_from_file is added.

This is useful to tracing programs but also other program types
inheriting this set of helpers such as iterators or LSM programs.

Signed-off-by: Florent Revest <redacted>
Acked-by: KP Singh <redacted>

Some minor comments.
quoted hunk ↗ jump to hunk
---
 include/uapi/linux/bpf.h       |  7 +++++++
 kernel/trace/bpf_trace.c       | 20 ++++++++++++++++++++
 scripts/bpf_helpers_doc.py     |  4 ++++
 tools/include/uapi/linux/bpf.h |  7 +++++++
 4 files changed, 38 insertions(+)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 162999b12790..7d598f161dc0 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -3787,6 +3787,12 @@ union bpf_attr {
  *             *ARG_PTR_TO_BTF_ID* of type *task_struct*.
  *     Return
  *             Pointer to the current task.
+ *
+ * struct socket *bpf_sock_from_file(struct file *file)
+ *     Description
+ *             If the given file contains a socket, returns the associated socket.
"If the given file is a socket" or "represents a socket" would fit better here.
+ *     Return
+ *             A pointer to a struct socket on success or NULL on failure.
NULL if the file is not a socket.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help