From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63070C433EF for ; Mon, 27 Dec 2021 15:53:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238356AbhL0Pw7 (ORCPT ); Mon, 27 Dec 2021 10:52:59 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:44184 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238546AbhL0Pp6 (ORCPT ); Mon, 27 Dec 2021 10:45:58 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 47C29610A4; Mon, 27 Dec 2021 15:45:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E10EC36AEA; Mon, 27 Dec 2021 15:45:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1640619956; bh=TTxzljI+kg08DgroJfFa+qiy9rsijKLL7cw6GGM0c9g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YMgO9ZutIHwsG1Eo2d5QREJS2Tok9Rly9yywll5E9zIY/9qtdi0Izxs0I9UTYfkhu dlFAb64ISXTSn9xdCkhJ2TZJvJCyzrDXyIIm3rIfW30ROB3ExmCAi5N3K+fMJIaJg5 BflRGyIlrQlaDX6XT986Jd2wglmMw2mVoo/Hs/0I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guodong Liu , Zhiyong Tao , Chen-Yu Tsai , Linus Walleij Subject: [PATCH 5.15 120/128] pinctrl: mediatek: fix global-out-of-bounds issue Date: Mon, 27 Dec 2021 16:31:35 +0100 Message-Id: <20211227151335.526242164@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211227151331.502501367@linuxfoundation.org> References: <20211227151331.502501367@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: Guodong Liu commit 2d5446da5acecf9c67db1c9d55ae2c3e5de01f8d upstream. 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: Guodong Liu Signed-off-by: Zhiyong Tao Reviewed-by: Chen-Yu Tsai Link: https://lore.kernel.org/r/20211110071900.4490-2-zhiyong.tao@mediatek.com Signed-off-by: Linus Walleij Signed-off-by: Greg Kroah-Hartman --- drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- 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, 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);