From patchwork Sat Jul 16 21:46:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Rix X-Patchwork-Id: 12920296 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 64C63CCA482 for ; Sat, 16 Jul 2022 21:48:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=P+tKCzoxy+HnHHTimRpsux35Z27C0FDGJ8mYlVo4RnE=; b=gGidRMT6o5v4qB 80llZjxjW/xNmuMhYE0UAm9lKxAwxGdyPr6fbJFmnrHuEnUqLz6R4CJPvYT8uwiSNc5R+q447AY2v dfZllPE2Av8ZF9G2q8RC22iq13RzzE3aBfhl22gv/yX6q+EocqVQPKxz3oZoj+wpsPwslAL6iVUBX Z5N6i7W5XW9ssVEpCi/f16RTVwiuER8f2xxuEapCENoT1z7PF0XLFBYcp3LklzYZKFsb8Ipww+gU0 IyMbb+IZhzVVl+W3SQ34F/P49QJGqQKVo7OJ9JEGqgR7qcaFtnxiKfPCmb6uA/mbzxgFUSKAB60pK OcJ067bZlGaZ/tvZQ/LQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oCpcz-000of9-Ay; Sat, 16 Jul 2022 21:47:09 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oCpcv-000odI-2g for linux-arm-kernel@lists.infradead.org; Sat, 16 Jul 2022 21:47:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658008020; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=epB7rlrzw6XyEr2+HEifgpL7PVvDrusi3GoURdV5q2k=; b=LvkxiRDCfF89BwExC+722hks9pkTzm85AZYVlcfzyl7XLlFueho97/sBIoJ7xGBr1WmuSr 7qvas7WIxJyembU9I9yORBSV4LT+niTy2zGcqEbN1JHz2fChmIblIkiFL8BugzBIMYSFhv Bjw1LNIPU2oUDuatJkJos+0YbJdgqfU= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-341-_YhX71bOOzSBWnjR3e0oyg-1; Sat, 16 Jul 2022 17:46:59 -0400 X-MC-Unique: _YhX71bOOzSBWnjR3e0oyg-1 Received: by mail-qk1-f197.google.com with SMTP id bp14-20020a05620a458e00b006b59195c391so6287262qkb.19 for ; Sat, 16 Jul 2022 14:46:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=epB7rlrzw6XyEr2+HEifgpL7PVvDrusi3GoURdV5q2k=; b=EVi+qtkDuBWv133qDcQFx6HOn8mP4Dp6J0WYWXRUvCHCZcEAR3iN96eLSZmibAikDa XJv9rBmmnyrcKrLK380pmCUKts7+CjKHf2hpFQkCcY/en3+umEkr4iBcNJH4e8s9dGlz SvTCoEp+6mFK3miL9W+Zsn0sZ2v1OkRzsfstNWRCRHonMP9gWx2Li8xInA9UUM3yL4M+ hbhYdmvKP95Lv0mWBvGwS8GX3qSXc45t8ZTgDQiiop9Ks8db+avg4VHkuEsyYLMtp0lX P8kIJI1K9a7tjlN8hPIFMQ5G8hOq4FPHo9YDrmMJCdmX/XQJzFsm/TKotiGUjmV+yBqH pvcA== X-Gm-Message-State: AJIora/40NDEy2QjyqjiYEo5vp5CCDGvF+V0RZESCs9PxrL5JQx3+8su mXIQAccI+rr1VbLwrkJTDtpMbDGVVE9wHJn+fgOA+9eGq6xGVtriPt9ls5m/2RIkOWHqDHqAw6X cU6umuEK9qMbjc3ZOjIjFV0sl5p57ku1g1Xk= X-Received: by 2002:a37:2f44:0:b0:6b5:b10d:6f1 with SMTP id v65-20020a372f44000000b006b5b10d06f1mr13314492qkh.519.1658008018890; Sat, 16 Jul 2022 14:46:58 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sCWMb1HpZpVkq7nYKBH6ZxTcvmV5ifECAsHhu9bjCZGadDxzE/B/vvdUPRDZA6qJClbqRJjg== X-Received: by 2002:a37:2f44:0:b0:6b5:b10d:6f1 with SMTP id v65-20020a372f44000000b006b5b10d06f1mr13314475qkh.519.1658008018680; Sat, 16 Jul 2022 14:46:58 -0700 (PDT) Received: from dell-per740-01.7a2m.lab.eng.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id o21-20020a05620a2a1500b006b5cdbbfccfsm5742503qkp.79.2022.07.16.14.46.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jul 2022 14:46:58 -0700 (PDT) From: Tom Rix To: nbd@nbd.name, john@phrozen.org, sean.wang@mediatek.com, Mark-MC.Lee@mediatek.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, matthias.bgg@gmail.com Cc: netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Tom Rix Subject: [PATCH] net: ethernet: mtk_eth_soc: fix off by one check of ARRAY_SIZE Date: Sat, 16 Jul 2022 17:46:54 -0400 Message-Id: <20220716214654.1540240-1-trix@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=trix@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220716_144705_235266_0A8A2543 X-CRM114-Status: GOOD ( 11.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In mtk_wed_tx_ring_setup(.., int idx, ..), idx is used as an index here struct mtk_wed_ring *ring = &dev->tx_ring[idx]; The bounds of idx are checked here BUG_ON(idx > ARRAY_SIZE(dev->tx_ring)); If idx is the size of the array, it will pass this check and overflow. So change the check to >= . Fixes: 804775dfc288 ("net: ethernet: mtk_eth_soc: add support for Wireless Ethernet Dispatch (WED)") Signed-off-by: Tom Rix --- drivers/net/ethernet/mediatek/mtk_wed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mediatek/mtk_wed.c b/drivers/net/ethernet/mediatek/mtk_wed.c index 8f0cd3196aac..29be2fcafea3 100644 --- a/drivers/net/ethernet/mediatek/mtk_wed.c +++ b/drivers/net/ethernet/mediatek/mtk_wed.c @@ -651,7 +651,7 @@ mtk_wed_tx_ring_setup(struct mtk_wed_device *dev, int idx, void __iomem *regs) * WDMA RX. */ - BUG_ON(idx > ARRAY_SIZE(dev->tx_ring)); + BUG_ON(idx >= ARRAY_SIZE(dev->tx_ring)); if (mtk_wed_ring_alloc(dev, ring, MTK_WED_TX_RING_SIZE)) return -ENOMEM;