io_uring/net: mask socket type with SOCK_TYPE_MASK in io_socket_bpf_populate()
PATCH 1/1 io_uring/net: mask socket type with SOCK_TYPE_MASK in io_socket_bpf_populate()
When an IORING_OP_SOCKET request is prepared in io_socket_prep(), sock->type retains creation flags such as SOCK_CLOEXEC and SOCK_NONBLOCK until __sys_socket_file() masks them off with SOCK_TYPE_MASK during execution.
However, io_socket_bpf_populate() copies sock->type into bctx->socket.type without masking off ~SOCK_TYPE_MASK. As a result, a cBPF filter inspecting bctx->socket.type against socket types such as SOCK_DGRAM or SOCK_STREAM can be bypassed by ORing SOCK_CLOEXEC or SOCK_NONBLOCK into the socket type.
Mask sock->type with SOCK_TYPE_MASK when populating bctx->socket.type.
--- io_uring/net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
io_uring/net.c +1 -1
@@ -1711,7 +1711,7 @@ void io_socket_bpf_populate(struct io_uring_bpf_ctx *bctx, struct io_kiocb *req) struct io_socket *sock = io_kiocb_to_cmd(req, struct io_socket); bctx->socket.family = sock->domain; - bctx->socket.type = sock->type; + bctx->socket.type = sock->type &SOCK_TYPE_MASK ; bctx->socket.protocol = sock->protocol; }
Signature · 1 line
2.56.0.257.gf7497c7d27-goog
Quoted 5 lines · Dominik Maier
When an
IORING_OP_SOCKETrequest is prepared inio_socket_prep(),sock->typeretains creation flags such asSOCK_CLOEXECandSOCK_NONBLOCKuntil__sys_socket_file()masks them off withSOCK_TYPE_MASKduring execution.
Quoted 7 lines
However,
io_socket_bpf_populate()copiessock->typeintobctx->socket.typewithout masking off ~SOCK_TYPE_MASK. As a result, a cBPF filter inspectingbctx->socket.typeagainst socket types such asSOCK_DGRAMorSOCK_STREAMcan be bypassed by ORingSOCK_CLOEXECorSOCK_NONBLOCKinto the socket type.[...]
Applied, thanks!
[1/1] io_uring/net: mask socket type with SOCK_TYPE_MASK in io_socket_bpf_populate()
commit: e66907c3ba229399ecfb4ef032b95a4a071c894e
Best regards,
Signature · 1 line
Jens Axboe