All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] HID: rmi: Check that the RMI_STARTED bit is set before unregistering the RMI transport device
@ 2019-10-23  1:24 Andrew Duggan
  2019-10-23  1:24 ` [PATCH] Input: synaptics-rmi4 - validate that the rmi_dev pointer is set before dereferencing it Andrew Duggan
  2019-11-15 15:26 ` [PATCH] HID: rmi: Check that the RMI_STARTED bit is set before unregistering the RMI transport device Jiri Kosina
  0 siblings, 2 replies; 7+ messages in thread
From: Andrew Duggan @ 2019-10-23  1:24 UTC (permalink / raw)
  To: linux-input, linux-kernel
  Cc: Andrew Duggan, Jiri Kosina, Benjamin Tissoires, Federico Cerutti,
	Christopher Heiny, Dmitry Torokhov

In the event that the RMI device is unreachable, the calls to
rmi_set_mode() or rmi_set_page() will fail before registering the RMI
transport device. When the device is removed, rmi_remove() will call
rmi_unregister_transport_device() which will attempt to access the
rmi_dev pointer which was not set. This patch adds a check of the
RMI_STARTED bit before calling rmi_unregister_transport_device().
The RMI_STARTED bit is only set after rmi_register_transport_device()
completes successfully. A subsequent patch in the RMI core will add
checks to validate the pointers before accessing them.

The kernel oops was reported in this message:
https://www.spinics.net/lists/linux-input/msg58433.html

Signed-off-by: Andrew Duggan <aduggan@synaptics.com>
Reported-by: Federico Cerutti <federico@ceres-c.it>
---
 drivers/hid/hid-rmi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/hid-rmi.c b/drivers/hid/hid-rmi.c
index 7c6abd7e0979..9ce22acdfaca 100644
--- a/drivers/hid/hid-rmi.c
+++ b/drivers/hid/hid-rmi.c
@@ -744,7 +744,8 @@ static void rmi_remove(struct hid_device *hdev)
 {
 	struct rmi_data *hdata = hid_get_drvdata(hdev);
 
-	if (hdata->device_flags & RMI_DEVICE) {
+	if ((hdata->device_flags & RMI_DEVICE)
+	    && test_bit(RMI_STARTED, &hdata->flags)) {
 		clear_bit(RMI_STARTED, &hdata->flags);
 		cancel_work_sync(&hdata->reset_work);
 		rmi_unregister_transport_device(&hdata->xport);
-- 
2.20.1


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

* [PATCH] Input: synaptics-rmi4 - validate that the rmi_dev pointer is set before dereferencing it
  2019-10-23  1:24 [PATCH] HID: rmi: Check that the RMI_STARTED bit is set before unregistering the RMI transport device Andrew Duggan
@ 2019-10-23  1:24 ` Andrew Duggan
  2019-10-29  4:19   ` Dmitry Torokhov
  2019-11-15 15:26 ` [PATCH] HID: rmi: Check that the RMI_STARTED bit is set before unregistering the RMI transport device Jiri Kosina
  1 sibling, 1 reply; 7+ messages in thread
From: Andrew Duggan @ 2019-10-23  1:24 UTC (permalink / raw)
  To: linux-input, linux-kernel
  Cc: Andrew Duggan, Jiri Kosina, Benjamin Tissoires, Federico Cerutti,
	Christopher Heiny, Dmitry Torokhov

A bug in hid-rmi was causing rmi_unregister_transport_device() to be
called even if the call to rmi_register_transport_device() failed to
allocate the rmi device. A patch has been submitted to fix the issue in
hid-rmi. This patch will ensure that should a simialr situation
occur then the rmi driver will not dereference a NULL pointer.

Signed-off-by: Andrew Duggan <aduggan@synaptics.com>
---
 drivers/input/rmi4/rmi_bus.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/input/rmi4/rmi_bus.c b/drivers/input/rmi4/rmi_bus.c
index af706a583656..6c3abae1e159 100644
--- a/drivers/input/rmi4/rmi_bus.c
+++ b/drivers/input/rmi4/rmi_bus.c
@@ -118,8 +118,10 @@ void rmi_unregister_transport_device(struct rmi_transport_dev *xport)
 {
 	struct rmi_device *rmi_dev = xport->rmi_dev;
 
-	device_del(&rmi_dev->dev);
-	put_device(&rmi_dev->dev);
+	if (rmi_dev) {
+		device_del(&rmi_dev->dev);
+		put_device(&rmi_dev->dev);
+	}
 }
 EXPORT_SYMBOL(rmi_unregister_transport_device);
 
-- 
2.20.1


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

* Re: [PATCH] Input: synaptics-rmi4 - validate that the rmi_dev pointer is set before dereferencing it
  2019-10-23  1:24 ` [PATCH] Input: synaptics-rmi4 - validate that the rmi_dev pointer is set before dereferencing it Andrew Duggan
@ 2019-10-29  4:19   ` Dmitry Torokhov
  2019-10-29 18:40     ` Andrew Duggan
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Torokhov @ 2019-10-29  4:19 UTC (permalink / raw)
  To: Andrew Duggan
  Cc: linux-input, linux-kernel, Jiri Kosina, Benjamin Tissoires,
	Federico Cerutti, Christopher Heiny

Hi Andrew,

On Wed, Oct 23, 2019 at 01:24:05AM +0000, Andrew Duggan wrote:
> A bug in hid-rmi was causing rmi_unregister_transport_device() to be
> called even if the call to rmi_register_transport_device() failed to
> allocate the rmi device. A patch has been submitted to fix the issue in
> hid-rmi. This patch will ensure that should a simialr situation
> occur then the rmi driver will not dereference a NULL pointer.

This looks like "garbage in, garbage out" problem where we should not be
calling unregister in the first place. I'd rather not apply this.

Thanks.

-- 
Dmitry

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

* Re: [PATCH] Input: synaptics-rmi4 - validate that the rmi_dev pointer is set before dereferencing it
  2019-10-29  4:19   ` Dmitry Torokhov
@ 2019-10-29 18:40     ` Andrew Duggan
  0 siblings, 0 replies; 7+ messages in thread
From: Andrew Duggan @ 2019-10-29 18:40 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: linux-input, linux-kernel, Jiri Kosina, Benjamin Tissoires,
	Federico Cerutti, Christopher Heiny

Hi Dmitry,

On 10/28/19 9:19 PM, Dmitry Torokhov wrote:
> CAUTION: Email originated externally, do not click links or open attachments unless you recognize the sender and know the content is safe.
>
>
> Hi Andrew,
>
> On Wed, Oct 23, 2019 at 01:24:05AM +0000, Andrew Duggan wrote:
>> A bug in hid-rmi was causing rmi_unregister_transport_device() to be
>> called even if the call to rmi_register_transport_device() failed to
>> allocate the rmi device. A patch has been submitted to fix the issue in
>> hid-rmi. This patch will ensure that should a simialr situation
>> occur then the rmi driver will not dereference a NULL pointer.
> This looks like "garbage in, garbage out" problem where we should not be
> calling unregister in the first place. I'd rather not apply this.

That's fine, like I said the actual fix to prevent 
rmi_unregister_transport_device() from being called inappropriately is 
in the hid-rmi driver.

https://lore.kernel.org/linux-input/20191023012344.20998-1-aduggan@synaptics.com/

I was on the fence on whether or not it was better to prevent the NULL 
pointer dereference even at the expense of masking bugs like the one in 
the hid-rmi driver.

Thanks for the feedback,

Andrew


> Thanks.
>
> --
> Dmitry

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

* Re: [PATCH] HID: rmi: Check that the RMI_STARTED bit is set before unregistering the RMI transport device
  2019-10-23  1:24 [PATCH] HID: rmi: Check that the RMI_STARTED bit is set before unregistering the RMI transport device Andrew Duggan
  2019-10-23  1:24 ` [PATCH] Input: synaptics-rmi4 - validate that the rmi_dev pointer is set before dereferencing it Andrew Duggan
@ 2019-11-15 15:26 ` Jiri Kosina
  2019-11-15 18:18   ` Andrew Duggan
  1 sibling, 1 reply; 7+ messages in thread
From: Jiri Kosina @ 2019-11-15 15:26 UTC (permalink / raw)
  To: Andrew Duggan
  Cc: linux-input, linux-kernel, Benjamin Tissoires, Federico Cerutti,
	Christopher Heiny, Dmitry Torokhov

On Wed, 23 Oct 2019, Andrew Duggan wrote:

> In the event that the RMI device is unreachable, the calls to
> rmi_set_mode() or rmi_set_page() will fail before registering the RMI
> transport device. When the device is removed, rmi_remove() will call
> rmi_unregister_transport_device() which will attempt to access the
> rmi_dev pointer which was not set. This patch adds a check of the
> RMI_STARTED bit before calling rmi_unregister_transport_device().
> The RMI_STARTED bit is only set after rmi_register_transport_device()
> completes successfully. A subsequent patch in the RMI core will add
> checks to validate the pointers before accessing them.

Andrew,

my mailbox doesn't seem to have that 'subsequent patch' ... was it ever 
sent and I missed it? If so, could you please resend it?

Thanks,

-- 
Jiri Kosina
SUSE Labs


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

* Re: [PATCH] HID: rmi: Check that the RMI_STARTED bit is set before unregistering the RMI transport device
  2019-11-15 15:26 ` [PATCH] HID: rmi: Check that the RMI_STARTED bit is set before unregistering the RMI transport device Jiri Kosina
@ 2019-11-15 18:18   ` Andrew Duggan
  2019-11-18  9:24     ` Jiri Kosina
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Duggan @ 2019-11-15 18:18 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: linux-input, linux-kernel, Benjamin Tissoires, Federico Cerutti,
	Christopher Heiny, Dmitry Torokhov

Hi Jiri,

On 11/15/19 7:26 AM, Jiri Kosina wrote:
> On Wed, 23 Oct 2019, Andrew Duggan wrote:
>
>> In the event that the RMI device is unreachable, the calls to
>> rmi_set_mode() or rmi_set_page() will fail before registering the RMI
>> transport device. When the device is removed, rmi_remove() will call
>> rmi_unregister_transport_device() which will attempt to access the
>> rmi_dev pointer which was not set. This patch adds a check of the
>> RMI_STARTED bit before calling rmi_unregister_transport_device().
>> The RMI_STARTED bit is only set after rmi_register_transport_device()
>> completes successfully. A subsequent patch in the RMI core will add
>> checks to validate the pointers before accessing them.
> Andrew,
>
> my mailbox doesn't seem to have that 'subsequent patch' ... was it ever
> sent and I missed it? If so, could you please resend it?

The subsequent patch which I was referring to is:

https://lore.kernel.org/linux-input/20191023012344.20998-2-aduggan@synaptics.com/

Since this second patch was for the input subsystem I decided to just 
make them separate patches instead of creating a series. However, based 
on Dmitry's feedback it was determined that the second patch wasn't a 
good idea and it won't be applied. This first patch is enough to fix the 
issue by preventing the call to rmi_unregister_transport_device() if the 
subsequent call to register failed. The only change I would make to this 
patch would be to remove the last sentence of the comment. If you choose 
to apply that patch then would this be a change you would make? Or would 
you prefer I submit a v2 with this update?

Thanks,

Andrew


> Thanks,
>
> --
> Jiri Kosina
> SUSE Labs
>

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

* Re: [PATCH] HID: rmi: Check that the RMI_STARTED bit is set before unregistering the RMI transport device
  2019-11-15 18:18   ` Andrew Duggan
@ 2019-11-18  9:24     ` Jiri Kosina
  0 siblings, 0 replies; 7+ messages in thread
From: Jiri Kosina @ 2019-11-18  9:24 UTC (permalink / raw)
  To: Andrew Duggan
  Cc: linux-input, linux-kernel, Benjamin Tissoires, Federico Cerutti,
	Christopher Heiny, Dmitry Torokhov

On Fri, 15 Nov 2019, Andrew Duggan wrote:

> Since this second patch was for the input subsystem I decided to just 
> make them separate patches instead of creating a series. However, based 
> on Dmitry's feedback it was determined that the second patch wasn't a 
> good idea and it won't be applied. This first patch is enough to fix the 
> issue by preventing the call to rmi_unregister_transport_device() if the 
> subsequent call to register failed. The only change I would make to this 
> patch would be to remove the last sentence of the comment. If you choose 
> to apply that patch then would this be a change you would make? Or would 
> you prefer I submit a v2 with this update?

I've modified the changelog and applied. Thanks,

-- 
Jiri Kosina
SUSE Labs


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

end of thread, other threads:[~2019-11-18  9:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-23  1:24 [PATCH] HID: rmi: Check that the RMI_STARTED bit is set before unregistering the RMI transport device Andrew Duggan
2019-10-23  1:24 ` [PATCH] Input: synaptics-rmi4 - validate that the rmi_dev pointer is set before dereferencing it Andrew Duggan
2019-10-29  4:19   ` Dmitry Torokhov
2019-10-29 18:40     ` Andrew Duggan
2019-11-15 15:26 ` [PATCH] HID: rmi: Check that the RMI_STARTED bit is set before unregistering the RMI transport device Jiri Kosina
2019-11-15 18:18   ` Andrew Duggan
2019-11-18  9:24     ` Jiri Kosina

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.