Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2280872rwb; Mon, 19 Sep 2022 02:40:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7LvXBOCtGju06rc3evxY2ioYtQOGSgaD0qtN3Cea0chunh0/pR53wdr+BSo0O072eqMTOv X-Received: by 2002:a17:906:ef90:b0:77c:280b:93a1 with SMTP id ze16-20020a170906ef9000b0077c280b93a1mr12211519ejb.709.1663580415166; Mon, 19 Sep 2022 02:40:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663580415; cv=none; d=google.com; s=arc-20160816; b=FX1jrGQtyKTr8KiCrleTOJYRTan383vO2sU5Ej/Md06cSZFGav1gUzdpboZeW+nKcX wBiGO7g7gPTCCUrdQHAqw/0Zx3Q9rrktt5v/xMqaf1q/p0LotNiWH4lTd5rFOH+ztYq1 F6uA4Bna8ZEROMpnBs1SLhLE/0XisGOjJYXzZeKTDwPZHxxUV0hYLgOQm79WoFxXisLA ejaHgt0OLiXsMkkxn+zit9HhZcawR+zeVTO0lPecSkrfnTr94XecPD1txlZ7FCSUmxR9 j9uYi7ZiuxTj0T2abtugJblAWuIZfd49F/p2I+QSFR1ILYMfxcdoSxnlWEE0JA5Y2Gbz xdCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=zgj5CYWKZgJbAqXHgzBhGuk8A4h8FTDoZLTDoeqVF3E=; b=rWTLQRXmInEbHZEOndQjYyJMkn1sPfBHciDeMA4t6w6o7OvvuYkpbqSAlFuUE9mQ1y 6Wq2XhXsRapt9POHC+rcsgUkP8VmcpkrTfmX7t19wkSQSlz83gYnalUsCyA+VxuDT9Ty RNfsmTzmS18fdbIFYnL94id58DeegdkeoJIzBn6OJ8JMRMIPo1J0LJVpF8K6nvo18GW+ NuAlHqzbtg/hUKXHttEZrG3ccbIYV7oulx5IxWq7cCa17egoxBuzI2y7rPZL8feT2/Hu s0fXfaWhujj2BYjjRu7EizplsSvyLC33uBYKNotTG1vy1+ZKrFlTWNN0KhV0jTgV7lkq l/Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=gkS2+O+z; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b26-20020a170906151a00b007750de928f7si19096459ejd.488.2022.09.19.02.39.50; Mon, 19 Sep 2022 02:40:15 -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; dkim=pass header.i=@mediatek.com header.s=dk header.b=gkS2+O+z; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230212AbiISJZU (ORCPT + 99 others); Mon, 19 Sep 2022 05:25:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230203AbiISJZE (ORCPT ); Mon, 19 Sep 2022 05:25:04 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7565184 for ; Mon, 19 Sep 2022 02:24:52 -0700 (PDT) X-UUID: 9a37d653e3c942fd9fdb5fb7375a517c-20220919 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=zgj5CYWKZgJbAqXHgzBhGuk8A4h8FTDoZLTDoeqVF3E=; b=gkS2+O+znlbjI3q6RdV1SQ8qU9xbshNBz5Hp+ppG0WhOgiLAtvaP6QACLpRZPapDy2Kfdk65E+sI3hUfzPMHAoWM/cPb3VNGPJdMaQ+arHIypffHlnmC39BxUFLoEGrvmH4UkT9jWurIYjMoLrJwmxF+jN87jhZgNk++pEnir48=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.11,REQID:612ed1d0-25de-4913-b52b-fcfeea3c4014,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:39a5ff1,CLOUDID:d1c9225e-5ed4-4e28-8b00-66ed9f042fbd,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:nil,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: 9a37d653e3c942fd9fdb5fb7375a517c-20220919 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 42249857; Mon, 19 Sep 2022 17:24:46 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Mon, 19 Sep 2022 17:24:45 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Mon, 19 Sep 2022 17:24:44 +0800 From: Yong Wu To: Joerg Roedel , Matthias Brugger , Will Deacon CC: Robin Murphy , , , , , Yong Wu , AngeloGioacchino Del Regno , , , , , , , , Guenter Roeck , Dan Carpenter Subject: [PATCH v5 4/6] iommu/mediatek: Validate number of phandles associated with "mediatek,larbs" Date: Mon, 19 Sep 2022 17:24:03 +0800 Message-ID: <20220919092405.8256-5-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220919092405.8256-1-yong.wu@mediatek.com> References: <20220919092405.8256-1-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS,UNPARSEABLE_RELAY 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 From: Guenter Roeck Fix the smatch warnings: drivers/iommu/mtk_iommu.c:878 mtk_iommu_mm_dts_parse() error: uninitialized symbol 'larbnode'. If someone abuse the dtsi node(Don't follow the definition of dt-binding), for example "mediatek,larbs" is provided as boolean property, "larb_nr" will be zero and cause abnormal. To fix this problem and improve the code safety, add some checking for the invalid input from dtsi, e.g. checking the larb_nr/larbid valid range, and avoid "mediatek,larb-id" property conflicts in the smi-larb nodes. Fixes: d2e9a1102cfc ("iommu/mediatek: Contain MM IOMMU flow with the MM TYPE") Reported-by: kernel test robot Reported-by: Dan Carpenter Signed-off-by: Guenter Roeck Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 97b721006a47..01b31b09bd8d 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -1048,6 +1048,8 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m larb_nr = of_count_phandle_with_args(dev->of_node, "mediatek,larbs", NULL); if (larb_nr < 0) return larb_nr; + if (larb_nr == 0 || larb_nr > MTK_LARB_NR_MAX) + return -EINVAL; for (i = 0; i < larb_nr; i++) { u32 id; @@ -1066,6 +1068,11 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m ret = of_property_read_u32(larbnode, "mediatek,larb-id", &id); if (ret)/* The id is consecutive if there is no this property */ id = i; + if (id >= MTK_LARB_NR_MAX) { + of_node_put(larbnode); + ret = -EINVAL; + goto err_larbdev_put; + } plarbdev = of_find_device_by_node(larbnode); of_node_put(larbnode); @@ -1073,6 +1080,11 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m ret = -ENODEV; goto err_larbdev_put; } + if (data->larb_imu[id].dev) { + platform_device_put(plarbdev); + ret = -EEXIST; + goto err_larbdev_put; + } data->larb_imu[id].dev = &plarbdev->dev; if (!plarbdev->dev.driver) { -- 2.18.0