Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2701282pxj; Mon, 31 May 2021 08:35:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNWI8tDDD2XWbYMIDKPGU2f/xfVpQLnpkdh3E3opFONPqpJt03u2z/XcElLcidz/llyKgQ X-Received: by 2002:aa7:c441:: with SMTP id n1mr26389447edr.6.1622475318843; Mon, 31 May 2021 08:35:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622475318; cv=none; d=google.com; s=arc-20160816; b=uucu19FoXYQtl31PQpDtu6aMqXHMfase7/eOaKtHbK8dGxKYTWZ0gKQiDsmkX+iW2r GZ7omsbgAmZAjE9423/RgG+PdQpaBSFk5O13ui+4OrtjhTYVF5d/esTPBlb3kzIqP8ZQ R8wpvWn1AXhHc96s3cgjfd10F0DPf1hFFMYIhprgB9KL+yiW1tXeWY7Gx1fZjR4w9khw fYCocfWxqdWSPjIm6wgkqFoR2HG17dTBDloY/0iZBKB6xyZCD95+Md05D9weZsSs84sd 17+COsNIJznuilFU2EEVkoK7FrZdbBt0IrKfrhpxkr8DjVNgWWi5pkcM8s8Zxy8wbF7c fIcA== 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=DzFxtC7PXClNgpnvW6V18oSS2y1rB8H5GYQnJFtNfBk27eV+AAF3IcUCckh6fua+Hm CmLd/FcxX6CrqrZ9jJX58T7xqKEcojKFhOdgqA76nZQrZueo2tLnEIAs+/bHIYSST/Wf G+/UTEuvk3ijWTs/BzP9Ll801u/Y6FgLUlhAvirk50EW6t6du3tinMvut6nEMPcOgmpb KC/ABLOqY9QpTL1L5kQBBXMTZ6tmtsSfhFcWqpdC1mJpv+AV9i4iO00m3UmmEWATDZCK hF+Yet/VsS4a63FdvFG620bd9Yx4GhRAcbkZlo8Rm7pAica5l2fxuH3Awg9E4ww/Tt8I IGkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BltVo9jd; 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 e22si2886014edv.165.2021.05.31.08.34.54; Mon, 31 May 2021 08:35:18 -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=BltVo9jd; 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 S234566AbhEaPfe (ORCPT + 99 others); Mon, 31 May 2021 11:35:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:47638 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233630AbhEaOV1 (ORCPT ); Mon, 31 May 2021 10:21:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4B744619B8; Mon, 31 May 2021 13:44:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468671; bh=OnKk4J0rJiPuHFiwNihNYM0eQogylE7E2JYfh02LAe4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BltVo9jdc/WnHqQX8V2ij/jGMzHj89ryCckdvZ2ekb+EOUdsUbyILVQ8wwJSfJPsq DobpPPe5p26Vcn31bLWqaV2pPwjkkyjMLA2RwWWefKu+foZqgnkgLs+m7UF368SVCE zMZwUCZsbp6qtdrH3HP++5qbume/i1XQFBhoaIq4= 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.4 080/177] net: dsa: fix a crash if ->get_sset_count() fails Date: Mon, 31 May 2021 15:13:57 +0200 Message-Id: <20210531130650.674754658@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130647.887605866@linuxfoundation.org> References: <20210531130647.887605866@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));