bpf: Allow NULL buffers in bpf_dynptr_slice(_rw)
authorDaniel Rosenberg <drosen@google.com>
Sat, 6 May 2023 01:31:30 +0000 (18:31 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 6 May 2023 23:42:57 +0000 (16:42 -0700)
commit3bda08b63670c39be390fcb00e7718775508e673
treecdbbc77269e5b94951bdf4a89d9aa03469587c81
parente04ddf179c2acb6de841016e5bcf29b26705b4ec
bpf: Allow NULL buffers in bpf_dynptr_slice(_rw)

bpf_dynptr_slice(_rw) uses a user provided buffer if it can not provide
a pointer to a block of contiguous memory. This buffer is unused in the
case of local dynptrs, and may be unused in other cases as well. There
is no need to require the buffer, as the kfunc can just return NULL if
it was needed and not provided.

This adds another kfunc annotation, __opt, which combines with __sz and
__szk to allow the buffer associated with the size to be NULL. If the
buffer is NULL, the verifier does not check that the buffer is of
sufficient size.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Link: https://lore.kernel.org/r/20230506013134.2492210-2-drosen@google.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Documentation/bpf/kfuncs.rst
include/linux/skbuff.h
kernel/bpf/helpers.c
kernel/bpf/verifier.c