Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2653498rwl; Mon, 27 Mar 2023 03:26:36 -0700 (PDT) X-Google-Smtp-Source: AK7set/5L4vL94JSq0u7XkpL2R5At82QIQT4fC+DbL5rpOzDuLa94xZSkp7eN0g5jwmpEuYIldoM X-Received: by 2002:a05:6a20:8921:b0:cd:ed5c:513 with SMTP id i33-20020a056a20892100b000cded5c0513mr7205760pzg.31.1679912795851; Mon, 27 Mar 2023 03:26:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679912795; cv=none; d=google.com; s=arc-20160816; b=BuBBn5qg/GMxQaB2jggb0Ers/UN/OcamhfC9Rsv3zxCNFQ+b0q3EhsGiPUHeN8pSMe ussW+fN3SXBcybG+1md513xtWx0pk46Jm2YRq2y7kSb7AVy3A6zTTWmaBVFSbRmtPkDJ pue3v5HQWR3zs0o4XKDnB/7L//pK/MQChc8w2fGzmbtFMUDy53QeuuLVs1DL0uUs7obd 3WJvznENUeTpUZfc0lB/PujUjgh8aCzqAUm8C+bABWUk/GzYFphf9sY2EjGElyggmnQo z+NveFGrcI+NUAmbidPvbtCXqN6yQ098B22fFv73g07llPv4fG0QQ7bvd9WbjpxtjT1Y JsVw== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=4T97RiVIu/ZqaNDq36vpljtk9AclCggxNxvgqicnCDo=; b=pFd6VGH858m4OHHfR1asW+rPFgy4sdyE31ZvN5u+03nvjQatzx0ugy2P3aT9q3ob1o YWNRelzJ/qRV+WHpEqe+L3r5L/aiHWF5ue4kVVyohITHi8667L1OtfousIcBlH98ArW6 pN3YkbcfSXAY0/zk5izpeXni0Zgr7kEG2YzlkJwE4/3QjUVmBXrZ7Zt6hrijzAssqO/0 NFwSWGQh8CyFKhMTy8HqQSFigs46fc8l1hBPSD5Hk0lgZCqPnHmP1UNNdEMnY8zCYJMQ TDpVpdcmlz9HL3JTz8iUSs34J/B1s5YpY0iezUr4WuHyHOdTPuezFHTv3OYE8xVX167g prTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Hv7zuAqo; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k66-20020a632445000000b0050f8d63a868si18509212pgk.787.2023.03.27.03.26.24; Mon, 27 Mar 2023 03:26: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=@kernel.org header.s=k20201202 header.b=Hv7zuAqo; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233324AbjC0KXf (ORCPT + 99 others); Mon, 27 Mar 2023 06:23:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233151AbjC0KXT (ORCPT ); Mon, 27 Mar 2023 06:23:19 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A26E4222; Mon, 27 Mar 2023 03:23:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id AAACECE12DA; Mon, 27 Mar 2023 10:23:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A426CC433EF; Mon, 27 Mar 2023 10:23:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679912589; bh=cznD+cbBiom3mZdOBAF5neKKYMVd/kyzeOHaPpGn7q0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Hv7zuAqo1uTMOAoGK5/bleBXMR0ApJAVGiiL3r15iEu4vABCjfjxLfp+Wyc8alcg+ DzgDI/cvMlvkBPKSSIVXGYNE9+DVx3ok757cNQ3OKCl4YDw8nAKt6yOA+E0B1sJx8/ v3CzvwlwTCffJ08BMVtmbohIHChkqijE2kEeArCaW7m6qAXFuswJ6XjsGQccRY6qaR EHl1JPR86iO8Ct0Z8QlhqlQ/+8IpvrbmHWocOLnW/cjlzzs2nYDAsKqycwmN9svEIu BwHAMWa8hhZLHIyaBVYxIEPLVOykH6VoP7FPJsIAs4UbiTYUqCMvcaSQd5Nl00Lndw SJDx+NYf3filg== Date: Mon, 27 Mar 2023 15:52:57 +0530 From: Manivannan Sadhasivam To: Jeffrey Hugo Cc: mani@kernel.org, mhi@lists.linux.dev, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2] bus: mhi: host: Range check CHDBOFF and ERDBOFF Message-ID: <20230327102257.GC16424@thinkpad> References: <1679674384-27209-1-git-send-email-quic_jhugo@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1679674384-27209-1-git-send-email-quic_jhugo@quicinc.com> X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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 On Fri, Mar 24, 2023 at 10:13:04AM -0600, Jeffrey Hugo wrote: > If the value read from the CHDBOFF and ERDBOFF registers is outside the > range of the MHI register space then an invalid address might be computed > which later causes a kernel panic. Range check the read value to prevent > a crash due to bad data from the device. > > Fixes: 6cd330ae76ff ("bus: mhi: core: Add support for ringing channel/event ring doorbells") > Cc: stable@vger.kernel.org > Signed-off-by: Jeffrey Hugo Reviewed-by: Manivannan Sadhasivam Thanks, Mani > Reviewed-by: Pranjal Ramajor Asha Kanojiya > --- > > v2: > -CC stable > -Use ERANGE for the error code > > drivers/bus/mhi/host/init.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/drivers/bus/mhi/host/init.c b/drivers/bus/mhi/host/init.c > index 3d779ee..b46a082 100644 > --- a/drivers/bus/mhi/host/init.c > +++ b/drivers/bus/mhi/host/init.c > @@ -516,6 +516,12 @@ int mhi_init_mmio(struct mhi_controller *mhi_cntrl) > return -EIO; > } > > + if (val >= mhi_cntrl->reg_len - (8 * MHI_DEV_WAKE_DB)) { > + dev_err(dev, "CHDB offset: 0x%x is out of range: 0x%zx\n", > + val, mhi_cntrl->reg_len - (8 * MHI_DEV_WAKE_DB)); > + return -ERANGE; > + } > + > /* Setup wake db */ > mhi_cntrl->wake_db = base + val + (8 * MHI_DEV_WAKE_DB); > mhi_cntrl->wake_set = false; > @@ -532,6 +538,12 @@ int mhi_init_mmio(struct mhi_controller *mhi_cntrl) > return -EIO; > } > > + if (val >= mhi_cntrl->reg_len - (8 * mhi_cntrl->total_ev_rings)) { > + dev_err(dev, "ERDB offset: 0x%x is out of range: 0x%zx\n", > + val, mhi_cntrl->reg_len - (8 * mhi_cntrl->total_ev_rings)); > + return -ERANGE; > + } > + > /* Setup event db address for each ev_ring */ > mhi_event = mhi_cntrl->mhi_event; > for (i = 0; i < mhi_cntrl->total_ev_rings; i++, val += 8, mhi_event++) { > -- > 2.7.4 > > -- மணிவண்ணன் சதாசிவம்