From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) (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 B17B3197A7D for ; Mon, 19 Jan 2026 23:55:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768866904; cv=none; b=m1Gh7fTIetJ1dk+s48SxUPCyE7j/ifElFk6DoKpyFnhCy6jIGJHjF5LrzxlrcK6rQBQDdvawiDsDf+XMm9LSJDkuLr63vKI2d96Pnvi2p5A9Tju5uiSSRrh9lXchtDQTXs3n5d/OUcQ+5aVzdvqdFs2clDRYGkhydOGRl22HOHw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768866904; c=relaxed/simple; bh=C9C+IU1pA+5Fb3cPH0ew3W1/JrGbtTU07hYMcQtLXSM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OncI8ATGxJUt+yTHNzMnYHX6/CuFuc4XQMXchy/+t4F/7Kh54jcppcNcxhFTNvDYvGnFsySLpk+qPLq46Gd1nSFixDVFMKV3EliTQ4MJbUN4bqHEohtGkFpksm0ngU2/FaShcqBcTo5UKTOnGJX8/g2KeII9hNiMQKioxGzj6ps= 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=Mhy6hlra; arc=none smtp.client-ip=209.85.210.42 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="Mhy6hlra" Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-7cfd5d34817so3205125a34.1 for ; Mon, 19 Jan 2026 15:55:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1768866901; x=1769471701; 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=2gUWeWDz/48yCjzxnphLYuWL+CABKXH9qFjCUViavDY=; b=Mhy6hlraW9cYJnejpzsav4WDFjcUEv1CnUh4lLcor94hJRiZBvuJjcOMUuGtDKwAa9 fJBjsF+6LafLwer8zY+vvi1wpKgieoFbNYB8ivx+XNVpzLKA/UqofnjvxMN/9x6wKW55 3zWcMNTF4vUZHrihyWs1eHgvvYq50UqalGSHYkYuGUFGEqk+HIvs2A1I7T1p/RpUwoi6 79KtZpLBDU0Gjv2rLJcraVO6BBkTLm9GJtkTfaptTVAsbIi+xkPvNqlFUcHlEN2pTqZM g/4bL1zpk/46NNGjdRnWGxnpFIn2VWnlhosXsW6CBXy/el0elKJjZ22wk2pP9eXZhuTM lG+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768866901; x=1769471701; 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=2gUWeWDz/48yCjzxnphLYuWL+CABKXH9qFjCUViavDY=; b=mcjyeCkZucCd6+q75temAatb7avVQrditKAGwkwydAszJ3W23PcR2GXZ99LjTpQWKY AlFkmGqWtgtNtGVxFHOtURm8v2s5aCoVBfBP5CGoPzOz4Qc0ZWLj62vVBM1dIZcJE4yv KaEH/OctgpiEy0McRtORM92ajzqn5NdqilhmT2e4no7KGEYO56LxuZPuybXoeJj0D/PH wBI4XEMTMUnhu0NKRD/nn8Jac8lRV13rj8zZevS578w8oZij4oDABH776SFTwGBqBFu1 dJhLgypgnhJYfMZHpn98DTDtb/WS+DY6ohLdKDjqvkaSHBp7ziVUVr/Q3xFms5LWxEHJ oSqg== X-Forwarded-Encrypted: i=1; AJvYcCXGIqGS7RfwZLTQHVZ2PEXSbhHmZYC7RupZZyyenu9VmtUKk+bis1ZFkUPEBWAec6Cr78ytdhxAg9eV3X0=@vger.kernel.org X-Gm-Message-State: AOJu0YwCrjkZmGLt7+n5g9qSurR0byMs5tiX0KupDIMWPhXYwcpCgIJB EmIB9/wMK934QqbsVEYNqHM9WzKATc2pqMA90sILiCHBut5xQAihUBm7msfpnyU1/f4= X-Gm-Gg: AY/fxX5FPirrs+gbmLU0lC4GONf4gPR8DB7y6025b9FEWNlq75Tkr0ihJeMHS5hlCGH kHcndVRXZ8jLWmfnGNkSBNpd67eIEMAav4be/JR98I8oKQd8Z4I3ATO4h7sEW8mzzEmrtPbWPT1 KlvSOr0CWFcfQgba8pCd0t3R+5Ka07Y41L/V9OGZds12pcreTzshpOPzOvJ8PJ0mZLUKDiJ+NGQ vmSIRWVCz2b4b5bEiv1fSnhWrjAdgwH4qqUiKXtAc16BPA6wQHpeVEBHq/VtlkhWX58xt83x7rK zzKJz6O+TvctAKYmy7dp5so1wJT6m43BaVayOPjuOPU6KL4ZnctGABGgpj6Ts/IlalOwBixqlak v2LWiiZoxK13nSOIzFNCPgN3em9Ak2jEG2AkkyadvS6MYaylQ0mHe29qVvbsaVwbR1fhCbI2HAO 4z01FspVoYvQnC4NglpOfc97Ab9lly7aOtK+oGJLUH5rLfc/ATAAo9JF2c X-Received: by 2002:a05:6830:2409:b0:7ca:f5d9:f767 with SMTP id 46e09a7af769-7cfe01ceb64mr6657513a34.34.1768866901627; Mon, 19 Jan 2026 15:55:01 -0800 (PST) Received: from m2max ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7cfdf2a5f02sm7509997a34.25.2026.01.19.15.55.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jan 2026 15:55:00 -0800 (PST) From: Jens Axboe To: io-uring@vger.kernel.org Cc: brauner@kernel.org, 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: Mon, 19 Jan 2026 16:54:25 -0700 Message-ID: <20260119235456.1722452-3-axboe@kernel.dk> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260119235456.1722452-1-axboe@kernel.dk> References: <20260119235456.1722452-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 | 9 ++++++++- io_uring/bpf_filter.c | 10 ++++++++++ io_uring/net.c | 9 +++++++++ io_uring/net.h | 6 ++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/io_uring/bpf_filter.h b/include/uapi/linux/io_uring/bpf_filter.h index 8334a40e0f06..ad6961be5efa 100644 --- a/include/uapi/linux/io_uring/bpf_filter.h +++ b/include/uapi/linux/io_uring/bpf_filter.h @@ -15,7 +15,14 @@ struct io_uring_bpf_ctx { __u8 opcode; __u8 sqe_flags; __u8 pad[6]; - __u64 resv[6]; + union { + __u64 resv[6]; + struct { + __u32 family; + __u32 type; + __u32 protocol; + } socket; + }; }; enum { diff --git a/io_uring/bpf_filter.c b/io_uring/bpf_filter.c index 08ca30545228..8934c0586842 100644 --- a/io_uring/bpf_filter.c +++ b/io_uring/bpf_filter.c @@ -29,6 +29,16 @@ static void io_uring_populate_bpf_ctx(struct io_uring_bpf_ctx *bctx, bctx->user_data = req->cqe.user_data; /* clear residual */ memset(bctx->pad, 0, sizeof(bctx->pad) + sizeof(bctx->resv)); + + /* + * Opcodes can provide a handler fo populating more data into bctx, + * for filters to use. + */ + switch (req->opcode) { + case IORING_OP_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