Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1133096rwd; Thu, 25 May 2023 08:24:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5A1hxPwhAEexTvtp/QeB+pWT5q8ChZkxCvUhyhssUw90JGq9NfHPkZGoU9FUdDc20pMRPj X-Received: by 2002:a17:90a:bc8e:b0:255:4f4c:368 with SMTP id x14-20020a17090abc8e00b002554f4c0368mr1944112pjr.27.1685028267760; Thu, 25 May 2023 08:24:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685028267; cv=none; d=google.com; s=arc-20160816; b=WkY74DP/gs/Nqr913keUOF2EPUrkhHsrItErQ1s/eQFH76m9k7sHbuDqaeuZmOn5eS B9s2KnjAlc6448Rjuu3n5wupCttdN5Gi10pC3+PvOISDoIyp2v/2CEBDY3EWnlsafOuO dLbZdK+SbiaMOV45mzr4i0hBdjKBXVMwgBiAfi/wixpB8jQqLkUUksAmtPZq00om7j5r LQGySvCzg90ituu1U4QnIwi1jVwKj8tt4TzCCKQ+ni4q0B5idgmM26KaIczga7ZFUFvY AkFfidYnBbTdTMvPokCpibTe9k4G86MIYZkXH5cpWntLONkUBpIrvpM+7bjjyoB3Zd4t ZT7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=HA3qUCQl+kbC1FXFzRqNFiSIMfQf3R+uAszbM9bIdbk=; b=bWdRjPl4J5Y9SzqTME/2yl0PrxYcPliNq3DpfKzGEPPw+PL9iCTxyWUIq7zGeMxwkz YR90LBwWUPtyJ8P2naf2tnzzdIXSp5IFjd3MngWhn+2hGe4tv1dT9kJGUDm4cMEiXVUB I6SCpM8NpV2vsXRBjpnhF3lycP3fob12oi2dSJ940Nn5m1+sQGhDxh1opu1IxqnlU0/d uYJw3xTY6FZW2MJBRp8HTqMP9WZDSFFjxHVOlBFTpDn+9amfvKY8Tuoe1N0GbjBpMe2N Sa0yETr0m9IsRuGN+pn7lhcQH0oeucKsjsT5u7dYy7fLcohR4HUjeyso3SDKwljmbyQ+ ySJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZmZmCUKd; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u10-20020a17090abb0a00b002508889985fsi3636385pjr.95.2023.05.25.08.24.12; Thu, 25 May 2023 08:24:27 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZmZmCUKd; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241222AbjEYPDH (ORCPT + 99 others); Thu, 25 May 2023 11:03:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234964AbjEYPDG (ORCPT ); Thu, 25 May 2023 11:03:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 460D6189; Thu, 25 May 2023 08:03:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D8BB264679; Thu, 25 May 2023 15:03:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4465BC433D2; Thu, 25 May 2023 15:03:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685026984; bh=v5l1gvHWvPer9BfVYzVxNGNE0+xUGwapBdck9MVDveI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=ZmZmCUKd7mJfuzmwGQ60FzlZnwYhoLCVQrb5gzf30/fJ0TEV+3DxP/a86j64IoMXT CkFldmgrDgfgEda+EtNTp9E0bdHua+Vazuuhele39hrAuF39uH3mTwrFyeb9tRA8rG Bu5WIV7BrRPn+NUOkk5znwpflsqnivDbrBaycVYp79EUNflhOohqOEFjyolNUB4kng ZAk4fkm0CtB5EYVqu7KKenphkuqu4n0Py5TSkI9qfncI/6pP3EtzHknCY+YtlKqbjo 69E/md3sUuVp9GWPiqUFUeDbsYoouXQyhEe97FtNyPnqR8fURlxUDOaQnjxpbquGQW 03QUMxOYtWHbA== Message-ID: <83d90ef3-67ba-737e-02fb-dbfb7cc8d2de@kernel.org> Date: Thu, 25 May 2023 09:03:02 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH net-next v3] net: ioctl: Use kernel memory on protocol ioctl callbacks Content-Language: en-US To: Simon Horman , Eric Dumazet Cc: Breno Leitao , willemdebruijn.kernel@gmail.com, Remi Denis-Courmont , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Alexander Aring , Stefan Schmidt , Miquel Raynal , Matthieu Baerts , Mat Martineau , Marcelo Ricardo Leitner , Xin Long , leit@fb.com, axboe@kernel.dk, asml.silence@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, dccp@vger.kernel.org, linux-wpan@vger.kernel.org, mptcp@lists.linux.dev, linux-sctp@vger.kernel.org References: <20230525125503.400797-1-leitao@debian.org> From: David Ahern In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 On 5/25/23 8:54 AM, Simon Horman wrote: > On Thu, May 25, 2023 at 04:19:32PM +0200, Eric Dumazet wrote: >> On Thu, May 25, 2023 at 2:55 PM Breno Leitao wrote: >>> >>> Most of the ioctls to net protocols operates directly on userspace >>> argument (arg). Usually doing get_user()/put_user() directly in the >>> ioctl callback. This is not flexible, because it is hard to reuse these >>> functions without passing userspace buffers. >>> >>> Change the "struct proto" ioctls to avoid touching userspace memory and >>> operate on kernel buffers, i.e., all protocol's ioctl callbacks is >>> adapted to operate on a kernel memory other than on userspace (so, no >>> more {put,get}_user() and friends being called in the ioctl callback). >>> >> >> diff --git a/include/net/phonet/phonet.h b/include/net/phonet/phonet.h >>> index 862f1719b523..93705d99f862 100644 >>> --- a/include/net/phonet/phonet.h >>> +++ b/include/net/phonet/phonet.h >>> @@ -109,4 +109,23 @@ void phonet_sysctl_exit(void); >>> int isi_register(void); >>> void isi_unregister(void); >>> >>> +#ifdef CONFIG_PHONET >>> +int phonet_sk_ioctl(struct sock *sk, unsigned int cmd, void __user *arg); >>> + >>> +static inline bool phonet_is_sk(struct sock *sk) >>> +{ >>> + return sk->sk_family == PF_PHONET && sk->sk_protocol == PN_PROTO_PHONET; >>> +} >>> +#else >>> +static inline bool phonet_is_sk(struct sock *sk) >>> +{ >>> + return 0; >>> +} >>> + >>> +static inline int phonet_sk_ioctl(struct sock *sk, unsigned int cmd, void __user *arg) >>> +{ >>> + return 1; >>> +} >>> +#endif >>> + >>> >> >> PHONET can be built as a module, so I guess the compiler would >> complain if "CONFIG_PHONET=m" ??? > > Yes, indeed it does. > phonet_sk_ioctl is simple enough to make an inline in which case this should go in include//linux/phonet.h.