Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2737121pxj; Mon, 31 May 2021 09:28:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjbzbP3eHuDezfhhD1Z4JOmLrZc9BtT8TD4GqblcukXHOCTj3BcVRUkJ7Nqmemf7XmSjCc X-Received: by 2002:a17:906:58d1:: with SMTP id e17mr23819997ejs.179.1622478480295; Mon, 31 May 2021 09:28:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622478480; cv=none; d=google.com; s=arc-20160816; b=APXeyVM0O5gAAD3a2HcgzkX0ZNLfkZ+JiF8h2KeR1VB69NkoOy8Jbnmguzx1Fhyjb3 Gue9hyPmR5kZO9QIvp0wkmmC76Vhk5LlCkbavu1esctlFZRN9KmAcn9eiFkaglAV+u4B v6S96fwWRJcdmVJYPfKRwWSO0RBO93O8Wy/DmWtULIip/9wdQ4S6O/aZ43CmH/8cLXsg 3nJ08DESm9/FQRB1vkGBcyo64w/c0VyBn/8TsNCUzy2Q/kj7elFm2R54f3qKG0RhzRuP aR+Vvh1rG4gpLgd4PY2D32k/DKv951L00qa+B5WFZjNH1LRc579BALunfwW0QhKt9uzQ /sGA== 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=rOu0fk2oGtGRxdTptJuqxLfHSqc1I/521XHpYWp3l3JRZpDuCpq2LJsWmbrq9WBHlT aEorXqadXh8bHtJAOLeL90arybHBuJ9bgAvbUtfBK8ozhmcqEheGu067QQPCHYelX+HC aNXK/vF7qgIkaTqLxGuytROcm7l0GwHe6PiTo8RIL6FQRj/dU82cum1T/rrepKf75jRK V9/ylyi2AOOPceWHlaKgOpC+CiTjzyxm9Nhidq1Q9QDGQiAH7a+NsSuV53UJC836/Bpd uMakOzoJdLr3pxUH7KRy7SdEtItTjYfwocI8lKGpVOM5nPrS3jLYplp9Yzez7ji5WkhI V02Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UE37x+Cj; 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 bm25si189956edb.202.2021.05.31.09.27.37; Mon, 31 May 2021 09:28:00 -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=UE37x+Cj; 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 S233957AbhEaQ0F (ORCPT + 99 others); Mon, 31 May 2021 12:26:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:39884 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233721AbhEaOnl (ORCPT ); Mon, 31 May 2021 10:43:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3CE1761439; Mon, 31 May 2021 13:54:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469289; bh=OnKk4J0rJiPuHFiwNihNYM0eQogylE7E2JYfh02LAe4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UE37x+Cjolje7sGlN+Fe/IPHI0498pIuMZwlZsMGI2Mesi6g6fvs/Ja+nYf4tQeZq ad1JfSIwsMYiz4OvwOisdhhgbZaz9zwmZ7NqS4aqjs19l2525U2aexjeMGGod85gfK PSDxGXFH33W/l0NBn28JZ7pUr8xqIkhHs/Q02JWo= 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.12 142/296] net: dsa: fix a crash if ->get_sset_count() fails Date: Mon, 31 May 2021 15:13:17 +0200 Message-Id: <20210531130708.648021756@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@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));