Re: PROBLEM: Using BPF_PROG_TEST_RUN with data_out != NULL is unsafe

From: Lorenz Bauer
Date: Tue Aug 14 2018 - 09:28:04 EST


Sorry for the late reply.

On 4 April 2018 at 11:01, Daniel Borkmann <daniel@xxxxxxxxxxxxx> wrote:

> In case you point data_in and data_out to the same address, then the total buffer size therefore has to be
> attr.test.data_size_in + 256 in order to not overrun anything while not being
> aware of the BPF test program. The XDP_PACKET_HEADROOM is exposed to user space
> in linux/bpf.h.

Would it be possible to extend the API of BPF_PROG_TEST_RUN to allow
user space to specify the
length of the output buffer? The kernel could then either clamp
output, or return an error.

The current API seems fundamentally hard to use, and unsafe. It leads
to kludges like [1] in a library
I'm maintaining.

1: https://github.com/newtools/ebpf/blob/f4398602ca2a37b99a1f29df9a7e8adcc57be680/prog.go#L200-L204

--
Lorenz Bauer | Systems Engineer
25 Lavington St., London SE1 0NZ

www.cloudflare.com