Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <sdf@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200617010416.93086-3-sdf@google.com

authored by

Stanislav Fomichev and committed by
Alexei Starovoitov
8030e250 a0cb12b0

+14
+14
Documentation/bpf/prog_cgroup_sockopt.rst
··· 86 86 *not* the original input ``setsockopt`` arguments. The potentially 87 87 modified values will be then passed down to the kernel. 88 88 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 + 89 103 Example 90 104 ======= 91 105