Message ID | 1679066059-8399-1-git-send-email-quic_jhugo@quicinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp403726wrt; Fri, 17 Mar 2023 08:27:52 -0700 (PDT) X-Google-Smtp-Source: AK7set9nkOMeSrRWAzM2sF66NYim46UXtJ1zVLmHe4xvN+u8R/wPr3ZwdGYF58IjdIv3I2MB1k5c X-Received: by 2002:a05:6a20:6914:b0:d7:3c1a:6c9a with SMTP id q20-20020a056a20691400b000d73c1a6c9amr5557650pzj.4.1679066871818; Fri, 17 Mar 2023 08:27:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679066871; cv=none; d=google.com; s=arc-20160816; b=ohPHkfnepnyvVraF6zNavS28a53DVXlAQqEhtC2eAsPPhVtqiWfUkDH+a6i2RgTAhO 5dmm91N1QxueB8ejxnyKP03Esz1VhYfD7QIQZmmwoYewEL4IIJxQ6NN7VUeRZZv+SnPv hAWEy+dgVnwQvMSXYwN9++U64PXxGRFkZkpTqS5fQmhKNj5sxV7sqGhDufY50APNcpi0 YG7lg2A8DECSxbshbcHmG6PqdqUsuFgK4puAJlzcDIMuo2Zqzkwj8BT0GUUowzsYRUhS E6VRkUgN5vsc9aKUuWdD8LWOueoB53bi7XZ1dT2JdnoZabbilOrtA5OLFld4A6HtFcuY RxEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=8ijszwjv44e5NjQhRxjTHZb02NugQYjiyLDTec+Eoeg=; b=dXRXl/LF9711kQQLy0UTq9u76UDdcltLs0R58OzZqiTyIKvUyD/F267B1DsywbGW9g WAp18C0ujnnwSh7k1Yf5VNo/vjJTNJOUNqLuJal8JYgWy3KjAbLES3tke4SWVPAwGufJ cNi91VyWzCXTg+nLe2iqYu5z8LkoQ2X1JHQsGjdWO4VuH6+L8Xb+yg8eBBmMqetzz4jJ mDe0F5sWhH1mdn1FmptoX/Tym1pwTokMWY99tEsL4iP3iNe1Sl1cc8kTRcONydceD0vf WHnVBh6wUR3hBuxnu1uD6wz1ONzsaiWW3v1R4uYeGRvJEuxh4O0vw0IqEKoZeE8nv/jv LWuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=eNKmMsrp; 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=quicinc.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ha4-20020a17090af3c400b00237413f8c6esi6551742pjb.154.2023.03.17.08.27.36; Fri, 17 Mar 2023 08:27:51 -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=@quicinc.com header.s=qcppdkim1 header.b=eNKmMsrp; 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=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231627AbjCQPPR (ORCPT <rfc822;chrisfriedt@gmail.com> + 99 others); Fri, 17 Mar 2023 11:15:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230188AbjCQPOx (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 17 Mar 2023 11:14:53 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A01CF421C; Fri, 17 Mar 2023 08:14:50 -0700 (PDT) Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32H7Y1dg024346; Fri, 17 Mar 2023 15:14:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=8ijszwjv44e5NjQhRxjTHZb02NugQYjiyLDTec+Eoeg=; b=eNKmMsrpF1ifkyzgsRsqoEyQIfqE5PYBIsDFMcVDKL31rrBT5B79pkAJsFXCjm6DUpUv HTpxiuxOjVIWgpO8pu1COTbwfcl9Fk5NBtglEU/Hti8IKsBQBd8eU5xvv7mfAsQFrzq/ b6DMcfDy/vpk3LhdUwSTBfVNfXu3TOAjWsJuJmCFG53739UinGbr9TS8/xBMu3vel8Pn ZDbOh4P3TfOBoYeOlc2RxQDH9/JWYVcAgxqzTwmrxev3RTdhiNQy6jywzIlndFXAKyJa anz10ogvxVBf2BXzws74ER6RTlwJTRozOUnsxPmjYRk19wGsHkGTGskquV012klaMRpi jw== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3pc3ypbxwf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Mar 2023 15:14:38 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 32HFEbad003725 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Mar 2023 15:14:37 GMT Received: from jhugo-lnx.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Fri, 17 Mar 2023 08:14:36 -0700 From: Jeffrey Hugo <quic_jhugo@quicinc.com> To: <mani@kernel.org> CC: <mhi@lists.linux.dev>, <linux-arm-msm@vger.kernel.org>, <linux-kernel@vger.kernel.org>, Jeffrey Hugo <quic_jhugo@quicinc.com> Subject: [PATCH] bus: mhi: host: Range check CHDBOFF and ERDBOFF Date: Fri, 17 Mar 2023 09:14:19 -0600 Message-ID: <1679066059-8399-1-git-send-email-quic_jhugo@quicinc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: WekpdTnu3wqu5W6dgV6bgJseax8SXZuL X-Proofpoint-ORIG-GUID: WekpdTnu3wqu5W6dgV6bgJseax8SXZuL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-17_10,2023-03-16_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 priorityscore=1501 mlxscore=0 suspectscore=0 bulkscore=0 phishscore=0 adultscore=0 impostorscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303170104 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760629224118054351?= X-GMAIL-MSGID: =?utf-8?q?1760629224118054351?= |
Series |
bus: mhi: host: Range check CHDBOFF and ERDBOFF
|
|
Commit Message
Jeffrey Hugo
March 17, 2023, 3:14 p.m. UTC
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") Signed-off-by: Jeffrey Hugo <quic_jhugo@quicinc.com> Reviewed-by: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com> --- drivers/bus/mhi/host/init.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
Comments
On Fri, Mar 17, 2023 at 09:14:19AM -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") Please CC stable list. > Signed-off-by: Jeffrey Hugo <quic_jhugo@quicinc.com> > Reviewed-by: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com> > --- > 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..ae8ebcfb 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 -EINVAL; Isn't -ERANGE a better errno here and also in other places of the driver? Thanks, Mani > + } > + > /* 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 -EINVAL; > + } > + > /* 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 > >
On 3/24/2023 4:34 AM, Manivannan Sadhasivam wrote: > On Fri, Mar 17, 2023 at 09:14:19AM -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") > > Please CC stable list. The stable folks have been automatically picking up everything with a fixes tag for years. CCing the stable list does not seem to do anything unless the patch needs specific backporting adjustments. Do you still want an explicit CC? > >> Signed-off-by: Jeffrey Hugo <quic_jhugo@quicinc.com> >> Reviewed-by: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com> >> --- >> 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..ae8ebcfb 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 -EINVAL; > > Isn't -ERANGE a better errno here and also in other places of the driver? I suppose that could work. This was modeled after the existing BHI (eg BHIOFF) range checks. You want those updated in the same change or a separate one? > Thanks, > Mani > >> + } >> + >> /* 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 -EINVAL; >> + } >> + >> /* 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 >> >> >
On Fri, Mar 24, 2023 at 07:50:01AM -0600, Jeffrey Hugo wrote: > On 3/24/2023 4:34 AM, Manivannan Sadhasivam wrote: > > On Fri, Mar 17, 2023 at 09:14:19AM -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") > > > > Please CC stable list. > > The stable folks have been automatically picking up everything with a fixes > tag for years. CCing the stable list does not seem to do anything unless > the patch needs specific backporting adjustments. > > Do you still want an explicit CC? > That was the impression I had but Greg wanted us to explicitly CC stable list and add a hint about how deep the patch needs to be applied. > > > > > Signed-off-by: Jeffrey Hugo <quic_jhugo@quicinc.com> > > > Reviewed-by: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com> > > > --- > > > 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..ae8ebcfb 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 -EINVAL; > > > > Isn't -ERANGE a better errno here and also in other places of the driver? > > I suppose that could work. This was modeled after the existing BHI (eg > BHIOFF) range checks. You want those updated in the same change or a > separate one? > That can go into a separate change. Thanks, Mani > > Thanks, > > Mani > > > > > + } > > > + > > > /* 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 -EINVAL; > > > + } > > > + > > > /* 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 > > > > > > > > >
diff --git a/drivers/bus/mhi/host/init.c b/drivers/bus/mhi/host/init.c index 3d779ee..ae8ebcfb 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 -EINVAL; + } + /* 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 -EINVAL; + } + /* 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++) {