Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2570063rwd; Fri, 19 May 2023 07:27:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6QLoU1B0I4N568R3VmEN4o3tyJGowP61pk98c2QN2EcrW+NQyzNpkFUr8UI8kzvq5Itwwk X-Received: by 2002:a05:6a00:1783:b0:645:ac97:5295 with SMTP id s3-20020a056a00178300b00645ac975295mr3157669pfg.9.1684506446608; Fri, 19 May 2023 07:27:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684506446; cv=none; d=google.com; s=arc-20160816; b=v1N8upt7Z103xFwGG7eGnIZ+Uu53uTpi/Xw9RVxoAMJUiodWleOLSXSpVjiR8ZdOlW 1FZg0NWaz+5TkpFoox6a7hOGvQgv1MTqw60mR4INswX8kWMXHkiY23qhFAqtljKBcof9 nixOcZ/mV4fVwrb18AgUV0SQWHTynOdv9Wkwjt58FURSJpXgR4hGzXni/MREQQqLSNRe mu15uSAvlpy4ZSw4iW4EgNGrJd/DvacZ1pyxRIilRY3Zy4Mq/IPUD7cyVBkVDK/9PGx0 EkDQiIPdR+JHGKstHlOsv9WDDixU/K0N5XGi8aYSuUqg1YC7kqo7eUQmKLKmfgCzpavz X39A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=r7ULh3M0H8qIVsGAtuoIazs7qN+QHKisX7Lo9F9iZXA=; b=V6hCPpyYrvjZicRRp18QQlBtYzAfSxoCGeSmIBYVd7UmcW5wyqMCOoR7fOkF0NF1Bj H3GjKwQ0Lk1UTxXDAdUcixhL2qRX3GEt868JRf+6YOrKfjeRemvik1uNfooEyh98KqBm G15qq+pGYUsR9jjiPLsJnpsXx0Iuynj+yf/eCdXr+nAJGD6ORlT193xUKpzsD7yKPa0D dpHE0ehrdf+QxhFRXKWwXp2fQI2sAdK4qunJ0Y3xuk8kGMsdZvIcoBdEqwCdrCD4nHcf yqWlS3E3XXC6TJBE+b5NDkm1+xiNbxeKkwsakwFij5DinSHe9by5SqKu1FEVcUcRzqjs X3Gw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q3-20020aa79603000000b00635ebd8854esi4112986pfg.173.2023.05.19.07.27.11; Fri, 19 May 2023 07:27:26 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230513AbjESOWb convert rfc822-to-8bit (ORCPT + 99 others); Fri, 19 May 2023 10:22:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229524AbjESOW2 (ORCPT ); Fri, 19 May 2023 10:22:28 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C0A3E49 for ; Fri, 19 May 2023 07:22:24 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-182-eNKQvqjvOHWCSGmOHW-ZdA-1; Fri, 19 May 2023 15:22:11 +0100 X-MC-Unique: eNKQvqjvOHWCSGmOHW-ZdA-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 19 May 2023 15:22:08 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Fri, 19 May 2023 15:22:08 +0100 From: David Laight To: 'Breno Leitao' , "axboe@kernel.dk" , "davem@davemloft.net" , "edumazet@google.com" , "kuba@kernel.org" , "pabeni@redhat.com" , "willemdebruijn.kernel@gmail.com" , "courmisch@gmail.com" , "nhorman@tuxdriver.com" CC: "asml.silence@gmail.com" , "alex.aring@gmail.com" , "dccp@vger.kernel.org" , "mptcp@lists.linux.dev" , "linux-kernel@vger.kernel.org" , "matthieu.baerts@tessares.net" , "marcelo.leitner@gmail.com" , "linux-wpan@vger.kernel.org" , "linux-sctp@vger.kernel.org" , "leit@fb.com" , "dsahern@kernel.org" Subject: RE: [PATCH 1/1] net: ioctl: Use kernel memory on protocol ioctl callbacks Thread-Topic: [PATCH 1/1] net: ioctl: Use kernel memory on protocol ioctl callbacks Thread-Index: AQHZiloXkjARdT8YlUi1kSrEdFLkt69ho1RA Date: Fri, 19 May 2023 14:22:08 +0000 Message-ID: References: <20230519135821.922326-1-leitao@debian.org> <20230519135821.922326-2-leitao@debian.org> In-Reply-To: <20230519135821.922326-2-leitao@debian.org> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, 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 From: Breno Leitao > Sent: 19 May 2023 14:58 > > 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). > > This changes the "struct proto" ioctl format in the following way: > > int (*ioctl)(struct sock *sk, int cmd, > - unsigned long arg); > + int *karg); I think I'd add a karg_len field for the actual buffer length. It will save embarrassment later on. Do any of the ioctl functions return +ve values on success? If not you can use the return value as the length for any copy_to_user(). If all the current 'cmd' are 16bit, there is the option of using 32bit IOR() etc commands to get automatic sizing. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)