Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp7626779rwn; Wed, 14 Sep 2022 01:36:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM44u8BPrLQxBXFzYV2BhuTOr7zUhPv2fgeBHf3nsLZ/WYTKrguTyEa4hK0sgzbQStJo2osJ X-Received: by 2002:a17:90b:1c07:b0:202:ff6e:6015 with SMTP id oc7-20020a17090b1c0700b00202ff6e6015mr3626923pjb.210.1663144586195; Wed, 14 Sep 2022 01:36:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663144586; cv=none; d=google.com; s=arc-20160816; b=CBOj/CYC7LI0ni+PlmVPK8aIqizqWnRuNWzCbsTENJM/foUrXA8bXv0fEkgDQk2grF Urut4Ct3gXCQzQyr5F7oM9LdRsEpw3jXE4QaIsbHALVf2iS/OjjlgYtGyDRWazzjl2cg /9xZ/pnHkEiu89Td0ZxN13YeTenHHfgps4X94PrVT3RCilgDGryScy0TwkEqByl255dw IzDPs7ZguVhcEekWhiqm+RT77iq/PXxZnzW+38jp/tX9oAzL9ZU6tZQiAYp0/qhAKh9z ij2DC7tnB485jRLigdHhutjSBfOE+bz+TeR8DqSTWRlyJzN8hDQJB3bEXXK1WOTDM3/o iQPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=i4WqWGFN996ypu86FTXwvXB/hikI0wOqqPyZaEJtfSY=; b=fH7r3Z7rmyNunpDrQITFfbCIz50WTIlpP7x/PfTrbd8yOvNVBpK+L51EBx4LYJAv6N QRwv9+gTRpoDKnZaT7/RsHjgb9P/8VZb+jY4/DV3ifs9KWneh7qWunRM3T0xQFddvmko 4x2btN4bgNQBcDj8CAtdX2cOZoB4n9U+zm8X20kViePyF++8jjG7EslKzTPDFuwVR+PL iQDGarJhoY3ZFqr3AkrfUbp4CTjLNU0Zw6XilgwvZhp9OTKiDmTKTmrhwM938TxRF2zo zYuRjSMBYta+IlMwQTgOZt1mGwANV3cCZMfYXnlDAQjcbeQRN3LQ0wSwIO0fDGDJ6F7E Moyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Pk9I7QN+; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a19-20020a631a53000000b00430347960c1si14147742pgm.690.2022.09.14.01.36.13; Wed, 14 Sep 2022 01:36:26 -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=@gmail.com header.s=20210112 header.b=Pk9I7QN+; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229709AbiINI0X (ORCPT + 99 others); Wed, 14 Sep 2022 04:26:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbiINI0V (ORCPT ); Wed, 14 Sep 2022 04:26:21 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B371C6525D; Wed, 14 Sep 2022 01:26:20 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id jm11so14355115plb.13; Wed, 14 Sep 2022 01:26:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=i4WqWGFN996ypu86FTXwvXB/hikI0wOqqPyZaEJtfSY=; b=Pk9I7QN+hJasEV+ylLAnn7dJqAYMe00n+0NJAPi7Arcl49+qWU46huTRyJ/6g1miDI UHLfAT7GiwUwnBVezIgkd+Und4q9abZujU5mCdq0k/Frqkbm9jBJIAZUsIX6EaJpqapv AMgy7bF3S+AiAC8n3cG5najvxtQRY1YDrpYs+IaTqk3DRpikS9g6LgIDqiR7bPGQJZDU 0rqRThk1bGGSL0sqTqtXi9dSIDuya/lwoGjO9ryAb/h7OfVn6VmuUcr2Lyj35y4nlfea HcHWGWF67tVLL09vn4vCcWjWfnjqKyxUsl5p+uneutQTOHX5mQJW3XqiuWTV2o+HAXx6 dNZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=i4WqWGFN996ypu86FTXwvXB/hikI0wOqqPyZaEJtfSY=; b=qSvqO61kK1myVmblZqqVwy6IdZPeyv85Jo+dlacdWOicoWXQR6KerGNxYgoj4aq10K kXDXYorfTO5oHLMx5XP8dHSS9bMxf0pxFiZn314ffGQjfptzcbM6t5jrJVS5+rYg0V/P LBbxREYDbv0h9WHKhpZM5Zo6jHPwkDl707LOzLh95wfbUVgbZSJiWmuvTCagAdw4twvt 3mT5O4Za/a+mWDff0H/kuFwI2CXQeg61VpUAq3GQq1fuN+lcsDecQpCRrnYwjBx0h4Dm Oa8rv/uzVdSsl1ATVElOX5X3MsAGrWW9EE2aLM8Mv2seY+wPJx30NO4Wl2v0y2UW/PKH wCHg== X-Gm-Message-State: ACrzQf017U0LwiNEjaHzgYV2IBpVa1eorR2dIwnGZElnt0DlWiku5tQ3 0bAtARmmt4/Oi8yI/srxDw9mXfXtZxc= X-Received: by 2002:a17:90a:4607:b0:202:e22d:489c with SMTP id w7-20020a17090a460700b00202e22d489cmr3603534pjg.80.1663143980150; Wed, 14 Sep 2022 01:26:20 -0700 (PDT) Received: from localhost.localdomain ([2402:7500:486:362c:d94f:b1bb:6842:3424]) by smtp.gmail.com with ESMTPSA id s8-20020a17090a880800b0020036e008bcsm8683195pjn.4.2022.09.14.01.26.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Sep 2022 01:26:19 -0700 (PDT) From: cy_huang To: lee@kernel.org Cc: matthias.bgg@gmail.com, gene_chen@richtek.com, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, ChiYuan Huang , stable@vger.kernel.org Subject: [PATCH] mfd: mt6360: add bound check in regmap read/write function Date: Wed, 14 Sep 2022 16:26:13 +0800 Message-Id: <1663143973-29254-1-git-send-email-u0084500@gmail.com> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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: ChiYuan Huang Fix the potential risk for null pointer if bank index is over the maximimum. Refer to the discussion list for the experiment result on mt6370. https://lore.kernel.org/all/20220914013345.GA5802@cyhuang-hp-elitebook-840-g3.rt/ If not to check the bound, there is the same issue on mt6360. Fixes: 3b0850440a06c (mfd: mt6360: Merge different sub-devices I2C read/write) Cc: stable@vger.kernel.org Signed-off-by: ChiYuan Huang --- drivers/mfd/mt6360-core.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c index 6eaa677..d375333 100644 --- a/drivers/mfd/mt6360-core.c +++ b/drivers/mfd/mt6360-core.c @@ -410,6 +410,9 @@ static int mt6360_regmap_read(void *context, const void *reg, size_t reg_size, u8 crc; int ret; + if (bank >= MT6360_SLAVE_MAX) + return -EINVAL; + if (bank == MT6360_SLAVE_PMIC || bank == MT6360_SLAVE_LDO) { crc_needed = true; ret = mt6360_xlate_pmicldo_addr(®_addr, val_size); @@ -460,6 +463,9 @@ static int mt6360_regmap_write(void *context, const void *val, size_t val_size) int write_size = val_size - MT6360_REGMAP_REG_BYTE_SIZE; int ret; + if (bank >= MT6360_SLAVE_MAX) + return -EINVAL; + if (bank == MT6360_SLAVE_PMIC || bank == MT6360_SLAVE_LDO) { crc_needed = true; ret = mt6360_xlate_pmicldo_addr(®_addr, val_size - MT6360_REGMAP_REG_BYTE_SIZE); -- 2.7.4