Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp4155591rwb; Tue, 16 Aug 2022 15:56:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR7O2GweyeGW9nJnR/uRxt5PMIa0E2OhTo9CNbPFYK42e/oyBcX01p1JW8+2Pr81YBNuWorI X-Received: by 2002:a17:902:c401:b0:16f:b59:85a7 with SMTP id k1-20020a170902c40100b0016f0b5985a7mr23999413plk.115.1660690598308; Tue, 16 Aug 2022 15:56:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660690598; cv=none; d=google.com; s=arc-20160816; b=zZ4YRjhRlIcT0WWt7YxPujDme/Rm/1hIeLVNRST7oLovpDp2SClCmcv6+A84APdBZR 8FZrSW73a6ZdsQkOMXPgo1CNEqykZ61Rc//grDKhxabhFs4pb5+pyZQ0m4AN89aQQQp0 ktHYENtcWnwRXN8J0hfPnyi+TnRqTJySrylij6G9xJGhDT8zwWdKYs4xSXHNUywr+HpL SWYRjTsQjD+qNiE3y6Fw2wEBkHPlnGyQdHZ6OxHgCBQHthjXZ3KB3Is1Yw7SrmeitBJY Vm0lGhDyr0A2z17U1xsUDyt6X9aONaTfmuMQpJLlrMKxljdZSuWOxRAQCI08jrkfU5e1 ON7w== 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 :message-id:date:subject:cc:to:from; bh=q4b/YPmnIgdWpRi/z8cFZz/5evrq+MluJ4xXuzwZQJI=; b=RyzbnoLr1+2wPwJwdrdyyy6aagk4i/Xch1lFCS+ARbHK44F1nvIv9QW78gJrj9oBy+ HUQCVqOW1+0UI7kGi09pY1GZkH6oPuUfjj6aDeSqwiihn18pU1qVWj3Wn+BInmjODVhd 2BOegKnwKhgCzUNB3PHk3ZgoWYxp7QQUfVDvS4/w577faMEtRDTS60a9tUMIcqDGGVuM wa0+708m13Dud/iDaUiNGzqlmUH+3aXg7xdDvPzh706wCUvhjGHvEFDb3WpEJivVzBiI RiIUVuMKqKQRvBVjBNa83a6zHpBzEBPsjINmvzXoxVLmE8QMgGmqAB+4PsIRrpajaJ1b z2gg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r139-20020a632b91000000b0042269726215si4540179pgr.815.2022.08.16.15.56.27; Tue, 16 Aug 2022 15:56:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238037AbiHPWj5 (ORCPT + 99 others); Tue, 16 Aug 2022 18:39:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230056AbiHPWj4 (ORCPT ); Tue, 16 Aug 2022 18:39:56 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D65B37963B; Tue, 16 Aug 2022 15:39:54 -0700 (PDT) Received: from rustam-GF63-Thin-9RCX.. (unknown [136.169.224.60]) by mail.ispras.ru (Postfix) with ESMTPSA id 0977B40D403E; Tue, 16 Aug 2022 22:39:48 +0000 (UTC) From: Rustam Subkhankulov To: Vladimir Oltean Cc: Rustam Subkhankulov , Andrew Lunn , Vivien Didelot , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Alexey Khoroshilov , ldv-project@linuxtesting.org Subject: [PATCH] net: dsa: sja1105: fix buffer overflow in sja1105_setup_devlink_regions() Date: Wed, 17 Aug 2022 03:38:45 +0300 Message-Id: <20220817003845.389644-1-subkhankulov@ispras.ru> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If an error occurs in dsa_devlink_region_create(), then 'priv->regions' array will be accessed by negative index '-1'. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Rustam Subkhankulov Fixes: bf425b82059e ("net: dsa: sja1105: expose static config as devlink region") --- drivers/net/dsa/sja1105/sja1105_devlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/sja1105/sja1105_devlink.c b/drivers/net/dsa/sja1105/sja1105_devlink.c index 0569ff066634..10c6fea1227f 100644 --- a/drivers/net/dsa/sja1105/sja1105_devlink.c +++ b/drivers/net/dsa/sja1105/sja1105_devlink.c @@ -93,7 +93,7 @@ static int sja1105_setup_devlink_regions(struct dsa_switch *ds) region = dsa_devlink_region_create(ds, ops, 1, size); if (IS_ERR(region)) { - while (i-- >= 0) + while (--i >= 0) dsa_devlink_region_destroy(priv->regions[i]); return PTR_ERR(region); } -- 2.34.1