Skip to content

Commit 8030e25

Browse files
fomichevAlexei Starovoitov
authored andcommitted
bpf: Document optval > PAGE_SIZE behavior for sockopt hooks
Extend existing doc with more details about requiring ctx->optlen = 0 for handling optval > PAGE_SIZE. Signed-off-by: Stanislav Fomichev <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent a0cb12b commit 8030e25

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Documentation/bpf/prog_cgroup_sockopt.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ then the next program in the chain (A) will see those changes,
8686
*not* the original input ``setsockopt`` arguments. The potentially
8787
modified values will be then passed down to the kernel.
8888

89+
Large optval
90+
============
91+
When the ``optval`` is greater than the ``PAGE_SIZE``, the BPF program
92+
can access only the first ``PAGE_SIZE`` of that data. So it has to options:
93+
94+
* Set ``optlen`` to zero, which indicates that the kernel should
95+
use the original buffer from the userspace. Any modifications
96+
done by the BPF program to the ``optval`` are ignored.
97+
* Set ``optlen`` to the value less than ``PAGE_SIZE``, which
98+
indicates that the kernel should use BPF's trimmed ``optval``.
99+
100+
When the BPF program returns with the ``optlen`` greater than
101+
``PAGE_SIZE``, the userspace will receive ``EFAULT`` errno.
102+
89103
Example
90104
=======
91105

0 commit comments

Comments
 (0)