Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3154552rwd; Fri, 2 Jun 2023 23:15:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4o69gSshA+wUq8BcPvrXXbS2VTtc5Y9xA6Y05bWRDrrxnd+bl5Ez4dyGHxsl6twjv9kPpq X-Received: by 2002:a05:6871:ad81:b0:19f:5c37:ab9d with SMTP id zn1-20020a056871ad8100b0019f5c37ab9dmr6520311oab.43.1685772935311; Fri, 02 Jun 2023 23:15:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685772935; cv=none; d=google.com; s=arc-20160816; b=tJQm3Lb06T5PWPTBeVcpBZm1W5Fj7+KIg17FmKjtGzLdFsoCR56ha33ko1WwApAStE D5wXKP4SiOtcl9dHK+xyYbTF/2H/E4Gvuv3QveHogrvlTJQVrRawtKk0O0i+TU2qAejB wNybUfVrB43n0212vxbvuXyjGRhpH0nEuSdS8CYEJn71JGKjD9w/acLMZK6K3UmQl9y8 8sRE+BM2TWwvRGGbEI7SOWdOi5v6yd1ggw+oBWU7HvJ1WrlkVR3sqLcTyynIl5VtR/Sz r5p/0UiIAgKl3dDZjIVQQoYUuhQDpXsARxGw+sJL2vxTbN7ah6VgcqkcaZreCCJgEfeH qHIQ== 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:subject:cc:to:from:date :dkim-signature; bh=LzmXOs203fO1/Jd3p4ek97lqhyRx5HboLXsQmJr+Zz0=; b=XAJSpJ80N0MFfqQ2oX/BnYK2M3pYPq7ayKu5BpW42bhhed3TQi+0ka4g9Zvq0UwGc5 5vE1/iNwf9eb67wZYyWTFytt1vBBorTaIaNOXEleMQj2PrH2QhRRYnwGKxebmYdpJ4f7 2m9UdFXXOH8DMujiKKrFefccE7StRwaF1Ti3ePvuaJZ5zZGUtCeInE8l64/XQTQIWgrb g+AQFc9KQXRjn+fZBDGDIGQe7D9WVUlXPayrEG7gXQ9lQfcu3djZlQNUQnXxsdFwPKGY wO/Xh8s6tmQaX912W/SVpni2FebAvm9NsafQtCutr6BwiKlr0kM6xDgPNqUWf7U7kkVB Tq/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eXbV5kUQ; 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 z125-20020a633383000000b0053b8c700f19si2190450pgz.529.2023.06.02.23.15.18; Fri, 02 Jun 2023 23:15:35 -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=eXbV5kUQ; 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 S231432AbjFCFzZ (ORCPT + 99 others); Sat, 3 Jun 2023 01:55:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbjFCFzW (ORCPT ); Sat, 3 Jun 2023 01:55:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5615CE55 for ; Fri, 2 Jun 2023 22:55:21 -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 DB30D60B3B for ; Sat, 3 Jun 2023 05:55:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD340C433D2; Sat, 3 Jun 2023 05:55:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685771720; bh=BY2PwvlTytRqfRCUBmDd8GS5hKDMoCaWTKd22a+Jz7g=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=eXbV5kUQyk/ndeeFuEAYQ2mjH9VqVcghvb6SRK5JEmWREgCJDta+zkb5TacF0BMFE 7NTX2djcBKIWj+mqddnlnqz+tU9/yhD6KfmISw/hOc4QQgPsOj1K2et9boIjWcjPNg 50dsOkWKHz2rhXKzfbAZZqD2KJGHrYuRw0bt+rU/ii09eBKHNz6IZXPj7GNJtqAv38 KQAboIaP2DUgxIwu6h4bqIrt9wF8grcXzWqZppwe5tj9PcKaejywkknT2SGwNaJY3b 6pHloOodNZu98yQm3BAcklIyzGOTYWjBeGDVoFRH8Lq1sB9jB7rXSMs1awpFSGEXBi FpOEFSrV1beKw== Date: Fri, 2 Jun 2023 22:55:19 -0700 From: Jakub Kicinski To: Ding Hui Cc: Alexander Duyck , Andrew Lunn , davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, pengdonglin@sangfor.com.cn, huangcun@sangfor.com.cn Subject: Re: [PATCH net-next] net: ethtool: Fix out-of-bounds copy to user Message-ID: <20230602225519.66c2c987@kernel.org> In-Reply-To: <44905acd-3ac4-cfe5-5e91-d182c1959407@sangfor.com.cn> References: <20230601112839.13799-1-dinghui@sangfor.com.cn> <135a45b2c388fbaf9db4620cb01b95230709b9ac.camel@gmail.com> <6110cf9f-c10e-4b9b-934d-8d202b7f5794@lunn.ch> <6e28cea9-d615-449d-9c68-aa155efc8444@lunn.ch> <44905acd-3ac4-cfe5-5e91-d182c1959407@sangfor.com.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 Sat, 3 Jun 2023 09:51:34 +0800 Ding Hui wrote: > > If that is the case maybe it would just make more sense to just return > > an error if we are at risk of overrunning the userspace allocated > > buffer. > > In that case, I can modify to return an error, however, I think the > ENOSPC or EFBIG mentioned in a previous email may not be suitable, > maybe like others length/size checking return EINVAL. > > Another thing I wondered is that should I update the current length > back to user if user buffer is not enough, assuming we update the new > length with error returned, the userspace can use it to reallocate > buffer if he wants to, which can avoid re-call previous ioctl to get > the new length. This entire thread presupposes that user provides the length of the buffer. I don't see that in the code. Take ethtool_get_stats() as an example, you assume that stats.n_stats is set correctly, but it's not enforced today. Some app somewhere may pass in zeroed out stats and work just fine.