Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2629695pxj; Mon, 31 May 2021 06:58:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRfDT91B2C11HrkdXDylsobAXVKDh/h1Umiz0/GmpUa1yix4VAGsepqSQk5dkSzTtzzWmW X-Received: by 2002:a92:de49:: with SMTP id e9mr2786458ilr.56.1622469526115; Mon, 31 May 2021 06:58:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622469526; cv=none; d=google.com; s=arc-20160816; b=epU4khWMY5BWCEG4qz9cq7zfw+UNKr91ie8xpt66RcUpayiSbCboEIdk0tJWWRnftM lW5B9Kx1yghC/495R7ZH5EUoDSXqg234Kq6aM5kz9Cp8Rh0ljwmr06RQYstwnsAolQF4 1c31dlSTSaCVx0ru9QY+f/yXG3IJPr77LxxUIPwD7t8j2fmHeOsZbfTuqJl1yYrW0DrJ 8qXpD5tKeHuFI/1AFJRur7jM+0J6cOlMVvZKdmt+9zF4f0rurXJHZvSDABGXekG/Q+LS yjYMe0MCO7xemtSCbD4bWhRWol1M8mMPuVL5yVgj3JVNjI8HGFh/dwmyE6j+v26kAcpB 1//g== 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=6cH1Su3Cjx65kT7nn1kyqUaF9Qnu7V5muG5N9ufPGBc=; b=bq20KlnzC/lO32UQXpCJxzuj4+YkCsfMTKEnneuOuzZcdy9CvxzYsvhdrK94h1E4PP URlaQpeA2NDQUJPFiACkgFe0L3zrn3c9xF2/QcgF4uKVKXSp1eJF8aMRPKWop/F1XglB Ws7NkbJD8M4soMTg3N2o2Hs6Yis9dGybZCyDfBriLMWFMi4vMiDLo8dTlGZG6vS2pQfv /ms/7kAHzojj4xhmGePVba3fHG1voj08PwADXXUIoz6eENn9N90OiaOIEnxTP3oAmAF6 1B2pAd6pWnPCM1FPauAnDBLKm7HwXfcyTuoE6/qB2+nWkbn5Duv4VzTuOrcMUZvZtVt8 +AiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="j/fSyOy2"; 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 a11si1631793jap.60.2021.05.31.06.58.33; Mon, 31 May 2021 06:58:46 -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="j/fSyOy2"; 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 S233076AbhEaN70 (ORCPT + 99 others); Mon, 31 May 2021 09:59:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:40216 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232236AbhEaNgY (ORCPT ); Mon, 31 May 2021 09:36:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5561861403; Mon, 31 May 2021 13:25:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622467547; bh=5DpGA1KMFU7ZPxexWARaQNUL3rVmBIhU43e6YNWNlMc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j/fSyOy2RAPnAk98Eq/qWNXVi98jr0ZYw5WI2Ns3Q/ZqWDWonvAmlXjQlHjk/ZtH3 7PwGPREWj2laIs8LRr75agdZLSicXeCidOHak7w4Un9ko0X6mmkZBLk2eM9EMrRFOX l1+iUVYnLgDq3KSkbq39HUkhFRcEGIgik//FxipY= 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 4.19 071/116] net: dsa: fix a crash if ->get_sset_count() fails Date: Mon, 31 May 2021 15:14:07 +0200 Message-Id: <20210531130642.551687572@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130640.131924542@linuxfoundation.org> References: <20210531130640.131924542@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 @@ -87,8 +87,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; @@ -118,6 +117,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));