From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Miller Subject: Re: [PATCH net-next] net: remove redundant input checks in SIOCSIFTXQLEN case of dev_ifsioc Date: Mon, 23 Jul 2018 14:00:25 -0700 (PDT) Message-ID: <20180723.140025.949946162106654052.davem@davemloft.net> References: Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: tariqt@mellanox.com, netdev@vger.kernel.org, eranbe@mellanox.com To: xiyou.wangcong@gmail.com Return-path: Received: from shards.monkeyblade.net ([23.128.96.9]:48710 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388139AbeGWWD3 (ORCPT ); Mon, 23 Jul 2018 18:03:29 -0400 In-Reply-To: Sender: netdev-owner@vger.kernel.org List-ID: From: Cong Wang Date: Mon, 23 Jul 2018 13:37:22 -0700 > On Sun, Jul 22, 2018 at 12:29 AM Tariq Toukan wrote: >> >> >> >> On 19/07/2018 8:21 PM, Cong Wang wrote: >> > On Thu, Jul 19, 2018 at 7:50 AM Tariq Toukan wrote: >> >> --- a/net/core/dev_ioctl.c >> >> +++ b/net/core/dev_ioctl.c >> >> @@ -282,14 +282,7 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd) >> >> return dev_mc_del_global(dev, ifr->ifr_hwaddr.sa_data); >> >> >> >> case SIOCSIFTXQLEN: >> >> - if (ifr->ifr_qlen < 0) >> >> - return -EINVAL; >> > >> > Are you sure we can remove this if check too? >> > >> > The other one is safe to remove. >> > >> >> Hmm, let's see: >> dev_change_tx_queue_len gets unsigned long new_len, any negative value >> passed is interpreted as a very large number, then we test: >> if (new_len != (unsigned int)new_len) >> >> This test returns true if range of unsigned long is larger than range of >> unsigned int. AFAIK these ranges are Arch dependent and there is no >> guarantee this holds. > > I am not sure either, you probably have to give it a test. > And at least, explain it in changelog if you still want to remove it. On 64-bit we will fail with -ERANGE. The 32-bit int ifr_qlen will be sign extended to 64-bits when it is passed into dev_change_tx_queue_len(). And then for negative values this test triggers: if (new_len != (unsigned int)new_len) return -ERANGE; because: if (0xffffffffWHATEVER != 0x00000000WHATEVER) On 32-bit the signed value will be accepted, changing behavior. I think, therefore, that the < 0 check should be retained. Thank you.