public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Oliver Neukum <oneukum@suse.com>
To: Bastien Nocera <hadess@hadess.net>, linux-usb@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	Peter Hutterer <peter.hutterer@who-t.net>
Subject: Re: [RFC v1] USB: core: add USBDEVFS_REVOKE ioctl
Date: Mon, 25 Apr 2022 15:49:38 +0200	[thread overview]
Message-ID: <903b294f-8407-3438-54a9-3c96e361be41@suse.com> (raw)
In-Reply-To: <20220425132315.924477-1-hadess@hadess.net>



On 25.04.22 15:23, Bastien Nocera wrote:
>  struct usb_memory {
> @@ -237,6 +238,9 @@ static int usbdev_mmap(struct file *file, struct vm_area_struct *vma)
>  	dma_addr_t dma_handle;
>  	int ret;
>  
> +	if (!connected(ps) || ps->revoked)
> +		return -ENODEV;
> +
This lacks locking.
>  
> +static int usbdev_revoke(struct usb_dev_state *ps)
> +{
> +	struct usb_device *dev = ps->dev;
> +	unsigned int ifnum;
> +	struct async *as;
> +
> +	if (ps->revoked)
> +		return -ENODEV;
> +	ps->revoked = true;
> +
> +	usb_lock_device(dev);
And here you lock the device a second time. That is a bad idea.
> +	for (ifnum = 0; ps->ifclaimed && ifnum < 8*sizeof(ps->ifclaimed);
> +			ifnum++) {
> +		if (test_bit(ifnum, &ps->ifclaimed))
> +			releaseintf(ps, ifnum);
> +	}
> +	destroy_all_async(ps);
> +	usb_unlock_device(dev);
> +
> +	as = async_getcompleted(ps);
> +	while (as) {
> +		free_async(as);
> +		as = async_getcompleted(ps);
> +	}
> +
> +	return 0;
> +}
Getting your file descriptor revoked should wake you up
from poll(), shouldn't it?

> +
>  /*
>   * NOTE:  All requests here that have interface numbers as parameters
>   * are assuming that somehow the configuration has been prevented from
> @@ -2619,7 +2660,7 @@ static long usbdev_do_ioctl(struct file *file, unsigned int cmd,
>  #endif
>  	}
>  
> -	if (!connected(ps)) {
> +	if (!connected(ps) || ps->revoked) {
>  		usb_unlock_device(dev);
>  		return -ENODEV;
>  	}
> @@ -2779,6 +2820,11 @@ static long usbdev_do_ioctl(struct file *file, unsigned int cmd,
>  	case USBDEVFS_WAIT_FOR_RESUME:
>  		ret = proc_wait_for_resume(ps);
>  		break;
> +	case USBDEVFS_REVOKE:
You are still in usb_lock_device()

    Regards
        Oliver


  parent reply	other threads:[~2022-04-25 13:50 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-25 13:23 [RFC v1] USB: core: add USBDEVFS_REVOKE ioctl Bastien Nocera
2022-04-25 13:28 ` Bastien Nocera
2022-04-25 13:49 ` Oliver Neukum [this message]
2022-04-25 14:25   ` Bastien Nocera
2022-04-25 14:45   ` Bastien Nocera
2022-04-25 14:10 ` Greg Kroah-Hartman
2022-04-25 14:28   ` Bastien Nocera
2022-04-25 15:00     ` Greg Kroah-Hartman
2022-04-25 15:17       ` Bastien Nocera
2022-04-25 15:45         ` Greg Kroah-Hartman
2022-04-26  2:27           ` Peter Hutterer
2022-04-26  7:14             ` Oliver Neukum
2022-04-26  7:21               ` Greg Kroah-Hartman
2022-04-26  8:46                 ` Oliver Neukum
2022-04-26 10:07                   ` Bastien Nocera
2022-04-26 10:30                     ` Greg Kroah-Hartman
2022-04-26 10:37                       ` Bastien Nocera
2022-04-26 11:10                         ` Greg Kroah-Hartman
2022-04-28 10:28                         ` Oliver Neukum
2022-04-28 11:21                           ` Bastien Nocera
2022-04-26 10:07             ` Bastien Nocera
2022-04-26 10:07           ` Bastien Nocera
2022-04-25 16:14         ` Alan Stern
2022-04-25 17:09           ` Benjamin Tissoires

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=903b294f-8407-3438-54a9-3c96e361be41@suse.com \
    --to=oneukum@suse.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hadess@hadess.net \
    --cc=linux-usb@vger.kernel.org \
    --cc=peter.hutterer@who-t.net \
    --cc=stern@rowland.harvard.edu \
    /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