* [PATCH] bus: mhi: host: Range check CHDBOFF and ERDBOFF
@ 2023-03-17 15:14 Jeffrey Hugo
2023-03-24 10:34 ` Manivannan Sadhasivam
0 siblings, 1 reply; 4+ messages in thread
From: Jeffrey Hugo @ 2023-03-17 15:14 UTC (permalink / raw)
To: mani; +Cc: mhi, linux-arm-msm, linux-kernel, Jeffrey Hugo
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(+)
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++) {
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] bus: mhi: host: Range check CHDBOFF and ERDBOFF
2023-03-17 15:14 [PATCH] bus: mhi: host: Range check CHDBOFF and ERDBOFF Jeffrey Hugo
@ 2023-03-24 10:34 ` Manivannan Sadhasivam
2023-03-24 13:50 ` Jeffrey Hugo
0 siblings, 1 reply; 4+ messages in thread
From: Manivannan Sadhasivam @ 2023-03-24 10:34 UTC (permalink / raw)
To: Jeffrey Hugo; +Cc: mhi, linux-arm-msm, linux-kernel
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
>
>
--
மணிவண்ணன் சதாசிவம்
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] bus: mhi: host: Range check CHDBOFF and ERDBOFF
2023-03-24 10:34 ` Manivannan Sadhasivam
@ 2023-03-24 13:50 ` Jeffrey Hugo
2023-03-24 14:22 ` Manivannan Sadhasivam
0 siblings, 1 reply; 4+ messages in thread
From: Jeffrey Hugo @ 2023-03-24 13:50 UTC (permalink / raw)
To: Manivannan Sadhasivam; +Cc: mhi, linux-arm-msm, linux-kernel
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
>>
>>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] bus: mhi: host: Range check CHDBOFF and ERDBOFF
2023-03-24 13:50 ` Jeffrey Hugo
@ 2023-03-24 14:22 ` Manivannan Sadhasivam
0 siblings, 0 replies; 4+ messages in thread
From: Manivannan Sadhasivam @ 2023-03-24 14:22 UTC (permalink / raw)
To: Jeffrey Hugo; +Cc: mhi, linux-arm-msm, linux-kernel
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
> > >
> > >
> >
>
--
மணிவண்ணன் சதாசிவம்
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-03-24 14:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-17 15:14 [PATCH] bus: mhi: host: Range check CHDBOFF and ERDBOFF Jeffrey Hugo
2023-03-24 10:34 ` Manivannan Sadhasivam
2023-03-24 13:50 ` Jeffrey Hugo
2023-03-24 14:22 ` Manivannan Sadhasivam
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox