Skip to content

cBPF filter API adjustment

Jens Axboe io-uring lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 2 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2io_uring/bpf_filter: move filter size and populate helper into structio_uring/bpf_filter.c io_uring/opdef.c io_uring/opdef.h+18 -110 replies
2/2io_uring/bpf_filter: pass in expected filter payload sizeinclude/uapi/linux/io_uring/bpf_filter.h io_uring/bpf_filter.c+56 -171 reply

Reviews trailers per patch

None of the 2 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchChristian Brauner
SeriesR-b
1/2
2/2

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCHSET 0/2] cBPF filter API adjustment

Hi,

Christian brought up a good point on the API - what if the task and kernel differ on what the payload size is for an opcode? Currently there are two defined payloads, inside struct io_uring_bpf_ctx:

	struct {
		__u32	family;
		__u32	type;
		__u32	protocol;
	} socket;

	struct {
		__u64	flags;
		__u64	mode;
		__u64	resolve;
	} open;

and it could be a requirement that a filter exactly matches the payload that the kernel uses, if extensions have been made on the kernel side. Hence this small series updates the API slightly:

struct io_uring_bpf_filter adds a pdu_size field, which userspace can set to the size if expects. For an OPENAT/OPENAT2 filter, that would be sizeof(struct open) above. The kernel can validate that they match, where the mismatch policy is controlled by userspace. See patch 2 for details. In case of a mismatch that causes an error, the kernel side pdu_size is copied back to userspace.

Patch 1 exposes the pdu_size by shoving the filtering and pdu_size into the issue side definitions, and patch 2 implements the above size checking.

The liburing master branch has been updated as well for this, as copying back the pdu_size necessitates changing the API on that side. Test cases and man pages are updated as well.

 include/uapi/linux/io_uring/bpf_filter.h |  8 ++-
 io_uring/bpf_filter.c                    | 82 ++++++++++++++++--------
 io_uring/opdef.c                         |  6 ++
 io_uring/opdef.h                         |  6 ++
 4 files changed, 74 insertions(+), 28 deletions(-)
Signature · 1 line
Jens Axboe