All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
To: Shuah Khan <skhan@linuxfoundation.org>, shuah@kernel.org
Cc: valentina.manea.m@gmail.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Greg KH <gregkh@linuxfoundation.org>
Subject: Re: [PATCH 0/6] usbip fixes to crashes found by syzbot
Date: Sat, 13 Mar 2021 09:48:52 +0900	[thread overview]
Message-ID: <192bdb07-da84-ce96-2e25-7c0df749940a@i-love.sakura.ne.jp> (raw)
In-Reply-To: <afd1341b-2ed1-f781-d6c8-6064fea3aeb8@i-love.sakura.ne.jp>

On 2021/03/12 14:44, Tetsuo Handa wrote:
> And what you are missing in your [PATCH 4,5,6/6] is
> 
>   diff --git a/drivers/usb/usbip/vhci_sysfs.c b/drivers/usb/usbip/vhci_sysfs.c
>   index c4457026d5ad..3c64bd06ab53 100644
>   --- a/drivers/usb/usbip/vhci_sysfs.c
>   +++ b/drivers/usb/usbip/vhci_sysfs.c
>   @@ -423,6 +423,7 @@ static ssize_t attach_store(struct device *dev, struct device_attribute *attr,
>           /* end the lock */
>   
>           wake_up_process(vdev->ud.tcp_rx);
>   +       schedule_timeout_uninterruptible(HZ); // Consider being preempted here.
>           wake_up_process(vdev->ud.tcp_tx);
>   
>           rh_port_connect(vdev, speed);
> 
> . wake_up_process(tcp_tx) can call vhci_shutdown_connection() before wake_up_process(tcp_tx) is called.

wake_up_process(tcp_rx) can call vhci_shutdown_connection() before wake_up_process(tcp_tx) is called.

> Since vhci_shutdown_connection() destroys tcp_tx thread and releases tcp_tx memory via kthread_stop_put(tcp_tx),
> wake_up_process(tcp_tx) will access already freed memory. Your patch converted "NULL pointer dereference caused by
> failing to call kthread_stop_put(tcp_tx)" into "use after free caused by succeeding to call kthread_stop_put(tcp_tx)".
> 

And note that

  diff --git a/drivers/usb/usbip/vhci_sysfs.c b/drivers/usb/usbip/vhci_sysfs.c
  index c4457026d5ad..0e1a81d4632c 100644
  --- a/drivers/usb/usbip/vhci_sysfs.c
  +++ b/drivers/usb/usbip/vhci_sysfs.c
  @@ -422,11 +422,11 @@ static ssize_t attach_store(struct device *dev, struct device_attribute *attr,
          spin_unlock_irqrestore(&vhci->lock, flags);
          /* end the lock */
  
  -       wake_up_process(vdev->ud.tcp_rx);
  -       wake_up_process(vdev->ud.tcp_tx);
  -
          rh_port_connect(vdev, speed);
  
  +       wake_up_process(vdev->ud.tcp_tx);
  +       wake_up_process(vdev->ud.tcp_rx);
  +
          return count;
   }
   static DEVICE_ATTR_WO(attach);

is as well not sufficient, for you are still missing

  diff --git a/drivers/usb/usbip/vhci_sysfs.c b/drivers/usb/usbip/vhci_sysfs.c
  index c4457026d5ad..c958f89a9196 100644
  --- a/drivers/usb/usbip/vhci_sysfs.c
  +++ b/drivers/usb/usbip/vhci_sysfs.c
  @@ -422,11 +422,13 @@ static ssize_t attach_store(struct device *dev, struct device_attribute *attr,
          spin_unlock_irqrestore(&vhci->lock, flags);
          /* end the lock */
  
  -       wake_up_process(vdev->ud.tcp_rx);
  -       wake_up_process(vdev->ud.tcp_tx);
  +       schedule_timeout_uninterruptible(HZ); // Consider being preempted here.
  
          rh_port_connect(vdev, speed);
  
  +       wake_up_process(vdev->ud.tcp_tx);
  +       wake_up_process(vdev->ud.tcp_rx);
  +
          return count;
   }
   static DEVICE_ATTR_WO(attach);

because vhci_port_disconnect() from detach_store() can call usbip_event_add(&vdev->ud, VDEV_EVENT_DOWN)
(same use after free bug regarding tcp_tx and tcp_rx) as soon as all shared states are set up and
spinlocks are released.

What you had better consider first is how to protect event_handler()/usbip_sockfd_store()/attach_store()/detach_store() functions
 from concurrent calls. Please respond to https://lkml.kernel.org/r/3dab66dc-2981-bc88-a370-4b3178dfd390@i-love.sakura.ne.jp
before you try to make further changes.


  reply	other threads:[~2021-03-13  0:49 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-08  3:53 [PATCH 0/6] usbip fixes to crashes found by syzbot Shuah Khan
2021-03-08  3:53 ` [PATCH 1/6] usbip: fix stub_dev to check for stream socket Shuah Khan
2021-03-08  3:53 ` [PATCH 2/6] usbip: fix vhci_hcd " Shuah Khan
2021-03-08  3:53 ` [PATCH 3/6] usbip: fix vudc " Shuah Khan
2021-03-08  3:53 ` [PATCH 4/6] usbip: fix stub_dev usbip_sockfd_store() races leading to gpf Shuah Khan
2021-03-08  7:35   ` Tetsuo Handa
2021-03-08 10:10     ` Tetsuo Handa
2021-03-08 16:27       ` Shuah Khan
2021-03-09 11:04         ` Tetsuo Handa
2021-03-09 13:56           ` Tetsuo Handa
2021-03-09 19:50           ` Shuah Khan
2021-03-09 23:40             ` Tetsuo Handa
2021-03-09 23:52               ` Shuah Khan
2021-03-10  0:03                 ` Tetsuo Handa
2021-03-10  0:29                   ` Shuah Khan
2021-03-10  1:02                     ` Tetsuo Handa
2021-03-10  2:07                       ` Shuah Khan
2021-03-10 10:38                         ` Tetsuo Handa
2021-03-09 15:22         ` Shuah Khan
2021-03-08  3:53 ` [PATCH 5/6] usbip: fix vhci_hcd attach_store() " Shuah Khan
2021-03-08  3:53 ` [PATCH 6/6] usbip: fix vudc usbip_sockfd_store " Shuah Khan
2021-03-10 18:33 ` [PATCH 0/6] usbip fixes to crashes found by syzbot Greg KH
2021-03-11 12:34   ` Tetsuo Handa
2021-03-11 12:57     ` Greg KH
2021-03-11 13:24       ` Tetsuo Handa
2021-03-12  5:44         ` Tetsuo Handa
2021-03-13  0:48           ` Tetsuo Handa [this message]
2021-03-14 11:38             ` Tetsuo Handa
2021-03-17  6:21               ` Tetsuo Handa
2021-03-17 15:06                 ` Shuah Khan
2021-03-17 15:38                   ` Tetsuo Handa
2021-03-17 17:09                     ` Shuah Khan
2021-03-18 13:13                   ` Shuah Khan
2021-03-18 13:39                     ` Tetsuo Handa

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=192bdb07-da84-ce96-2e25-7c0df749940a@i-love.sakura.ne.jp \
    --to=penguin-kernel@i-love.sakura.ne.jp \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=valentina.manea.m@gmail.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.