From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
syzbot+0434ac83f907a1dbdd1e@syzkaller.appspotmail.com
Subject: Re: [PATCH v2] Input: powermate - fix use-after-free in powermate_config_complete
Date: Wed, 4 Oct 2023 07:30:21 -0700 [thread overview]
Message-ID: <ZR12/VYt0rNL1Lzd@penguin> (raw)
In-Reply-To: <20230916-topic-powermate_use_after_free-v2-1-505f49019f2f@gmail.com>
Hi Javier,
On Sun, Oct 01, 2023 at 05:35:54PM +0200, Javier Carrasco wrote:
> syzbot has found a use-after-free bug [1] in the powermate driver. This
> happens when the device is disconnected, which leads to a memory free
> from the powermate_device struct.
> When an asynchronous control message completes after the kfree and its
> callback is invoked, the lock does not exist anymore and hence the bug.
>
> Use usb_kill_urb() on pm->config to cancel any in-progress requests upon
> device disconnection. Given that this action is already done on pm->irq,
> reorder the code to have both calls after the call to
> input_unregister_device(), which is the most common approach.
>
> [1] https://syzkaller.appspot.com/bug?extid=0434ac83f907a1dbdd1e
>
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
> Reported-by: syzbot+0434ac83f907a1dbdd1e@syzkaller.appspotmail.com
> ---
> Changes in v2:
> - Use usb_kill_urb() on pm->config upon device disconnection.
> - Link to v1: https://lore.kernel.org/r/20230916-topic-powermate_use_after_free-v1-1-2ffa46652869@gmail.com
> ---
> drivers/input/misc/powermate.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/input/misc/powermate.c b/drivers/input/misc/powermate.c
> index c1c733a9cb89..c0aea75eb087 100644
> --- a/drivers/input/misc/powermate.c
> +++ b/drivers/input/misc/powermate.c
> @@ -423,8 +423,9 @@ static void powermate_disconnect(struct usb_interface *intf)
> usb_set_intfdata(intf, NULL);
> if (pm) {
> pm->requires_update = 0;
> - usb_kill_urb(pm->irq);
No, you do not want interrupts coming in while input device is being
destroyed, this one needs to stay where it is.
> input_unregister_device(pm->input);
> + usb_kill_urb(pm->irq);
> + usb_kill_urb(pm->config);
> usb_free_urb(pm->irq);
> usb_free_urb(pm->config);
> powermate_free_buffers(interface_to_usbdev(intf), pm);
Thanks.
--
Dmitry
prev parent reply other threads:[~2023-10-04 14:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-01 15:35 [PATCH v2] Input: powermate - fix use-after-free in powermate_config_complete Javier Carrasco
2023-10-04 14:30 ` Dmitry Torokhov [this message]
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=ZR12/VYt0rNL1Lzd@penguin \
--to=dmitry.torokhov@gmail.com \
--cc=javier.carrasco.cruz@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=syzbot+0434ac83f907a1dbdd1e@syzkaller.appspotmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox