# \[PATCH\] HID: magicmouse: fix NULL-deref on disconnect

- Subsystems: HID CORE LAYER, THE REST
- Maintainers: Jiri Kosina, Benjamin Tissoires, Linus Torvalds
- List: linux-input
- 2 messages, 2 authors
- Page: https://ratatoskr.run/linux-input/2021/05/1379411/t

## \[PATCH\] HID: magicmouse: fix NULL-deref on disconnect

- From: Johan Hovold \<johan@kernel.org\>
- Date: 2021-05-17 10:06:22 
- Message: https://ratatoskr.run/linux-input/2021/05/1379411.md

```text
Commit 9d7b18668956 ("HID: magicmouse: add support for Apple Magic
Trackpad 2") added a sanity check for an Apple trackpad but returned
success instead of -ENODEV when the check failed. This means that the
remove callback will dereference the never-initialised driver data
pointer when the driver is later unbound (e.g. on USB disconnect).

Reported-by: <redacted>
Fixes: 9d7b18668956 ("HID: magicmouse: add support for Apple Magic Trackpad 2")
Cc: <redacted>      # 4.20
Cc: Claudio Mettler <redacted>
Cc: Marek Wyborski <redacted>
Cc: Sean O'Brien <redacted>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/hid/hid-magicmouse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index 2bb473d8c424..56dda50aa3d8 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -693,7 +693,7 @@ static int magicmouse_probe(struct hid_device *hdev,
 	if (id->vendor == USB_VENDOR_ID_APPLE &&
 	    id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 &&
 	    hdev->type != HID_TYPE_USBMOUSE)
-		return 0;
+		return -ENODEV;
 
 	msc = devm_kzalloc(&hdev->dev, sizeof(*msc), GFP_KERNEL);
 	if (msc == NULL) {
-- 
2.26.3

```

## Re: \[PATCH\] HID: magicmouse: fix NULL-deref on disconnect

- From: Jiri Kosina \<jikos@kernel.org\>
- Date: 2021-05-26 10:51:15 
- Message: https://ratatoskr.run/linux-input/2021/05/1392504.md

```text
On Mon, 17 May 2021, Johan Hovold wrote:

> Commit 9d7b18668956 ("HID: magicmouse: add support for Apple Magic
> Trackpad 2") added a sanity check for an Apple trackpad but returned
> success instead of -ENODEV when the check failed. This means that the
> remove callback will dereference the never-initialised driver data
> pointer when the driver is later unbound (e.g. on USB disconnect).
> 
> Reported-by: <redacted>
> Fixes: 9d7b18668956 ("HID: magicmouse: add support for Apple Magic Trackpad 2")
> Cc: <redacted>      # 4.20
> Cc: Claudio Mettler <redacted>
> Cc: Marek Wyborski <redacted>
> Cc: Sean O'Brien <redacted>
> Signed-off-by: Johan Hovold <johan@kernel.org>

Applied, thanks Johan.

-- 
Jiri Kosina
SUSE Labs

```
