Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1086358rwd; Thu, 25 May 2023 07:54:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ751/KWvZhteMtq1FhUKK8vnuDGftjJLD+NYV9M2QaiJEDZeWmafsAiQ30DvOJqXhhPgaDo X-Received: by 2002:a17:903:2287:b0:1a3:cd4c:8d08 with SMTP id b7-20020a170903228700b001a3cd4c8d08mr2121871plh.38.1685026447845; Thu, 25 May 2023 07:54:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685026447; cv=none; d=google.com; s=arc-20160816; b=OEnY2gzlnYZz9Qr5l/t9oJQ/P0ODAfYLff2HYfDOWaCL7hZ9caBIY8YpfQlDNHdWKd AiRsTR6Vhev6mcL5zM98+uk9cU/RtbNICLiCJb2AjrN6200BNZorsTCOHNhinsRmn2U4 5zQbcr5rH5h9uFgCGmKOrwtLDzwwm8GK6r1wAyvRiD5bpore82WU8S3Tiy7QPGPt8xRl lXZncvGZORa1ew3FYrAdC7P3lXVGKGIxzzMY5Uhigzn7R4h79P76Ga8jyuMBzjuZ7Iv/ BvEqAuWb+QpzYPBIWsDllvdbqD85ooNpSw5PYbRpSAMyAagL8Nkg3ZP76NIc8+AqNlJx FdPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=xY3OLocOSEgHA4fLQ6+Y82/v18zp3KYq0EzJK7Sx6w4=; b=OCW6IpFjw7Y4mgp7hIrPKjt9JbAzYSFvGTIHgCI66E8fMq/rmw+PzrEvdm6GcF1K3Y cBs7e6JYhLUl0X6fJOGR5DwAps1YeWDgzIGcAwfpnYZaMOel2V7OUCjIv2vVjwwSdzgB 84JgjzWgNk1nTjRpM9/5RSEmGx1cCnfyPK3JbF0mcxtQ9BifZa10LFlEbt6jJllVcyKx +Js+F4hPy0+RGNn7Z75A1XD5p3OjDFeIZT7n3QFMr0MYYw04cTt02npfE6rhogtdBC6w Jpdp0QAu6tlASIgPSdwO479pzrWuu6kYaSdxvDniRWE2LDauiGcr5cOyxsePw5awllyP S82g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=wHkJLBUP; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x5-20020a1709028ec500b001a6ee332903si1487000plo.347.2023.05.25.07.53.52; Thu, 25 May 2023 07:54:07 -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=@google.com header.s=20221208 header.b=wHkJLBUP; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241602AbjEYOTt (ORCPT + 99 others); Thu, 25 May 2023 10:19:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241346AbjEYOTs (ORCPT ); Thu, 25 May 2023 10:19:48 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E19A19A for ; Thu, 25 May 2023 07:19:46 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3f606e111d3so59595e9.1 for ; Thu, 25 May 2023 07:19:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685024385; x=1687616385; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=xY3OLocOSEgHA4fLQ6+Y82/v18zp3KYq0EzJK7Sx6w4=; b=wHkJLBUPHnTjbEYVjNmSFBfrwTo4TZCcKmMspyHDJqkEgtEn/NrM7MabqcVul3Nqno Tj3bI4zoJ6l4Hg9bQmHhQQbBhAlRKcDm8amOqdotCQ9oFlP/+FfObQ0hng3dnX7Q/MZN zgGYdbCaPMvQmlkltsmx7FD2VjtKEhvmJCJlXmwvBZuW6dSptjbG7SRNG1Fm7qQKN4yC liMx8NahKkYKHcLA5WQznaj+nl+rQ5jq8bHdUqe+SiABS/vuvAbc4CowJ81V9pztluPl E5+xBeURqDYhzDTgK1vcmxkBvMDxMcF/cgTRWGzjM42BHCjiZvvDd2GvPhq5Nbgt/3q2 /3lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685024385; x=1687616385; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xY3OLocOSEgHA4fLQ6+Y82/v18zp3KYq0EzJK7Sx6w4=; b=KNCI+UBUXeMoMoW2ai35zMdoAyaThow/PqFgawWvz/w1KR46+lDJU52PoYvmv8aNt6 cbYwwLfRyKaDUQA+Yva+nPUjCJZMlea5IM9XAxRgbo3B+X3zaZwfLls4DmXj6HYzkwIX UHVjC2f00mj6jceGWI0BpjM3iTIbismCogAMJLTPd4glOSM26T1uzYHtOhYEATin2A3W vlDA2jgaOo/I8BT/6brz63L3W8nOTF6HTGRqlf+qQOwW+mMibjJiIZG8RbuzGW1HVk6r FVCTdmagctc9FI2V9Z0AjACcWzQ/X5lLPKx6+nX6P7UrNoU8cfxUSJE54iWrQoqww3Nm DvBg== X-Gm-Message-State: AC+VfDxXVCK2qeZJoUwEyG/iNvghq8xPNhCGb10InLs8HRHfiQjce6Bc M6QRbVnyfwv3tPwKT/G2ucXNSRJ+KwJSFA0++GXOQg== X-Received: by 2002:a05:600c:a0e:b0:3f1:9a3d:4f7f with SMTP id z14-20020a05600c0a0e00b003f19a3d4f7fmr147224wmp.1.1685024384734; Thu, 25 May 2023 07:19:44 -0700 (PDT) MIME-Version: 1.0 References: <20230525125503.400797-1-leitao@debian.org> In-Reply-To: <20230525125503.400797-1-leitao@debian.org> From: Eric Dumazet Date: Thu, 25 May 2023 16:19:32 +0200 Message-ID: Subject: Re: [PATCH net-next v3] net: ioctl: Use kernel memory on protocol ioctl callbacks To: Breno Leitao Cc: dsahern@kernel.org, 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Thu, May 25, 2023 at 2:55=E2=80=AFPM Breno Leitao wr= ote: > > 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 =3D=3D PF_PHONET && sk->sk_protocol =3D=3D P= N_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, voi= d __user *arg) > +{ > + return 1; > +} > +#endif > + > PHONET can be built as a module, so I guess the compiler would complain if "CONFIG_PHONET=3Dm" ???