All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dongliang Mu <dzm91@hust.edu.cn>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Pavel Rojtberg <rojtberg@gmail.com>, Vicki Pfau <vi@endrift.com>,
	Nate Yocom <nate@yocom.org>,
	Mattijs Korpershoek <mkorpershoek@baylibre.com>,
	John Butler <radon86dev@gmail.com>,
	Matthias Benkmann <matthias.benkmann@gmail.com>,
	Christopher Crockett <chaorace@gmail.com>,
	Santosh De Massari <s.demassari@gmail.com>
Cc: hust-os-kernel-patches@googlegroups.com,
	Dongliang Mu <dzm91@hust.edu.cn>,
	syzbot+a3f758b8d8cb7e49afec@syzkaller.appspotmail.com,
	"Pierre-Loup A. Griffais" <pgriffais@valvesoftware.com>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] Input: xpad - fix GPF in xpad_probe
Date: Fri, 14 Apr 2023 20:55:47 +0800	[thread overview]
Message-ID: <20230414125603.686123-1-dzm91@hust.edu.cn> (raw)

In xpad_probe(), it does not allocate xpad->dev with input_dev type.
Then, when it invokes dev_warn with 1st argument - &xpad->dev->dev, it
would trigger GPF.

Fix this by allocating xpad->dev, its error handling and cleanup
operations in the remove function.

Note that this crash does not have any reproducer, so the patch
only passes compilation testing.

Reported-by: syzbot+a3f758b8d8cb7e49afec@syzkaller.appspotmail.com
Signed-off-by: Dongliang Mu <dzm91@hust.edu.cn>
---
 drivers/input/joystick/xpad.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index 66a92691a047..2e077b52f46a 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -1944,6 +1944,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
 {
 	struct usb_device *udev = interface_to_usbdev(intf);
 	struct usb_xpad *xpad;
+	struct input_dev *input_dev;
 	struct usb_endpoint_descriptor *ep_irq_in, *ep_irq_out;
 	int i, error;
 
@@ -1957,9 +1958,13 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
 	}
 
 	xpad = kzalloc(sizeof(struct usb_xpad), GFP_KERNEL);
-	if (!xpad)
-		return -ENOMEM;
+	input_dev = input_allocate_device();
+	if (!xpad || !input_dev) {
+		error = -ENOMEM;
+		goto err_free_mem;
+	}
 
+	xpad->dev = input_dev;
 	usb_make_path(udev, xpad->phys, sizeof(xpad->phys));
 	strlcat(xpad->phys, "/input0", sizeof(xpad->phys));
 
@@ -2134,6 +2139,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
 err_free_idata:
 	usb_free_coherent(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma);
 err_free_mem:
+	input_free_device(input_dev);
 	kfree(xpad);
 	return error;
 }
@@ -2159,6 +2165,7 @@ static void xpad_disconnect(struct usb_interface *intf)
 	usb_free_coherent(xpad->udev, XPAD_PKT_LEN,
 			xpad->idata, xpad->idata_dma);
 
+	input_free_device(xpad->dev);
 	kfree(xpad);
 
 	usb_set_intfdata(intf, NULL);
-- 
2.39.2


             reply	other threads:[~2023-04-14 13:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-14 12:55 Dongliang Mu [this message]
2023-04-17  9:25 ` [PATCH] Input: xpad - fix GPF in xpad_probe Dan Carpenter
     [not found]   ` <99794af0-7367-acff-357d-1cd4fa7f832e@hust.edu.cn>
2023-04-17 10:24     ` Vicki Pfau
     [not found]       ` <57577302-8d18-231f-062b-b1d262720943@hust.edu.cn>
2023-04-17 11:07         ` Vicki Pfau
2023-04-17 11:15           ` Dongliang Mu
2023-04-17 10:42   ` Dan Carpenter
2023-04-20 11:07     ` Dan Carpenter
2023-04-22 19:48       ` Dan Carpenter
2023-04-22 19:56         ` Dan Carpenter
2023-04-23  2:33         ` Dongliang Mu
2023-05-02 10:34           ` Dan Carpenter
2023-08-14 21:12 Claudia De-Massari

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230414125603.686123-1-dzm91@hust.edu.cn \
    --to=dzm91@hust.edu.cn \
    --cc=chaorace@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=hust-os-kernel-patches@googlegroups.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthias.benkmann@gmail.com \
    --cc=mkorpershoek@baylibre.com \
    --cc=nate@yocom.org \
    --cc=pgriffais@valvesoftware.com \
    --cc=radon86dev@gmail.com \
    --cc=rojtberg@gmail.com \
    --cc=s.demassari@gmail.com \
    --cc=syzbot+a3f758b8d8cb7e49afec@syzkaller.appspotmail.com \
    --cc=vi@endrift.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.