Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp732370pxh; Tue, 9 Nov 2021 18:20:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJyeOT9GE/YucX+nZkFDOxbaiuEkLtgjkDysL3sGetLIKRpIZDGfyDJMFCWnd8rguEdM71E9 X-Received: by 2002:a92:d74f:: with SMTP id e15mr8789932ilq.181.1636510826079; Tue, 09 Nov 2021 18:20:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636510826; cv=none; d=google.com; s=arc-20160816; b=PqhNgEu0VOGfFL1DUzYU1VwJJ4ESbkYLKeHX4FXVggGQiKChv0kgZRhyP6A/qQ0b6o Amz12O0mCux95dXeUTeG8SKFGF5Z34zTGayalHZSMgp/6Rk4GrSaS4sY7ecLBQVJHzpo 5iP51mXgHwAsXlcQzViuk0s0tBWL8Ri5X5EiOu2EQcFph6O6giAmSyPISnqFxgHlXEfC 8wKT+OgrRy+E8ZCWQ+C9zMt/dKZD9pxmXTUdvIdF7V6LGNXgi8LY+nEEwDzD9jHNoRA9 R7YYLwP2sBWYKxs35bcJZz1aDQn0l9cqj7Ypr4jeOnvvs1QmC3WYUa2HWd/RdAnSIV64 qP2g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=DU3uMLJok33NjfKlerihkXitY12leIKyJ9oTnpbGkSs=; b=NtqDolMe825dV+vEy8jhE43++dhOwwLppXO0SA5z07F/72BXUM1vFfQA2SY/oeh1f0 bbg+X4crbp04PA6qJ40OG/AuE93tGDSLUKpBDH1bWrXhiNAYGoHbTTfRcpZ/IM1qId7C 2cwq88NkZ/lL1Q4NTEMZkaOZVCPUj7URweEBqLpo2VtskZXxTGZf9UdvE9TMp+juvEbc UJMCF/mWfpuq7Mkqsq4ftaNvaW7tw713a+LRqlbMZ0LGCLBIJpCWw1LzeVGjXYPYFDak XrdRqGUsV5KqM+rV3nVKQlFPIzKmKibFVTAgQRNkB1Xrxk+3T57761mR2SBMWBi2/Qcr BVXw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j9si463174ils.179.2021.11.09.18.20.11; Tue, 09 Nov 2021 18:20:26 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229843AbhKJCRI (ORCPT + 99 others); Tue, 9 Nov 2021 21:17:08 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:41668 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229810AbhKJCRG (ORCPT ); Tue, 9 Nov 2021 21:17:06 -0500 X-UUID: 812c69d1ec49412da92515216e734baa-20211110 X-UUID: 812c69d1ec49412da92515216e734baa-20211110 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1372025789; Wed, 10 Nov 2021 10:14:17 +0800 Received: from mtkmbs10n2.mediatek.inc (172.21.101.183) 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; Wed, 10 Nov 2021 10:14:15 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkmbs10n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.3 via Frontend Transport; Wed, 10 Nov 2021 10:14:14 +0800 From: Zhiyong Tao To: , , , , CC: , , , , , , , , , , , , , "Guodong Liu" Subject: [PATCH v3] pinctrl: mediatek: fix global-out-of-bounds issue Date: Wed, 10 Nov 2021 10:14:11 +0800 Message-ID: <20211110021411.31761-2-zhiyong.tao@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211110021411.31761-1-zhiyong.tao@mediatek.com> References: <20211110021411.31761-1-zhiyong.tao@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Guodong Liu When eint virtual eint number is greater than gpio number, it maybe produce 'desc[eint_n]' size globle-out-of-bounds issue. Signed-off-by: Zhiyong Tao Signed-off-by: Guodong Liu --- drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c index 45ebdeba985a..12163d3c4bcb 100644 --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c @@ -285,8 +285,12 @@ static int mtk_xt_get_gpio_n(void *data, unsigned long eint_n, desc = (const struct mtk_pin_desc *)hw->soc->pins; *gpio_chip = &hw->chip; - /* Be greedy to guess first gpio_n is equal to eint_n */ - if (desc[eint_n].eint.eint_n == eint_n) + /* + * Be greedy to guess first gpio_n is equal to eint_n. + * Only eint virtual eint number is greater than gpio number. + */ + if (hw->soc->npins > eint_n && + desc[eint_n].eint.eint_n == eint_n) *gpio_n = eint_n; else *gpio_n = mtk_xt_find_eint_num(hw, eint_n); -- 2.25.1