Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp591956yba; Sun, 31 Mar 2019 07:34:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqyu4XM4/TfcCdjdLZXQn91PLBY4ZfVIbse4XtTpF4cP0oh0DCmC3vyWQ+6iTBWs0VnryTwf X-Received: by 2002:a65:49c4:: with SMTP id t4mr56512402pgs.421.1554042857773; Sun, 31 Mar 2019 07:34:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554042857; cv=none; d=google.com; s=arc-20160816; b=aumqpFv69phTby5IZAXucpFjIOAUstsng0NtqPsHOJxqbCOwpiUKdfVkSgbIrqoGDN opmXtM0HeKtafUU1dPMXKHA2nZCq//fIiArE8qJ52mRmBzJLdXcNuLMGf/9rxJBewmfJ 7PS8sr+H3UvvxjfT24HhJJYI2RJo8AVQrsDEJGJxirt/7KIS0B6Re5quZ0UoKWx+hl6/ 4MF8ZgK4sxxec5RITi/SZNfYXb30xAp1Z7QhSWPcAuuiXg/r5A+mgSrBn2wiSY1LaX0c QxvVABWBx01uD8CRP7Acyf/TXcYv5uZJ2XG31nfoz3Nkap2pB5yZRilymkHn0eEsFZpN hR7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=tSXTLWkNBwQ+7OxDnCw3ne+xa4SgHozyZ+1qD8tiba0=; b=RVdKIxcD0QufBn2Shjl7jJtP+uH6mJjpzH8SAdBGzrL5VA8SDkh0mwCpZf1zsLdBON 19+gSzgb8lQYGojy8d6yo3PeXQXMPnQlmldijK/veIWra6huvqpdxOoG17xVbRJ/Ycy3 3eAyHL8Tg3gnIQm0sja8aCXSYsGwyP96VT5OBsHcgxccMSk2r6esEMjano7bKK+xqx4T q3Xlsyl6WnBWRDB5xazjhNCuZN371GBhh0kQWQaxF0zrJ+T/VEGn6vrStEhgTHT0bUl2 k/F/PUvRgGUQMLiwVfNpEBWW4Q/EG0Iirxi8XvtiY/mR48/C1B7n+zYNNqN39bnOpuq1 VjlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@lunn.ch header.s=20171124 header.b=EpZPQGHB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x3si6512394plv.424.2019.03.31.07.34.02; Sun, 31 Mar 2019 07:34:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@lunn.ch header.s=20171124 header.b=EpZPQGHB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731258AbfCaOdV (ORCPT + 99 others); Sun, 31 Mar 2019 10:33:21 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:44563 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731210AbfCaOdV (ORCPT ); Sun, 31 Mar 2019 10:33:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Transfer-Encoding:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=tSXTLWkNBwQ+7OxDnCw3ne+xa4SgHozyZ+1qD8tiba0=; b=EpZPQGHBGNDQdLDT5NDCd03FOO trleJG4YHqN1dZL8dcnKnsJSueB442TC05tDCcDs2W61Xz/IIEma++ODmgVe69hOvdxxpbXBEV9q7 vhlIhQAGWcmNiQ13A6xkdAMighyL31qdI5aVtBt6VSTNJu18Aom682lfKcgDqrRi4jmo=; Received: from andrew by vps0.lunn.ch with local (Exim 4.89) (envelope-from ) id 1hAbWM-0005lI-2G; Sun, 31 Mar 2019 16:33:14 +0200 Date: Sun, 31 Mar 2019 16:33:14 +0200 From: Andrew Lunn To: Mukesh Ojha Cc: Colin King , Vivien Didelot , Florian Fainelli , "David S . Miller" , netdev@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] net: dsa: fix negative loop bound error on for loop Message-ID: <20190331143314.GA20636@lunn.ch> References: <20190330214241.15311-1-colin.king@canonical.com> <3723042a-88db-fa87-02ec-4ff231bbaff2@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3723042a-88db-fa87-02ec-4ff231bbaff2@codeaurora.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 31, 2019 at 03:25:47PM +0530, Mukesh Ojha wrote: > > On 3/31/2019 3:12 AM, Colin King wrote: > >From: Colin Ian King > > > >Currently the for-loop using an unsigned int for the loop counter > >which is problematic when comparing it to the signed int count > >This is an issue because if the signed int is negative then > >the negative loop bound is implicitly cast to an unsigned int on > >the comparison to loop counter i and will yield a very large value, > >eventually causing an error when memmove/memcpy'ing outside the > >allocated region pointed to by ndata. > > > >Fix this by simply making the loop counter i a signed int; > > > >Fixes: f2f2356685bc ("net: dsa: move master ethtool code") > >Signed-off-by: Colin Ian King > >--- > > net/dsa/master.c | 3 +-- > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > >diff --git a/net/dsa/master.c b/net/dsa/master.c > >index c58f33931be1..1b659647a303 100644 > >--- a/net/dsa/master.c > >+++ b/net/dsa/master.c > >@@ -87,8 +87,7 @@ static void dsa_master_get_strings(struct net_device *dev, uint32_t stringset, > > struct dsa_switch *ds = cpu_dp->ds; > > int port = cpu_dp->index; > > int len = ETH_GSTRING_LEN; > >- int mcount = 0, count; > >- unsigned int i; > >+ int mcount = 0, count, i; > > This looks fine but why the return value checking for the negative will not > be good here ? > ?count = ds->ops->get_sset_count(ds, port, stringset); Hi Mukesh Is there a return value check for negative? Andrew