Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp568456pxb; Fri, 16 Apr 2021 12:24:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwn63ylBBevRoKQ0wsOxPYONIQSzgtf1KqBcoDkTOcOIMljvuIzETdp/CtdPxIu+GXrWyyt X-Received: by 2002:a17:906:5f95:: with SMTP id a21mr9767256eju.456.1618601084633; Fri, 16 Apr 2021 12:24:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618601084; cv=none; d=google.com; s=arc-20160816; b=Y/DAYfVSZNKTA2lXBgPhO+B2jlDhFnL/C9NQk3QhmCgQ/HwqozuTDTpCFanq+98hX/ 2c76I90/7t4TRA27CE4A+FyRrvPUMAWknQ5lg5CWz3a/Y9+efyGDMMuC3KDFOIRInlAR 1ETGMTIxnQNLoge2DPvj4ZTFlMIrWekE9J1YEfV3ynZ9rCUNcYdhNMjPqt/AhIym+xWT 1T2+Eh7QOVyMRy3sSGIu6pTfxuw69Pm1KY2C1FZMgIbEzgSGcjDboQPIMh7NGJYzZvE5 50THdPFaPFKDh4UhRLUNdIDVixq3Rla+VgTldmmzsFxs7Zi1Wu1XPMSIyTEsjgblccwA YsYA== 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=HkBPprzdhBmkG9CrdjIegGPcQoQXZwaAreqKX1jyOw4=; b=ZpB3Myvb2H4SFti+0gcqS9FfeCOeiVxe2SPXk+tFUwAQ7UiUjoTTbP/SJ99v0ZEyEc Si37BWywONmC1bvIYqSEstOnj8d8sgGnkcmAfqA1n4zBogUntWCOLFCoWgjNMX98/HHD vnOnN35wY8w3qKWUTmnk1NUbni7XWSy0wXjlpdA+kUQ6t9V8DffeH0aQMyjgqK8QV8+p i9c15QXvCHY2pvN9IcVq/BkcN7tp3E5Kh783EKWK1BubAGv6ssxiBt8xxaw2BbcPL1ni r78w/vxbhXA0Y0NweKMhxnmT4nrsIcoayJEr1fQbafXHQVAlfy/6GFGBnis6wbqTDCCa Q60Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=VHKi6tyR; 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 d21si5344460ejm.343.2021.04.16.12.24.21; Fri, 16 Apr 2021 12:24:44 -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=VHKi6tyR; 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 S245392AbhDPSsB (ORCPT + 99 others); Fri, 16 Apr 2021 14:48:01 -0400 Received: from m43-7.mailgun.net ([69.72.43.7]:34781 "EHLO m43-7.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245287AbhDPSr7 (ORCPT ); Fri, 16 Apr 2021 14:47:59 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1618598854; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=HkBPprzdhBmkG9CrdjIegGPcQoQXZwaAreqKX1jyOw4=; b=VHKi6tyRgF0Sl7s2KlJGrI2IrqMWzohqxzlB4s8nE8qQDwbFnyAfXcQ39xfiQE/axZnXUPo3 y13sBtE0sHX7Fl1azgLw3apP5DBf1AF86TDBnLsXgcY52zKftZ2jagB4+nf1TVazGdoxJBjH g9tfEctBPIFghTLks+fdHHG0kIw= 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-n07.prod.us-west-2.postgun.com with SMTP id 6079dbb92cc44d3aeaf2c73f (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Fri, 16 Apr 2021 18:47:21 GMT Sender: bbhatt=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id DEDA4C4346B; Fri, 16 Apr 2021 18:47:20 +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, URIBL_BLOCKED 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 E9A6BC43465; Fri, 16 Apr 2021 18:47:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org E9A6BC43465 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 v1 6/6] bus: mhi: core: Add range checks for BHI and BHIe Date: Fri, 16 Apr 2021 11:47:05 -0700 Message-Id: <1618598825-18629-7-git-send-email-bbhatt@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1618598825-18629-1-git-send-email-bbhatt@codeaurora.org> References: <1618598825-18629-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 --- 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