Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4729291rwb; Tue, 8 Aug 2023 12:54:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFmO6X/euKsI8d5w5p1+ZjvHCD0qYOl3yb5yPqWarat6dYEkTjYEjV/WsrW5roh4DZmgtFH X-Received: by 2002:a05:6a21:788a:b0:13f:d171:fd6d with SMTP id bf10-20020a056a21788a00b0013fd171fd6dmr639357pzc.51.1691524445769; Tue, 08 Aug 2023 12:54:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691524445; cv=none; d=google.com; s=arc-20160816; b=B0ej4qV19VmGJnu2V5rpCvZt85J4Zn8xZn+mGL5ZlkcIfNUVtRF3QnQTrBX9p9ZkwB YkEjeN3/gOAfHkS79RWokNl56K4X6nRSXNFrBUSaWwDe6GSd8d+tOTwhmB9m5n3tegcQ mhb+6Tb6w7F769RkhawjbV5jB0j4ee8RVhQa0SFFpzaaEscRfD77BQ4MqRehwxSE1RLq LtBQ5c2C9rNtXWsv+eKocyVfdPVp4l6Fwp862nugg8WofCEdwoD4Ctwjx3XEYO369OL3 NRGDdil9w1RhjmUzBTuwn87EQYCr73oLVVj3GwLHDtb0vvMIutnXYyVwvN0N2i6D7sEm 1BsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=D1FImuotzzVQ6nA+cw3aWKU2TeJBwRAYe/LnZXkkaFw=; fh=l1VDbM6J2p5aUkzf5Bk93PWv8dfwilEfhcujjbOTx18=; b=vdXfwYaqGLmw5O1pANIcuZz7cBq4/vy0BG82b3ZbYXT9sDLbu+Uw2BBXvTvO5UsBWw eo5IEmMi1/R4OGCGu0HYmhOilTXd1+DkSmb+IVPSSDUUc10Abj2I2qFBNenl7w216lhB vGwX9/+Z7DW3IxQoASGB3xJWNyRyrs3IQ9We0rh/eZsrMOl+lY0J1bsfMUbdFNevrhWl wyIuPIzYCyHauoQr2cmdifqJQqUssT44lnH3x74T+OMa/Wb0fINUfGU5sw4wR3dNdp3I r9QsNp/fOG/Nrl7Sy9pnZDnw2+1VXriKGfbnO5BaBGJwUfaFRTq9Gn5Bv+135f8ElbuE 019Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ju5-20020a170903428500b001bb94f4112dsi6444510plb.580.2023.08.08.12.53.52; Tue, 08 Aug 2023 12:54:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235729AbjHHTRl (ORCPT + 99 others); Tue, 8 Aug 2023 15:17:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233408AbjHHTQX (ORCPT ); Tue, 8 Aug 2023 15:16:23 -0400 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61302F839C; Tue, 8 Aug 2023 09:39:15 -0700 (PDT) Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-4fe48d0ab0fso9142016e87.1; Tue, 08 Aug 2023 09:39:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691512724; x=1692117524; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D1FImuotzzVQ6nA+cw3aWKU2TeJBwRAYe/LnZXkkaFw=; b=EkCA40kxooti6uJfoNlssQSr4NVwrGflalP+OqK6jMNA3ijjWS+eZs4M6eyBQVVYyI P3kHuvn9LiAnPomnRuO7ZHip+S52gzRIikunEID3OL7n7HeIdUT5PhF4xsmZ2oRinjvf hI9EDM5uZ10nKb5k70YeyEcWgKGdYOqMwJWqYWa6MPUnDk8e85F1A74l1R4jl6+I0Loj bsza1vqK10MbxmFz0x56knIi3keDR+l1SS98hIerkHxa27MgvqqWxnw8z51imILB3cOy e4hdzFvoGcN9QFehT/WvdSMqGVYKQckTSmdtAz7S91690wrq3TmUCCrrVAhqmGaDDRZW yOEA== X-Gm-Message-State: AOJu0Yxl9tj8oc6OXXvZgkWKC0MKrNfxqj53h9M+IjPt/ox4OyBb8DX/ LNnmSJHzDprRO/nUSjbjiN6TPpNHYjo= X-Received: by 2002:a2e:3307:0:b0:2b6:fe3c:c3c1 with SMTP id d7-20020a2e3307000000b002b6fe3cc3c1mr9358880ljc.4.1691502072628; Tue, 08 Aug 2023 06:41:12 -0700 (PDT) Received: from localhost (fwdproxy-cln-003.fbsv.net. [2a03:2880:31ff:3::face:b00c]) by smtp.gmail.com with ESMTPSA id s15-20020a170906284f00b00992e265495csm6650549ejc.212.2023.08.08.06.41.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 06:41:12 -0700 (PDT) From: Breno Leitao To: sdf@google.com, axboe@kernel.dk, asml.silence@gmail.com, willemdebruijn.kernel@gmail.com Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, io-uring@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com Subject: [PATCH v2 7/8] io_uring/cmd: BPF hook for getsockopt cmd Date: Tue, 8 Aug 2023 06:40:47 -0700 Message-Id: <20230808134049.1407498-8-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808134049.1407498-1-leitao@debian.org> References: <20230808134049.1407498-1-leitao@debian.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add BPF hooks support for getsockopts io_uring command. So, bpf cgroups programs can run when SOCKET_URING_OP_GETSOCKOPT command is called. This implementation follows a similar approach to what __sys_getsockopt() does, but, using USER_SOCKPTR() for optval instead of kernel pointer. Signed-off-by: Breno Leitao --- io_uring/uring_cmd.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c index dbba005a7290..3693e5779229 100644 --- a/io_uring/uring_cmd.c +++ b/io_uring/uring_cmd.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include #include @@ -179,17 +181,23 @@ static inline int io_uring_cmd_getsockopt(struct socket *sock, if (err) return err; - if (level == SOL_SOCKET) { + err = -EOPNOTSUPP; + if (level == SOL_SOCKET) err = sk_getsockopt(sock->sk, level, optname, USER_SOCKPTR(optval), KERNEL_SOCKPTR(&optlen)); - if (err) - return err; + if (!in_compat_syscall()) + err = BPF_CGROUP_RUN_PROG_GETSOCKOPT(sock->sk, level, + optname, + USER_SOCKPTR(optval), + KERNEL_SOCKPTR(&optlen), + optlen, err); + + if (!err) return optlen; - } - return -EOPNOTSUPP; + return err; } static inline int io_uring_cmd_setsockopt(struct socket *sock, -- 2.34.1