Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp4047679pxy; Tue, 4 May 2021 16:42:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXofTmyHo6oFOXiG9ncd+ZVKq8/9kDDC74srCbd4HWnn2Du55c0ceWuHQ0cJe6na7ecrC3 X-Received: by 2002:a17:906:aac5:: with SMTP id kt5mr5039433ejb.414.1620171761574; Tue, 04 May 2021 16:42:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620171761; cv=none; d=google.com; s=arc-20160816; b=PTeLGU6+AjQUc6sHlsm5BPC7l7ywiDZn5pei5rLIKUJbKMZB6Y6fbIS4RKE2BWOOv/ nnLW19au7/0IWUt1p9HMPeF1j3dXYtamIGkwkNg6JbcYDNwV0zx+ap+0lPqJcMOwQzrW 50c8zhqdD82K4jc0HMpSB8kL3lR8qiXztP0ZdxR6SazkCcBvxIaVSj18K+nL2vfzXcEL Cz924KePOrnsnMAr4YKjSYDKYNUNf+7wjzrfQnscu7YrXA3B4KAL4muBFIhhdqn0+u// CSE5tEPc+RPIqtrQ6I/tej/iNIWLO8TLsd0MyTvAsE749mU4dClV0ySAm+4OcTiGpTMv Y/6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dmarc-filter:sender:dkim-signature; bh=2NJ2FCJ5eygsO7NmVQKBkrCnohRdJRzGE0EKHDhDgYA=; b=V9Ia3PhxjFsRl4Eh8Xro3yAlQimE7/KjsKi78go4s/1X3BBQkiQDklo7hGtR1cSVdk 19iqx+R87twroLa4dajv774CJT3sR7c0K1yexI37n6+hCR0Q5Hq/xlPtel7086S3sE7c lQGDtFmhC3CRigfsJIaWm3gmShTZtrFwS9lzl7Fp3D8r9+J4xXECUClpas4LtQgVXyok QnsdPaFUC9aWaHCuoNfg5WKXTRaGQ2RPFgRlQJk1V31xST1ewqU93UcPA5cxOAB6mnPm QoLnM21DFFOL8mmLTlPUbsxTG8WWtfkS86/8o42MCcN+9ofh2kv/GHIvAq+0y4vdcUnl sSgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=ZxWclR2c; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y3si4016689ejp.444.2021.05.04.16.42.18; Tue, 04 May 2021 16:42:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=ZxWclR2c; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231652AbhEDXjN (ORCPT + 99 others); Tue, 4 May 2021 19:39:13 -0400 Received: from m43-7.mailgun.net ([69.72.43.7]:62240 "EHLO m43-7.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231501AbhEDXjG (ORCPT ); Tue, 4 May 2021 19:39:06 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1620171490; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=2NJ2FCJ5eygsO7NmVQKBkrCnohRdJRzGE0EKHDhDgYA=; b=ZxWclR2c+o4w/lAGBNehqK7keFDIuUC0OUgS+iJhpadUCg2sO6ytr6CbBvn7qOcxGrM5iVTl MY089dWCtN7Fox0YH1pWPO7Jl1ja4bsj070gb2gKifqNBS1MzDOQZo9LiHuIUn/+ooXXJJVI IKBmQrfa/i63jRxPQl7HZntiHJs= X-Mailgun-Sending-Ip: 69.72.43.7 X-Mailgun-Sid: WyI3YTAwOSIsICJsaW51eC13aXJlbGVzc0B2Z2VyLmtlcm5lbC5vcmciLCAiYmU5ZTRhIl0= Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n06.prod.us-west-2.postgun.com with SMTP id 6091dae2f34440a9d4e2d122 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Tue, 04 May 2021 23:38:10 GMT Sender: bbhatt=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 75AC6C4338A; Tue, 4 May 2021 23:38:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00,SPF_FAIL autolearn=no autolearn_force=no version=3.4.0 Received: from malabar-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: bbhatt) by smtp.codeaurora.org (Postfix) with ESMTPSA id 89D26C43217; Tue, 4 May 2021 23:38:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 89D26C43217 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=bbhatt@codeaurora.org From: Bhaumik Bhatt To: manivannan.sadhasivam@linaro.org Cc: linux-arm-msm@vger.kernel.org, hemantk@codeaurora.org, jhugo@codeaurora.org, linux-kernel@vger.kernel.org, loic.poulain@linaro.org, linux-wireless@vger.kernel.org, kvalo@codeaurora.org, ath11k@lists.infradead.org, Bhaumik Bhatt Subject: [PATCH v2 6/6] bus: mhi: core: Add range checks for BHI and BHIe Date: Tue, 4 May 2021 16:37:58 -0700 Message-Id: <1620171478-35679-7-git-send-email-bbhatt@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1620171478-35679-1-git-send-email-bbhatt@codeaurora.org> References: <1620171478-35679-1-git-send-email-bbhatt@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org When obtaining the BHI or BHIe offsets during the power up preparation phase, range checks are missing. These can help controller drivers avoid accessing any address outside of the MMIO region. Ensure that mhi_cntrl->reg_len is set before MHI registration as it is a required field and range checks will fail without it. Signed-off-by: Bhaumik Bhatt Reviewed-by: Jeffrey Hugo --- drivers/bus/mhi/core/init.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/bus/mhi/core/init.c b/drivers/bus/mhi/core/init.c index 1cc2f22..86ad06e 100644 --- a/drivers/bus/mhi/core/init.c +++ b/drivers/bus/mhi/core/init.c @@ -885,7 +885,8 @@ int mhi_register_controller(struct mhi_controller *mhi_cntrl, if (!mhi_cntrl || !mhi_cntrl->cntrl_dev || !mhi_cntrl->regs || !mhi_cntrl->runtime_get || !mhi_cntrl->runtime_put || !mhi_cntrl->status_cb || !mhi_cntrl->read_reg || - !mhi_cntrl->write_reg || !mhi_cntrl->nr_irqs || !mhi_cntrl->irq) + !mhi_cntrl->write_reg || !mhi_cntrl->nr_irqs || + !mhi_cntrl->irq || !mhi_cntrl->reg_len) return -EINVAL; ret = parse_config(mhi_cntrl, config); @@ -1077,6 +1078,12 @@ int mhi_prepare_for_power_up(struct mhi_controller *mhi_cntrl) dev_err(dev, "Error getting BHI offset\n"); goto error_reg_offset; } + + if (bhi_off >= mhi_cntrl->reg_len) { + dev_err(dev, "BHI offset is out of range\n"); + ret = -EINVAL; + goto error_reg_offset; + } mhi_cntrl->bhi = mhi_cntrl->regs + bhi_off; if (mhi_cntrl->fbc_download || mhi_cntrl->rddm_size) { @@ -1086,6 +1093,12 @@ int mhi_prepare_for_power_up(struct mhi_controller *mhi_cntrl) dev_err(dev, "Error getting BHIE offset\n"); goto error_reg_offset; } + + if (bhie_off >= mhi_cntrl->reg_len) { + dev_err(dev, "BHIe offset is out of range\n"); + ret = -EINVAL; + goto error_reg_offset; + } mhi_cntrl->bhie = mhi_cntrl->regs + bhie_off; } -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project