linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] HID: i2c-hid-of: fix NULL-deref on failed power up
@ 2024-01-26 17:09 Johan Hovold
  2024-01-26 17:47 ` Doug Anderson
  0 siblings, 1 reply; 4+ messages in thread
From: Johan Hovold @ 2024-01-26 17:09 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires
  Cc: linux-input, linux-kernel, Johan Hovold, stable, Douglas Anderson

A while back the I2C HID implementation was split in an ACPI and OF
part, but the new OF driver never initialises the client pointer which
is dereferenced on power-up failures.

Fixes: b33752c30023 ("HID: i2c-hid: Reorganize so ACPI and OF are separate modules")
Cc: stable@vger.kernel.org      # 5.12
Cc: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
---
 drivers/hid/i2c-hid/i2c-hid-of.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/hid/i2c-hid/i2c-hid-of.c b/drivers/hid/i2c-hid/i2c-hid-of.c
index c4e1fa0273c8..8be4d576da77 100644
--- a/drivers/hid/i2c-hid/i2c-hid-of.c
+++ b/drivers/hid/i2c-hid/i2c-hid-of.c
@@ -87,6 +87,7 @@ static int i2c_hid_of_probe(struct i2c_client *client)
 	if (!ihid_of)
 		return -ENOMEM;
 
+	ihid_of->client = client;
 	ihid_of->ops.power_up = i2c_hid_of_power_up;
 	ihid_of->ops.power_down = i2c_hid_of_power_down;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] HID: i2c-hid-of: fix NULL-deref on failed power up
  2024-01-26 17:09 [PATCH] HID: i2c-hid-of: fix NULL-deref on failed power up Johan Hovold
@ 2024-01-26 17:47 ` Doug Anderson
  2024-01-26 17:53   ` Jiri Kosina
  2024-02-01  9:55   ` Johan Hovold
  0 siblings, 2 replies; 4+ messages in thread
From: Doug Anderson @ 2024-01-26 17:47 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel,
	stable

Hi,

On Fri, Jan 26, 2024 at 9:10 AM Johan Hovold <johan+linaro@kernel.org> wrote:
>
> A while back the I2C HID implementation was split in an ACPI and OF
> part, but the new OF driver never initialises the client pointer which
> is dereferenced on power-up failures.
>
> Fixes: b33752c30023 ("HID: i2c-hid: Reorganize so ACPI and OF are separate modules")
> Cc: stable@vger.kernel.org      # 5.12
> Cc: Douglas Anderson <dianders@chromium.org>
> Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
> ---
>  drivers/hid/i2c-hid/i2c-hid-of.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/hid/i2c-hid/i2c-hid-of.c b/drivers/hid/i2c-hid/i2c-hid-of.c
> index c4e1fa0273c8..8be4d576da77 100644
> --- a/drivers/hid/i2c-hid/i2c-hid-of.c
> +++ b/drivers/hid/i2c-hid/i2c-hid-of.c
> @@ -87,6 +87,7 @@ static int i2c_hid_of_probe(struct i2c_client *client)
>         if (!ihid_of)
>                 return -ENOMEM;
>
> +       ihid_of->client = client;

Good catch and thanks for the fix. FWIW, I'd be OK w/

Reviewed-by: Douglas Anderson <dianders@chromium.org>

That being said, I'd be even happier if you simply removed the
"client" from the structure and removed the error printout.
regulator_bulk_enable() already prints error messages when a failure
happens and thus the error printout is redundant and wastes space.

-Doug

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] HID: i2c-hid-of: fix NULL-deref on failed power up
  2024-01-26 17:47 ` Doug Anderson
@ 2024-01-26 17:53   ` Jiri Kosina
  2024-02-01  9:55   ` Johan Hovold
  1 sibling, 0 replies; 4+ messages in thread
From: Jiri Kosina @ 2024-01-26 17:53 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Johan Hovold, Benjamin Tissoires, linux-input, linux-kernel,
	stable

On Fri, 26 Jan 2024, Doug Anderson wrote:

> > A while back the I2C HID implementation was split in an ACPI and OF
> > part, but the new OF driver never initialises the client pointer which
> > is dereferenced on power-up failures.
> >
> > Fixes: b33752c30023 ("HID: i2c-hid: Reorganize so ACPI and OF are separate modules")
> > Cc: stable@vger.kernel.org      # 5.12
> > Cc: Douglas Anderson <dianders@chromium.org>
> > Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
> > ---
> >  drivers/hid/i2c-hid/i2c-hid-of.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/hid/i2c-hid/i2c-hid-of.c b/drivers/hid/i2c-hid/i2c-hid-of.c
> > index c4e1fa0273c8..8be4d576da77 100644
> > --- a/drivers/hid/i2c-hid/i2c-hid-of.c
> > +++ b/drivers/hid/i2c-hid/i2c-hid-of.c
> > @@ -87,6 +87,7 @@ static int i2c_hid_of_probe(struct i2c_client *client)
> >         if (!ihid_of)
> >                 return -ENOMEM;
> >
> > +       ihid_of->client = client;
> 
> Good catch and thanks for the fix. FWIW, I'd be OK w/
> 
> Reviewed-by: Douglas Anderson <dianders@chromium.org>

I've now queued this as a fix for 6.8 ....

> That being said, I'd be even happier if you simply removed the "client" 
> from the structure and removed the error printout. 
> regulator_bulk_enable() already prints error messages when a failure 
> happens and thus the error printout is redundant and wastes space.

... and this can be done for 6.9.

Thanks,

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] HID: i2c-hid-of: fix NULL-deref on failed power up
  2024-01-26 17:47 ` Doug Anderson
  2024-01-26 17:53   ` Jiri Kosina
@ 2024-02-01  9:55   ` Johan Hovold
  1 sibling, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2024-02-01  9:55 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Johan Hovold, Jiri Kosina, Benjamin Tissoires, linux-input,
	linux-kernel, stable

On Fri, Jan 26, 2024 at 09:47:23AM -0800, Doug Anderson wrote:
> On Fri, Jan 26, 2024 at 9:10 AM Johan Hovold <johan+linaro@kernel.org> wrote:

> > A while back the I2C HID implementation was split in an ACPI and OF
> > part, but the new OF driver never initialises the client pointer which
> > is dereferenced on power-up failures.

> Good catch and thanks for the fix. FWIW, I'd be OK w/
> 
> Reviewed-by: Douglas Anderson <dianders@chromium.org>
> 
> That being said, I'd be even happier if you simply removed the
> "client" from the structure and removed the error printout.
> regulator_bulk_enable() already prints error messages when a failure
> happens and thus the error printout is redundant and wastes space.

True, but that error message does not include the device that tried to
use the regulator.

I actually hit this when adding dev_dbg() to the function in question.
For such cases, it's also convenient to have struct device easily
accessible so I think it should be ok to just leave this pointer in.

Johan

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-02-01  9:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-26 17:09 [PATCH] HID: i2c-hid-of: fix NULL-deref on failed power up Johan Hovold
2024-01-26 17:47 ` Doug Anderson
2024-01-26 17:53   ` Jiri Kosina
2024-02-01  9:55   ` Johan Hovold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).