From patchwork Wed May 3 01:21:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xiaolei wang X-Patchwork-Id: 89533 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1011210vqo; Tue, 2 May 2023 18:36:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5mSQaL2OqEqGxvVElROazIrN7gxBI88Ez4x/L8If7B9uQar/YVRJl6IaF3pcbwl29GUsAn X-Received: by 2002:a17:90b:4a02:b0:24e:27a:e91f with SMTP id kk2-20020a17090b4a0200b0024e027ae91fmr685216pjb.11.1683077795922; Tue, 02 May 2023 18:36:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683077795; cv=pass; d=google.com; s=arc-20160816; b=aXIUfcC+sjXddxnAWMuJ/eK9FjaGLZ9i9pNFHogiwcNWC3GzirnfVo5zVcAcHtsSnx 0pewCz84DzoK8h7y27viozL4wwUIoiPQ0nrWy0hsOs4rRupDIdRX13CuctdgPyYcLFxJ iqd/SRGmW+g3FCbAYMiqA/SP6EbRgjB3ysWDQW6DFw+ZzlRhVe0rFCaHQJQk+/Pp55ms OEwxCOV/CmYoMilHRWH7dEZaHEbDaJ6/O7f0DNsYlkBqtSCoCC9bBvNMOt+pFs2zhLqN JI+f5Mgn+iAm/89yjccoGta2W8zgbC8/GPMkVxS4sR+ciyG5J69JCNr9zg47qjtFaaI0 XMmg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=+1RgkwJLdAJUJJO5LbJNMNCyEssUFb17iZLiwO/Y0dU=; b=PfvYRJEq5V+llHs/Dj+PSPeexJq3Ox2sDgAxJVmsEBvjJ+aWTVNLdY5QuNQbelRJet xIeSTUT4ErXcGN0yd/vfd6YpAPSUTT+eyvih1d2CivQaxu0A+PVcKS82GSd/iM9v33dR zOpfisnJWZAmg/RGgUqvHdZs1pXB8QAvrYAgicFU5VgkSxlAWO8bCynDQ1/74nQMT1Tx 0v7V+vdWjq410DbULU7lKe2nAOT69B9ajXSWSeN1zrCcenP0M3DZeoggSxhY+YUcTolo Qrc0wPnfgsm+lYV4vvmPDwPehVznFe/t3m6kGnAJnwz6mGtXo+yhrWtGtYtur4sNV0sG m1Iw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@windriver.com header.s=PPS06212021 header.b=KDm3uJ51; arc=pass (i=1 spf=pass spfdomain=windriver.com dkim=pass dkdomain=windriver.com dmarc=pass fromdomain=windriver.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=pass (p=REJECT sp=REJECT dis=NONE) header.from=windriver.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u6-20020a17090a450600b0024664356ef7si340542pjg.152.2023.05.02.18.36.22; Tue, 02 May 2023 18:36:35 -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=@windriver.com header.s=PPS06212021 header.b=KDm3uJ51; arc=pass (i=1 spf=pass spfdomain=windriver.com dkim=pass dkdomain=windriver.com dmarc=pass fromdomain=windriver.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=pass (p=REJECT sp=REJECT dis=NONE) header.from=windriver.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229492AbjECBWQ (ORCPT + 99 others); Tue, 2 May 2023 21:22:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbjECBWP (ORCPT ); Tue, 2 May 2023 21:22:15 -0400 Received: from mx0a-0064b401.pphosted.com (mx0a-0064b401.pphosted.com [205.220.166.238]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1932CC; Tue, 2 May 2023 18:22:13 -0700 (PDT) Received: from pps.filterd (m0250810.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3430vrTU023736; Tue, 2 May 2023 18:21:58 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriver.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : content-type : mime-version; s=PPS06212021; bh=+1RgkwJLdAJUJJO5LbJNMNCyEssUFb17iZLiwO/Y0dU=; b=KDm3uJ51AUPFGgoovx1Sp+oXjLJMu8q5MglI6w4lEsLBqBLrEZZhv7mts4JKV6kdfoWr B9ybUvUaPzgFIaaUx73q6yMLAJFmOlI1tI+m7h+q3xMehD0Q05P1M+iohLbwR+HtMc66 EgtNpQTolqmA6TEHn82z3ZAsAgqNoTSa2FczgTSOTacNFmK92pYdAB2fLQftB1324xvL 3NyAv7e7fQebOIrIaZL6VVQP+yjlEu9GY4vozt4MiitTeGyQ0aZtodGY5FibDame3iEx Yp8NK0W7Y/L2aNagz3t0zk3uXTVP9b/iqwi8FEwGgr3RXGMeVRTo4vdbuQsEXLxtTq2g Mg== Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2100.outbound.protection.outlook.com [104.47.70.100]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 3q8xh5k6sd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 May 2023 18:21:58 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JzfMVN/yFGdq8Dg2W29hdn4t6opzLoP+uJskg+p31lLlzJb1IejnbaG/UjBFqh5ONXCNl9VL1l7qc0+n8YWzZfW4QwazpKY67MIf63KfD0C2j1d/btpRBahbiufwK4I/A2v1Fuf7ToPbmRHMFpjP8Knwr+7SueXvJ7T4rE1f6HqF3WAbMujnZcnJWjOt8lEpUWXzI+nBCGqopw9JXKLetLelgeLTpKFQUL2RJpTK2Zwck0WPGqXrcxko4kQvGtzQ8eC/dV/OHw6zi496dyPEMNdVean37aQv0Vo6JCSpH4HmBCMy4KNFrAom0+JH+xcNFoFv4hWorNxLsoD2YZiKcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+1RgkwJLdAJUJJO5LbJNMNCyEssUFb17iZLiwO/Y0dU=; b=JVLL5kFm32dhvvTVCp9aeG5QJa5sHqrGXu6nSbrJaOljOhv7lng1dDBASZlOuETqA+5Sx8Z7K4JJxlH5wcaaVJLAiPqHkPvRqICCp1gHvGDm/yt0mbHrGRX+RWcK4MtAvOLE5YKSy8j9Qm+trH1ChB+kHUkHUqDiCywEoVhzrLfCAYfIW+NQhL4pzGCv8rKRAcCP9UlC0eJ0CpfIiBM9OdKgJCZwTeP1Cfo4MAgTDzynjCY+YkEHrVgUS/5BazV/ZEE3gHfPr+VJ/QyKvIcfD7pVEnBZbBUXnlG+SnlPw4+5aNpZlBxi1+mczCgKsl5WSZWb1sqKlDrvPTv6RMc4mQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from MW5PR11MB5764.namprd11.prod.outlook.com (2603:10b6:303:197::8) by BN0PR11MB5711.namprd11.prod.outlook.com (2603:10b6:408:167::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Wed, 3 May 2023 01:21:54 +0000 Received: from MW5PR11MB5764.namprd11.prod.outlook.com ([fe80::6485:357:72c7:e45]) by MW5PR11MB5764.namprd11.prod.outlook.com ([fe80::6485:357:72c7:e45%7]) with mapi id 15.20.6340.030; Wed, 3 May 2023 01:21:54 +0000 From: Xiaolei Wang To: aisheng.dong@nxp.com, festevam@gmail.com, shawnguo@kernel.org, ping.bai@nxp.com, kernel@pengutronix.de, linus.walleij@linaro.org, shenwei.wang@nxp.com, bartosz.golaszewski@linaro.org, peng.fan@nxp.com Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v2][PATCH] pinctrl: freescale: Fix a memory out of bounds when num_configs is 1 Date: Wed, 3 May 2023 09:21:27 +0800 Message-Id: <20230503012127.4157304-1-xiaolei.wang@windriver.com> X-Mailer: git-send-email 2.25.1 X-ClientProxiedBy: TYCPR01CA0131.jpnprd01.prod.outlook.com (2603:1096:400:26d::19) To MW5PR11MB5764.namprd11.prod.outlook.com (2603:10b6:303:197::8) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW5PR11MB5764:EE_|BN0PR11MB5711:EE_ X-MS-Office365-Filtering-Correlation-Id: 85e9c5d2-84fd-4276-f8f6-08db4b74c7d1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kQvwfVctGDcdOJjZrYC8Lgv+KbzAzamOgkDqJv6ocFJGEoAJM2x4IWEADKSzXnWjDnWLKSBapE5HpMcT0X/SIfALSzea91NgVvOS5x7AmMpzYua1LRtn8QRLzBRPsusZohSovtzpiQoNqjZ0kv4sdA9ojWhX7+6g2fyFVJ+7FN30O+HLKWl27b5Aaksx++5APEbz0/uAW3nvTlKE+95wrILDxWUQ3W0QgW3CTa8ivIugafcScprBeG80J9/Je5uX6YzP/8P2kcfYFhJ2c1eRmqlxA69Pfq4p4CJfmPVVFEWtPjyl80cuWD6NfUouUeqrGUvyk3pcPShtPHpGAR7ppyO2JPKRiEMlpn5D9OzNi2uz3mvZ3DptcUzZ1sxWJ2YfZ9STkzvrwtKOQyZB+GBJdNnrfGQ1vZwqwljjnPfIpA6Z+A5TNr3/nLTi8iJd/Us9VJWQZxOqtnUBqWiqTnP4KLJ+tctalu+lf10kv8AokliFsa29Go0i3x/o3dZDyNlrLA+D78n7biOJDwLvO0pOYcsAN4BBI9pfKhW/znjzSO7WWjgzM/ER+ltkLbtHC5Jv7gqqdqGMG40sLU4mG4aCn1FJ7uP/hO7nzW5UdFULHk/jF5wCteriOvHnAtUNlZYIARVbHDkWoiEHEuM2x2dMHN85DcAIiRMhQe68onqnzjc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW5PR11MB5764.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(136003)(39850400004)(346002)(376002)(396003)(451199021)(38100700002)(41300700001)(5660300002)(8936002)(8676002)(38350700002)(66946007)(66556008)(66476007)(316002)(2906002)(44832011)(7416002)(86362001)(186003)(6512007)(1076003)(26005)(6506007)(6486002)(52116002)(4326008)(6666004)(83380400001)(36756003)(2616005)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZMZ7iVZr5M4dG24LzrjBdwbvIaX4qsFhL3dXZg9ycTk/L4nj5aoH8hCv8IqfaZFSIp6mH3IGKiomTJ5YXn3egJ86Qdt7nBt788//dayCQNqnPhXiYwyamQP1pVJwjGJhqE+vO5wBMlPL3X75jaLBY/kqGueM6mLg3PYPe1H0vEwyauBibvSatepm7lgqWTUEaY1IVDAra/Ugn2i3w7L9mVpAoyR6OSaGK+kTJn7EfkCf+p5G7gQt3X1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wIgGWOrcdqn+qZhsskSKChCZbtuUZAaAVXWzfAYW0BwUNlm0U9l1HcB4QAvCIwcp1anB0PfLVMqppedNwS7aZLFK4LxvvSmcmxz6IvOavHBv2taozG9y3Y31FmLoW4FjeAd/yLOI3tgNWCkTMCvwD4qVIAvp4NGbi4nZIo8HKKvlkHHmrHzVrRqKHQ8TmHLSBm2e/gkGpDRbnyrF2nkzrAuitWrJCNVmoSVaHKidAia3pmwq0ItOu1Tx/gBPz5PAhJmJFmLWNk+kHDniCwkRKM874JMCAR85RA== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 85e9c5d2-84fd-4276-f8f6-08db4b74c7d1 X-MS-Exchange-CrossTenant-AuthSource: MW5PR11MB5764.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2023 01:21:54.6533 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: sjPE3ccb0ldYqO/EsqqN0HBQO7paD8nsIGjwI8/RbGlJgUAkSSnWRlbDHCp8/8D6BUn4/oex+8qChB5sN6jbnQaTMzsSqWTD5P+l8jynnsw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR11MB5711 X-Proofpoint-ORIG-GUID: iXhrNyVLBJ4qkcJjRqCTKc2TSY_LDZ53 X-Proofpoint-GUID: iXhrNyVLBJ4qkcJjRqCTKc2TSY_LDZ53 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-02_14,2023-04-27_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 suspectscore=0 mlxscore=0 phishscore=0 priorityscore=1501 mlxlogscore=590 adultscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030009 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764834983168540670?= X-GMAIL-MSGID: =?utf-8?q?1764834983168540670?= The config passed in by pad wakeup is 1, When num_configs is 1, configs[1] should not be obtained, which will generate the following memory out-of-bounds situation: BUG: KASAN: stack out of bounds in imx_pinconf_set_scu+0x9c/0x160 Read size 8 at address ffff8000104c7558 by task sh/664 CPU: 3 PID: 664 Communication: sh Tainted: G WC 6.1.20 #1 Hardware name: Freescale i.MX8QM MEK (DT) Call trace: dump_backtrace.part.0+0xe0/0xf0 show stack+0x18/0x30 dump_stack_lvl+0x64/0x80 print report +0x154/0x458 kasan_report+0xb8/0x100 __asan_load8+0x80/0xac imx_pinconf_set_scu+0x9c/0x160 imx_pinconf_set+0x6c/0x214 pinconf_set_config+0x68/0x90 pinctrl_gpio_set_config+0x138/0x170 gpiochip_generic_config+0x44/0x60 mxc_gpio_set_pad_wakeup+0x100/0x140 mxc_gpio_noirq_suspend+0x50/0x74 pm_generic_suspend_noirq+0x4c/0x70 genpd_finish_suspend+0x174/0x260 genpd_suspend_noirq+0x14/0x20 dpm_run_callback.constprop.0+0x48/0xec __device_suspend_noirq+0x1a8/0x370 dpm_noirq_suspend_devices+0x1cc/0x320 dpm_suspend_noirq+0x7c/0x11c suspend_devices_and_enter+0x27c/0x760 pm_suspend+0x36c/0x3e0 Fixes: f60c9eac54af ("gpio: mxc: enable pad wakeup on i.MX8x platforms") Signed-off-by: Xiaolei Wang --- drivers/pinctrl/freescale/pinctrl-scu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/pinctrl/freescale/pinctrl-scu.c b/drivers/pinctrl/freescale/pinctrl-scu.c index ea261b6e7458..3b252d684d72 100644 --- a/drivers/pinctrl/freescale/pinctrl-scu.c +++ b/drivers/pinctrl/freescale/pinctrl-scu.c @@ -90,7 +90,7 @@ int imx_pinconf_set_scu(struct pinctrl_dev *pctldev, unsigned pin_id, struct imx_sc_msg_req_pad_set msg; struct imx_sc_rpc_msg *hdr = &msg.hdr; unsigned int mux = configs[0]; - unsigned int conf = configs[1]; + unsigned int conf; unsigned int val; int ret; @@ -115,6 +115,7 @@ int imx_pinconf_set_scu(struct pinctrl_dev *pctldev, unsigned pin_id, * Set mux and conf together in one IPC call */ WARN_ON(num_configs != 2); + conf = configs[1]; val = conf | BM_PAD_CTL_IFMUX_ENABLE | BM_PAD_CTL_GP_ENABLE; val |= mux << BP_PAD_CTL_IFMUX;