Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2660962pxj; Mon, 31 May 2021 07:39:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwH1RAa9Z9RaS+kaCSpbPQcnsB/OdCPklzrDXNb9dOQ8pQSIAtBL2BmNExa8jnxvkFF6XxW X-Received: by 2002:a92:cf48:: with SMTP id c8mr7633691ilr.66.1622471983048; Mon, 31 May 2021 07:39:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622471983; cv=none; d=google.com; s=arc-20160816; b=uBRGS8t6395lzPHEHbmJn6hFXTg3dNxxsWNbozbyUmuUCo1VvciE170UlPxvbnhJrv 5L6PkmuVmKclNm4csYQzMeSwMD+/mq1bnlVrYUb3TLSmAy5osxdLE0jyloFv23+56QMc +NptW3UXnRbphzO1eYDwq8TaHQ6ZGyoaHxJMXLTim/lFZaG/bxZmH4lFdf6lpP0H0UEw WcFfx5Urw79pSjV5qSpPt3j3jddm4Xz5CHw5Q/jpsgHRSgD63y3fvohrgo3uVWirKifH O7Gg2n98whOXfN17Y91IXLlWtMXaBk3lFCJNVbjs+21hfO5x2FiIewFX7iwpcQovfmFg F98A== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=i3KMRHViT3sV/SjBNLotpG4bnPsYs3RK6W1Whe89fps=; b=iI5TrXmpuZb1T9Jc6Okt07J7croU7F4VE9Urvu98pki/215tAlZnyHlzOiG3fTNx/j hoGAYDDK6fuyw6QU05xHmRBflQpM0fjLdGk/Z/D3DJwyPhZvQTOtFZ2RAhSHQCfbAq1r PAV5Yma/sKn81xgabN3/WmQYdp/Nu8Ibtl1kucq3yH0HgJjj9uyI2kZunQQKFYOmcpko eS8lIZhXQJv2LyRUOLf0OoiKod/7UW+VBOU/dCTqdnyh20RT6G5Ym71Hl9lDtEiOhhUq NPv2J+mguGMC6/bquBs/8kq23pojEYGuCl6Y5KBqhDwvgFe8oCaKft4454aaQqpWMoIF 34dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0s9psv50; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n11si14882510ilk.68.2021.05.31.07.39.30; Mon, 31 May 2021 07:39:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0s9psv50; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234149AbhEaOje (ORCPT + 99 others); Mon, 31 May 2021 10:39:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:59498 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232801AbhEaN45 (ORCPT ); Mon, 31 May 2021 09:56:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 849DD61400; Mon, 31 May 2021 13:34:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468095; bh=OnKk4J0rJiPuHFiwNihNYM0eQogylE7E2JYfh02LAe4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0s9psv500/B3tS+hus5eGOZbPQKgrlXDc5lKNBWZib4YuJvTXYcCj6mF2gNyWTGvg SeLDRgWlhEPZKCGXfhaYfLogjQsJkCcHKwmzt9RC3MVX3HxZ7bniO09qb7JImBxglP jPLGsCiLen9yn3QeaINpwZOw4viAaMHF/712Jens= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" Subject: [PATCH 5.10 113/252] net: dsa: fix a crash if ->get_sset_count() fails Date: Mon, 31 May 2021 15:12:58 +0200 Message-Id: <20210531130701.809011402@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter commit a269333fa5c0c8e53c92b5a28a6076a28cde3e83 upstream. If ds->ops->get_sset_count() fails then it "count" is a negative error code such as -EOPNOTSUPP. Because "i" is an unsigned int, the negative error code is type promoted to a very high value and the loop will corrupt memory until the system crashes. Fix this by checking for error codes and changing the type of "i" to just int. Fixes: badf3ada60ab ("net: dsa: Provide CPU port statistics to master netdev") Signed-off-by: Dan Carpenter Reviewed-by: Andrew Lunn Reviewed-by: Florian Fainelli Reviewed-by: Vladimir Oltean Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/dsa/master.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/net/dsa/master.c +++ b/net/dsa/master.c @@ -147,8 +147,7 @@ static void dsa_master_get_strings(struc 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; uint8_t pfx[4]; uint8_t *ndata; @@ -178,6 +177,8 @@ static void dsa_master_get_strings(struc */ ds->ops->get_strings(ds, port, stringset, ndata); count = ds->ops->get_sset_count(ds, port, stringset); + if (count < 0) + return; for (i = 0; i < count; i++) { memmove(ndata + (i * len + sizeof(pfx)), ndata + i * len, len - sizeof(pfx));