From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f52.google.com (mail-dl1-f52.google.com [74.125.82.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCBF42EA159 for ; Tue, 27 Jan 2026 18:33:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769538800; cv=none; b=T3ExbybPZANxKaGtxE/OQHugJlu22yU9rjKHo4EjMfwb5r2zxMbMvAhxiGOOQllUW+LmE0FAwFQ38Ij4QOhcpy0nSIjeyCM8r7O+sHACaqrL27xWZ6cJDorfc3hbHuLuCIWSv1rX+50YDsHR6SUWq0VqNew4B+jh1Yy4Eu9PvnY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769538800; c=relaxed/simple; bh=2xgw0e4rGDrGC5UYd/H0Fu/bjp4HcjhxLYk3aWVibCE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TCJSXofGlb/xcQbQ2/F7D4x4EyXkf5bKZqXu3tpi662/pI9RprG/kRFQlHdeLmmQ+VVcsnbxUCCFgTiEvXC++1nweGzpf9258RMofl40cK6yWq60s9Iny7RCw3gJC3O6fPL6ow15/fJULUnt0dFNw/g1aWNpf/TRLQob47FqJh0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=PFypzoVM; arc=none smtp.client-ip=74.125.82.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="PFypzoVM" Received: by mail-dl1-f52.google.com with SMTP id a92af1059eb24-1233c155a42so8589907c88.1 for ; Tue, 27 Jan 2026 10:33:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1769538798; x=1770143598; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yHX7748gxORjaCJqCbdbPxtHhuUnXJdKJ2s3V+FA30o=; b=PFypzoVM5en/innuD510oE2GnPOk+3AayVSvA/qaiCpuGVvhR1ojiuVxEgZx+lk1kd lwET+IBL2s03uf6sd2SfnxrKzZb4CXqSdc1WbPv+avpn9B71UdgQWPj/H54mtvLYEG6Z JJ3XJnWB0tzUBzeDL8GQeHS9p41Cbj35DezlYjqnj7YOlwaWN2UWl9DaKF+UBJdoB7Fj 5dt4ld8ybLR5uf24QmvsNg6Mc09j8nEXIXRLLpwafGGa8YZQNCRIAuAkv2z10f6FEtCP y+gzaR92fDbsFtfDo/ADjPbj5BxxFdGHuNWxgzAs/kilw6bAP3f4nqfj8y0cej+bA4CL 05/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769538798; x=1770143598; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yHX7748gxORjaCJqCbdbPxtHhuUnXJdKJ2s3V+FA30o=; b=r7beCI4V/0M/bJkoYbJDXxf2/iljJ083wlJ5O64A5Tq3jZv7bD/xDt85rw+CRh6YiB sIhP3KECWK7bg9aJ34lMHtHEe5UNGdjG+3q0LsQkbae1NLI5EdOislR8fp6/4Us1eS8X frVvnPKdi0+62ZF7ChPM29hFklQNT5a42pHXBFyXSCdSzjCuRJsD3CgVY/b8Q7lk891y RMgg0h47IVUS+te/om1lOVf19UXTeZoO2/11txk1BwAGFb3b6VHdc7AGrV7OSvFB3yYg KVxtzqz23VMEmw3Yz5vO6Vtq6e1E7FQVfm3Fnf/nsGad2lLApu1VIvePTAxDDsEUj7qW jeoQ== X-Forwarded-Encrypted: i=1; AJvYcCW5YOxaQshSkzQrvINW64bO0X3/ZmtC/Wf2gfcvDs7wtJfzhwyrmlVtkc2DKFYVRoJf9jJxAIi5FIwPxBE=@vger.kernel.org X-Gm-Message-State: AOJu0YxHcG2hDP8R0qzzFFhk612yPPHOFVtiPsjsVVXfIumj1kPXdVAk 5X4DR+rSQtT5xokclKixh2A/8852uZ/5FzpU/Us7HjBtHUIxEloNAxo2wmTRE91eXIY= X-Gm-Gg: AZuq6aK1+w40kV6dmNld6hv/7UiPMuJirQ2opsGHYRqnUuj9iQVLfE9WF5oQHh8FwA5 zqTVmJ1E4natT6WIBhe6j/kJAikixRVljfAUwUh9Y0G8yLzKdaGaDK4ZhZB7Grfbs9vPTR7Pkhu 4qxXpgrDn5K/BbLGHZGlGYBvMs0cicr3cH1Lfy74Ge5qNN6jupZUhcz7vHJp+yXHqL7JcTqUVJ3 AUl9vIcxn0J3z7RriLMr3E84/FbZY51k8YaIsos7fAFdzyGbb6U/Syenk8SZkbZ6kraBsS9ByPK sr79PvHMcwEPBebvrL9Ap9yV8FlmNb2z3kqk+z7kBF53KQl/famOfotDu4OA/GyU9VvWXDnvx+p cxtrGqKiqrZeLVjgq8n5bUqDuHNY9wmQbrbrwfxB3foftlygSLWo5NOv2XGPRwdh/39CDLpx8D2 uaTVippdRmNqIJ2G9VROzGz+kwzlQqwQkwP26NR3ovtFQ1KpycqFeckf5wjx3Ftw== X-Received: by 2002:a05:7022:4399:b0:119:e56b:989b with SMTP id a92af1059eb24-124a005d351mr1119117c88.2.1769538797713; Tue, 27 Jan 2026 10:33:17 -0800 (PST) Received: from m2max.corp.tfbnw.net ([2620:10d:c090:600::cedf]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-124a7bd05b1sm670139c88.3.2026.01.27.10.33.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jan 2026 10:33:16 -0800 (PST) From: Jens Axboe To: io-uring@vger.kernel.org Cc: brauner@kernel.org, cyphar@cyphar.com, jannh@google.com, kees@kernel.org, linux-kernel@vger.kernel.org, Jens Axboe Subject: [PATCH 2/7] io_uring/net: allow filtering on IORING_OP_SOCKET data Date: Tue, 27 Jan 2026 11:29:57 -0700 Message-ID: <20260127183311.86505-3-axboe@kernel.dk> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260127183311.86505-1-axboe@kernel.dk> References: <20260127183311.86505-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Example population method for the BPF based opcode filtering. This exposes the socket family, type, and protocol to a registered BPF filter. This in turn enables the filter to make decisions based on what was passed in to the IORING_OP_SOCKET request type. Signed-off-by: Jens Axboe --- include/uapi/linux/io_uring/bpf_filter.h | 7 +++++++ io_uring/bpf_filter.c | 11 +++++++++++ io_uring/net.c | 9 +++++++++ io_uring/net.h | 6 ++++++ 4 files changed, 33 insertions(+) diff --git a/include/uapi/linux/io_uring/bpf_filter.h b/include/uapi/linux/io_uring/bpf_filter.h index 2d4d0e5743e4..4dbc89bbbf10 100644 --- a/include/uapi/linux/io_uring/bpf_filter.h +++ b/include/uapi/linux/io_uring/bpf_filter.h @@ -16,6 +16,13 @@ struct io_uring_bpf_ctx { __u8 sqe_flags; __u8 pdu_size; /* size of aux data for filter */ __u8 pad[5]; + union { + struct { + __u32 family; + __u32 type; + __u32 protocol; + } socket; + }; }; enum { diff --git a/io_uring/bpf_filter.c b/io_uring/bpf_filter.c index 5207226d72ea..889fa915fa54 100644 --- a/io_uring/bpf_filter.c +++ b/io_uring/bpf_filter.c @@ -30,6 +30,17 @@ static void io_uring_populate_bpf_ctx(struct io_uring_bpf_ctx *bctx, /* clear residual, anything from pdu_size and below */ memset((void *) bctx + offsetof(struct io_uring_bpf_ctx, pdu_size), 0, sizeof(*bctx) - offsetof(struct io_uring_bpf_ctx, pdu_size)); + + /* + * Opcodes can provide a handler fo populating more data into bctx, + * for filters to use. + */ + switch (req->opcode) { + case IORING_OP_SOCKET: + bctx->pdu_size = sizeof(bctx->socket); + io_socket_bpf_populate(bctx, req); + break; + } } /* diff --git a/io_uring/net.c b/io_uring/net.c index 519ea055b761..4fcba36bd0bb 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -1699,6 +1699,15 @@ int io_accept(struct io_kiocb *req, unsigned int issue_flags) return IOU_COMPLETE; } +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.protocol = sock->protocol; +} + int io_socket_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { struct io_socket *sock = io_kiocb_to_cmd(req, struct io_socket); diff --git a/io_uring/net.h b/io_uring/net.h index 43e5ce5416b7..a862960a3bb9 100644 --- a/io_uring/net.h +++ b/io_uring/net.h @@ -3,6 +3,7 @@ #include #include #include +#include struct io_async_msghdr { #if defined(CONFIG_NET) @@ -44,6 +45,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); 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); @@ -64,4 +66,8 @@ void io_netmsg_cache_free(const void *entry); static inline void io_netmsg_cache_free(const void *entry) { } +static inline void io_socket_bpf_populate(struct io_uring_bpf_ctx *bctx, + struct io_kiocb *req) +{ +} #endif -- 2.51.0