io_uring/net: allow filtering on IORING_OP_CONNECT
PATCH 1/1 io_uring/net: allow filtering on IORING_OP_CONNECT
This adds custom filtering for IORING_OP_CONNECT, where the target family is always exposed, and (for AF_INET / AF_INET6) port and address are exposed. port and v4_addr are in network byte order so filter authors can compare against on-wire constants.
Skip population unless addr_len covers the populated fields, to avoid leaking stale io_async_msghdr data on short connects.
--- include/uapi/linux/io_uring/bpf_filter.h | 16 +++++++++ io_uring/net.c | 41 ++++++++++++++++++++++++ io_uring/net.h | 7 ++++ io_uring/opdef.c | 2 ++ 4 files changed, 66 insertions(+)
include/uapi/linux/io_uring/bpf_filter.h +16 -0
@@ -27,6 +27,22 @@ struct io_uring_bpf_ctx {__u64 mode;__u64 resolve; } open; +/* +* For CONNECT: fields are populated only when addr_len covers +* them; unpopulated fields are zero from the caller-side memset +* in io_uring_populate_bpf_ctx(). port and v4_addr are network +* byte order. Filters may only issue BPF_LD|BPF_W|BPF_ABS at +* 4-byte aligned offsets; load + mask for sub-word fields. +*/ +struct { +__u32 family;/* sa_family_t zero-extended */ +__be16 port; +__u8 pad[2 ]; +union { +__be32 v4_addr; +__u8 v6_addr[16 ]; + }; + } connect; }; };
io_uring/net.c +41 -0
47 lines not on this page · raw message
io_uring/net.h +7 -0
@@ -46,6 +46,7 @@ int io_accept(struct io_kiocb *req, unsigned int issue_flags);int io_socket_prep (struct io_kiocb *req,const struct io_uring_sqe *sqe);int io_socket (struct io_kiocb *req,unsigned int issue_flags);void io_socket_bpf_populate (struct io_uring_bpf_ctx *bctx,struct io_kiocb *req); +void io_connect_bpf_populate (struct io_uring_bpf_ctx *bctx,struct io_kiocb *req);int io_connect_prep (struct io_kiocb *req,const struct io_uring_sqe *sqe);int io_connect (struct io_kiocb *req,unsigned int issue_flags);
@@ -69,4 +70,10 @@ static inline void io_socket_bpf_populate(struct io_uring_bpf_ctx *bctx, struct io_kiocb *req) { } + +static inline void io_connect_bpf_populate (struct io_uring_bpf_ctx *bctx, +struct io_kiocb *req) +{ +} +#endif
io_uring/opdef.c +2 -0
@@ -203,9 +203,11 @@ const struct io_issue_def io_issue_defs[] = { .unbound_nonreg_file = 1, .pollout = 1,#if defined(CONFIG_NET ) + .filter_pdu_size = sizeof_field(struct io_uring_bpf_ctx, connect), .async_size = sizeof(struct io_async_msghdr), .prep = io_connect_prep, .issue = io_connect, + .filter_populate = io_connect_bpf_populate, #else .prep = io_eopnotsupp_prep,#endif
Signature · 1 line
2.53.0
Jens Axboe
maintainerQuoted 7 lines · Shouvik Kar
This adds custom filtering for
IORING_OP_CONNECT, where the target family is always exposed, and (forAF_INET/AF_INET6) port and address are exposed. port andv4_addrare in network byte order so filter authors can compare against on-wire constants.Skip population unless
addr_lencovers the populated fields, to avoid leaking staleio_async_msghdrdata on short connects.
Looks pretty straight forward to me. Do you have a liburing test case for this too?
Signature · 1 line
Jens Axboe
Yes -- just sent: "[PATCH liburing] tests: add cBPF filter tests for IORING_OP_CONNECT"
Regards,
Shouvik
Quoted 15 lines · Jens Axboe
Quoted 7 lines · Shouvik Kar
This adds custom filtering for
IORING_OP_CONNECT, where the target family is always exposed, and (forAF_INET/AF_INET6) port and address are exposed. port andv4_addrare in network byte order so filter authors can compare against on-wire constants.Skip population unless
addr_lencovers the populated fields, to avoid leaking staleio_async_msghdrdata on short connects.Looks pretty straight forward to me. Do you have a liburing test case for this too?
--
Jens Axboe
Quoted 9 lines · Shouvik Kar
This adds custom filtering for
IORING_OP_CONNECT, where the target family is always exposed, and (forAF_INET/AF_INET6) port and address are exposed. port andv4_addrare in network byte order so filter authors can compare against on-wire constants.Skip population unless
addr_lencovers the populated fields, to avoid leaking staleio_async_msghdrdata on short connects.[...]
Applied, thanks!
[1/1] io_uring/net: allow filtering on IORING_OP_CONNECT
commit: 899bea8248cee35d54760a5e7d61a76af8e64411
Best regards,
Signature · 1 line
Jens Axboe