Re: [PATCH v2 1/3] bpf: Allow NULL buffers in bpf_dynptr_slice(_rw)

From: Andrii Nakryiko
Date: Wed May 03 2023 - 14:50:21 EST


On Mon, May 1, 2023 at 5:52 PM Daniel Rosenberg <drosen@xxxxxxxxxx> wrote:
>
> 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@xxxxxxxxxx>
> ---

LGTM

Acked-by: Andrii Nakryiko <andrii@xxxxxxxxxx>

> Documentation/bpf/kfuncs.rst | 23 ++++++++++++++++++++++-
> include/linux/skbuff.h | 2 +-
> kernel/bpf/helpers.c | 30 ++++++++++++++++++------------
> kernel/bpf/verifier.c | 17 +++++++++++++----
> 4 files changed, 54 insertions(+), 18 deletions(-)
>

[...]