Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1117973pxj; Fri, 21 May 2021 06:55:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxZ5O7qxdQG0miAgTEa8VWf6bVIddbZxQwtnaR2gx5DFvxrbYe/9q3ScIHrXxYW1w6BWmj X-Received: by 2002:a92:dcd1:: with SMTP id b17mr10517023ilr.145.1621605323289; Fri, 21 May 2021 06:55:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621605323; cv=none; d=google.com; s=arc-20160816; b=NmrWK7uzYw1DncJsSwwx5NfFzB72gXgC/Zij0n5m8os+LmsJNqSEpSGN8GECENxWRt egBjT0lKgZ6okmnv24bgxW1HXDabgakFIHxGgmqXXIMKHtahkuUY5glDian1zoeCsBgd aLnnj2Rg6P8b7dNElam9od2jPczo3L+hgOycNH5jWeZggmfmtIsW+F9S3kXIWoVDsRq2 H9z1wj3AXQQjsrkX7YoDBHIH5YcgcpIH7C6cTpmACeOPH92IL7YU61oYL3/mnBIJ0VMn Sn34Pik9jSBbEduGHxMCAjVb6pIfLfJzLwFyc3gU33uveZzeXI9Rn0sivTstOSGsrEO0 3KYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=wkGvXHvkyimelGMbBI0CIKCZGsdF+l1lKO17gNouNsA=; b=viMhUF/Pt0DFrwQ8mUYGwxFb8dl8HwP8n0G0nsLSl/N4vg5TSsXzkMpMcdLPyTM5uV VrelEZbBjQvAw+jhwUkNX+kEXQMTDzbH1Iomn/iOds+Jp+wY1qBByxggQZAPG1y3lMKy NI43NVj9dKjvf01OwN35aIto01qfEaX3husUjz/HW6657HSJWSNc3NwKFW+SjFtVCJzp eQc3jfOWajQnWpUWaNJ5RM4fFh6s2iqCPvpgbTTY0AVcYvz3xuRkmEC+J5GczpY75s9q 1gmYcdKhQ0PHAEVfYW/lUiM5ZXz06ylDqcyLK3Q1xMtMK3ir0HWfnpgJc8R+yq3oX4/S 428A== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 16si5872662ilt.35.2021.05.21.06.55.08; Fri, 21 May 2021 06:55:23 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232778AbhEUN4J (ORCPT + 99 others); Fri, 21 May 2021 09:56:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:53022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231707AbhEUN4J (ORCPT ); Fri, 21 May 2021 09:56:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 66940611AD; Fri, 21 May 2021 13:54:42 +0000 (UTC) Date: Fri, 21 May 2021 19:24:37 +0530 From: Manivannan Sadhasivam To: Bhaumik Bhatt 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 Subject: Re: [PATCH v4 6/6] bus: mhi: core: Add range checks for BHI and BHIe Message-ID: <20210521135437.GN70095@thinkpad> References: <1620330705-40192-1-git-send-email-bbhatt@codeaurora.org> <1620330705-40192-7-git-send-email-bbhatt@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1620330705-40192-7-git-send-email-bbhatt@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Thu, May 06, 2021 at 12:51:45PM -0700, Bhaumik Bhatt wrote: > 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 Reviewed-by: Manivannan Sadhasivam Thanks, Mani > --- > drivers/bus/mhi/core/init.c | 18 +++++++++++++++++- > 1 file changed, 17 insertions(+), 1 deletion(-) > > diff --git a/drivers/bus/mhi/core/init.c b/drivers/bus/mhi/core/init.c > index 1cc2f22..aeb1e3c 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,13 @@ 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: 0x%x is out of range: 0x%zx\n", > + bhi_off, mhi_cntrl->reg_len); > + 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 +1094,14 @@ 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: 0x%x is out of range: 0x%zx\n", > + bhie_off, mhi_cntrl->reg_len); > + 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 >