Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4069775rwl; Sun, 2 Apr 2023 22:19:20 -0700 (PDT) X-Google-Smtp-Source: AKy350YYuQrIGFxbuq6Hwo25maPflJCbDyabQP3dSJrIBi4+ArZFdM0Ck8C8765qimRB6TtwgRcm X-Received: by 2002:aa7:9f47:0:b0:628:184f:2c5 with SMTP id h7-20020aa79f47000000b00628184f02c5mr33192845pfr.14.1680499159738; Sun, 02 Apr 2023 22:19:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680499159; cv=none; d=google.com; s=arc-20160816; b=oDpgFHpC2ojDP0UtAji1dDv/fQ5HmVcuC+rfiQ7bS3rc9b/mJhPMvX829xu6Hxd6ce 6jTM+SRkUaHvSM+gMauV6E4VRk3UjHSGGxZ17vwu9bQtS07nfU/onJ+wm7uANmXA0Xap zXffgmY9IdAiy1K7GZg+SMS33xNMRokghG52Ssh0bR/Obskj8YnbNGkxG44tABe/NdBD 24HdMwIPHvWjPE+q56IFfvHBica3zH0JN0Q2KxqtyeUw+Kqz/apcdnYwkKjAAZqdydwM wS3JhUU824nHLOx+QNuj1QkSBRBaus/Fnd/VgbGtc2sq+/QCPKrKI+iFqsvOF5cWYB58 Bn3A== 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=SNdUayg4onZgHGqpeiNKKeX6PDKaOAArZTeIVpBxiQI=; b=BPsuyZXpVuDJozeOpIhqbzCV1kAA2AJZQSz3sw8050hFcAmBXYPkqMMbxCsRo/3dsE ktgxN6vngriAWIXd7EkSmiYWPSLcefPysc7hKJ5RhCB2geE9TzJyLIRLOX1ImIVax2t8 OLUybsDFJI3N5EUBAcRiQeoXD8GQ+g1sjc/OvCRfqiK+XjvSP45vrh1ort/3otfiifvz KuSiHy37r25e+eY4EZxNHYr9jlHcZsp6M1aFbubxWw0uz3kXJ1OJuFfA0ehaLS6rWPzI Mgee6Fq0DEKX3wTjvftxYWXsFBwYC34JJQnqLfykIEoHwYiYocMgI2jmOhPVNzVhhtPS r8VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="j/QRGMOc"; 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 z10-20020aa79e4a000000b005a8da0b042bsi7498185pfq.378.2023.04.02.22.19.08; Sun, 02 Apr 2023 22:19:19 -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="j/QRGMOc"; 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 S231425AbjDCFRZ (ORCPT + 99 others); Mon, 3 Apr 2023 01:17:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229751AbjDCFRY (ORCPT ); Mon, 3 Apr 2023 01:17:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87967AF1A; Sun, 2 Apr 2023 22:17:23 -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 ams.source.kernel.org (Postfix) with ESMTPS id 0BEECB80ED6; Mon, 3 Apr 2023 05:17:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0495FC433D2; Mon, 3 Apr 2023 05:17:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680499040; bh=g2TSS6m0UMtjThk7tJNAadrmxBfJBuYpYI2CML4irS0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=j/QRGMOcuaDDa2RhAQeD9MHMeuqXNqS23ZE/TWoO2ArLqF+WKfeWlC3RzppXrS9fo sm8AFyrw7xyv7HCHp8+vdvZ2J+Dx8P/7XNYrS9wa/otAv8huW2YSVQw88p0A1tOgt7 U1uYv35/CqW77ve5hwCzb/0Gt/5sfqXQ0/2qBe1nvTYyJ+sshEcyMHl3IkOFe5/gbd lagS1wWq/xYZvi1B2Xl8bc/QfdR+nYTcVjkitsLCqRPDm8W0kQyXmYqGksa4OvF5Ir EoPJZ+U9DD+4n+h54TzHSVSoqMpo8k+SaYAA1GMiNSlJd2ZrpVh9q3KIqzRrnZb0JP p2AQ0PXp5lqJw== Date: Mon, 3 Apr 2023 10:47:15 +0530 From: Manivannan Sadhasivam To: Jeffrey Hugo Cc: 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: <20230403051715.GB4627@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 Applied to mhi-next! - 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 > -- மணிவண்ணன் சதாசிவம்