Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp939106rdb; Sun, 20 Aug 2023 09:23:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEcfjBaizOWnDPnsp1f2J6E+AOqwNwWflyAZLJO+T4/V0DlSiDTSS6TpAly1JN+EYzsLrI6 X-Received: by 2002:a05:6a00:b4e:b0:688:94da:8aa8 with SMTP id p14-20020a056a000b4e00b0068894da8aa8mr3578508pfo.13.1692548638637; Sun, 20 Aug 2023 09:23:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692548638; cv=none; d=google.com; s=arc-20160816; b=N7PKcs5BtL5ph+Lxt3xYpR6R96oqUPOLswurSA01ZXkt9lUD+nTy8FUYCC8fT+aBSy TQyRkhn6WouABiq0nPSYG5gnHBoV1eDUd62irfqAM8/WgFxUZZAVPtRiXcKyN4QQmc8Z mUQlSXaZez1YAYnB6FOblqiH6zZO6D4nqsaIw6xjcLKGEo+X2F+5MoqzyrV571xGhkj3 WRsYh7UF8CB+QmtShNVozrJx7OkDn6GYQHe69YZUqII+/pUHuLpxLuqr3VbWc99yPmeA Fzz8OF/6Q0R4CwUirkkQvX+Ing/1N5/pH1tPpwlJZs9FiaTGba+OSMO7rmfpkAk+ZVTf MNQQ== 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=07ENq1IVrS75f2tHkaWZQfDYx4uyK/eennegrV/Q9BY=; fh=iPIk/eFzIqDGk5xAc4HZnzsVgTF2WBhoOqU83CIHXtw=; b=ftxaNvPhlU5k3I0bbp7Lewwz3e20Pnu7Et6+JiNdWUnifWa9gmJQePFwrRKCPZVzf+ anSHOZL2Bd+PRxLa0tRiJpGQcphKxcFjhh3HhkGH1qahsD1war5MxXh6wdbwqvi+owTQ NXjLNd0YaCK7rsi8OeY9IpJoJvPBGDJ+ETzbKdT6PrVw+KZ7LZlCkD9LdNuXd8/x4lax hsIMAG1Pr66DEoAecwEOxA9lPoZ1t+UCEF4tabwmKWCq9BbC6XZe7lenIp9uK0HKArXt soQH9lTkeCS7ByEZMInTTMSffrpPSLlDWwwhHjLUwwNrcv2/3vtKgiDkW3f2frkxygRY dNww== 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:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c4-20020a056a00248400b0068716de807bsi5801314pfv.241.2023.08.20.09.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 09:23:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9E464318E56; Sat, 19 Aug 2023 11:58:30 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352447AbjHQO5E (ORCPT + 99 others); Thu, 17 Aug 2023 10:57:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352435AbjHQO4g (ORCPT ); Thu, 17 Aug 2023 10:56:36 -0400 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C332F30DE; Thu, 17 Aug 2023 07:56:13 -0700 (PDT) Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-9923833737eso1035599966b.3; Thu, 17 Aug 2023 07:56:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692284172; x=1692888972; 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=07ENq1IVrS75f2tHkaWZQfDYx4uyK/eennegrV/Q9BY=; b=eUElgFImSn2iZBFv9ALM7bP5yoUrNa6bB88hZ0GlXZjbuq51DRTXL2D1m+yhpd1vzI 8NDjwECRXcnxDQtYnUKd9BLQtzNPjWsQ2kI6W7OG7hwB+P75vwICN3s4bAKqFp3VHxM4 cVg4T/cibCGHCzdiq9x6nSO6aMEfpiE4ZiZlys/BtQkb9pYolebI5FSvqA9HL5C1UFeZ 9BENy2pAqp/rfP3JQCuJJF64nhrO+tsu7xUFbcxFxPJA69M7irvm0JoIrTBWnLE7KDZJ QIaTsDSkfkvgC9mSSc1vnI7J2z5GYo8YtEk76+rpkwsPP+iA2qUgY5dqyoj4oy3XOo45 oGoQ== X-Gm-Message-State: AOJu0YzPnqecP8IqrS+HeiSPsXAD4E8Gx+kWxv5xCuY+WCJBX1IGhDrf DsOcs0vZNBqG9nqDAFQYd4o= X-Received: by 2002:a17:906:d18c:b0:98d:4000:1bf9 with SMTP id c12-20020a170906d18c00b0098d40001bf9mr4253849ejz.65.1692284171876; Thu, 17 Aug 2023 07:56:11 -0700 (PDT) Received: from localhost (fwdproxy-cln-000.fbsv.net. [2a03:2880:31ff::face:b00c]) by smtp.gmail.com with ESMTPSA id qx27-20020a170906fcdb00b0098e0a937a6asm10222970ejb.69.2023.08.17.07.56.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 07:56:11 -0700 (PDT) From: Breno Leitao To: sdf@google.com, axboe@kernel.dk, asml.silence@gmail.com, willemdebruijn.kernel@gmail.com, martin.lau@linux.dev, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, io-uring@vger.kernel.org, krisman@suse.de Subject: [PATCH v3 3/9] net/socket: Break down __sys_setsockopt Date: Thu, 17 Aug 2023 07:55:48 -0700 Message-Id: <20230817145554.892543-4-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230817145554.892543-1-leitao@debian.org> References: <20230817145554.892543-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_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, 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 Split __sys_setsockopt() into two functions by removing the core logic into a sub-function (do_sock_setsockopt()). This will avoid code duplication when doing the same operation in other callers, for instance. do_sock_setsockopt() will be called by io_uring setsockopt() command operation in the following patch. Signed-off-by: Breno Leitao --- include/net/sock.h | 2 ++ net/socket.c | 39 +++++++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index 2eb916d1ff64..2a0324275347 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1853,6 +1853,8 @@ int sk_setsockopt(struct sock *sk, int level, int optname, sockptr_t optval, unsigned int optlen); int sock_setsockopt(struct socket *sock, int level, int op, sockptr_t optval, unsigned int optlen); +int do_sock_setsockopt(struct socket *sock, bool compat, int level, + int optname, sockptr_t optval, int optlen); int sk_getsockopt(struct sock *sk, int level, int optname, sockptr_t optval, sockptr_t optlen); diff --git a/net/socket.c b/net/socket.c index 2c3ef8862b4f..b5e4398a6b4d 100644 --- a/net/socket.c +++ b/net/socket.c @@ -2221,30 +2221,20 @@ static bool sock_use_custom_sol_socket(const struct socket *sock) return test_bit(SOCK_CUSTOM_SOCKOPT, &sock->flags); } -/* - * Set a socket option. Because we don't know the option lengths we have - * to pass the user mode parameter for the protocols to sort out. - */ -int __sys_setsockopt(int fd, int level, int optname, char __user *user_optval, - int optlen) +int do_sock_setsockopt(struct socket *sock, bool compat, int level, + int optname, sockptr_t optval, int optlen) { - sockptr_t optval = USER_SOCKPTR(user_optval); char *kernel_optval = NULL; - int err, fput_needed; - struct socket *sock; + int err; if (optlen < 0) return -EINVAL; - sock = sockfd_lookup_light(fd, &err, &fput_needed); - if (!sock) - return err; - err = security_socket_setsockopt(sock, level, optname); if (err) goto out_put; - if (!in_compat_syscall()) + if (!compat) err = BPF_CGROUP_RUN_PROG_SETSOCKOPT(sock->sk, &level, &optname, optval, &optlen, &kernel_optval); @@ -2266,6 +2256,27 @@ int __sys_setsockopt(int fd, int level, int optname, char __user *user_optval, optlen); kfree(kernel_optval); out_put: + return err; +} +EXPORT_SYMBOL(do_sock_setsockopt); + +/* Set a socket option. Because we don't know the option lengths we have + * to pass the user mode parameter for the protocols to sort out. + */ +int __sys_setsockopt(int fd, int level, int optname, char __user *user_optval, + int optlen) +{ + sockptr_t optval = USER_SOCKPTR(user_optval); + bool compat = in_compat_syscall(); + int err, fput_needed; + struct socket *sock; + + sock = sockfd_lookup_light(fd, &err, &fput_needed); + if (!sock) + return err; + + err = do_sock_setsockopt(sock, compat, level, optname, optval, optlen); + fput_light(sock->file, fput_needed); return err; } -- 2.34.1