All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Sam Sun <samsun1006219@gmail.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
	 Greg KH <gregkh@linuxfoundation.org>,
	swboyd@chromium.org, ricardo@marliere.net,  hkallweit1@gmail.com,
	heikki.krogerus@linux.intel.com,  mathias.nyman@linux.intel.com,
	royluo@google.com,  syzkaller-bugs@googlegroups.com,
	xrivendell7@gmail.com
Subject: Re: [Linux kernel bug] general protection fault in disable_store
Date: Tue, 16 Apr 2024 17:05:55 +0800	[thread overview]
Message-ID: <CAEkJfYMSwuikpBJudOaFYrxgf9e=_O4nig6sTPLLAtpdEKQuyQ@mail.gmail.com> (raw)
In-Reply-To: <5704ac63-5e5b-416c-a2a1-57528e76a02f@rowland.harvard.edu>

On Mon, Apr 15, 2024 at 10:47 PM Alan Stern <stern@rowland.harvard.edu> wrote:
>
> Actually, I've got a completely different patch which I think will fix
> the problem you encountered.  Instead of using mutual exclusion to
> avoid the race, it prevents the two routines from being called at the
> same time so the race can't occur in the first place.  It also should
> guarantee the usb_hub_to_struct_hub() doesn't return NULL when
> disable_store() calls it.
>
> Can you try the patch below, instead of (not along with) the first
> patch?  Thanks.
>
> Alan Stern
>
>
>
> Index: usb-devel/drivers/usb/core/hub.c
> ===================================================================
> --- usb-devel.orig/drivers/usb/core/hub.c
> +++ usb-devel/drivers/usb/core/hub.c
> @@ -1788,16 +1788,15 @@ static void hub_disconnect(struct usb_in
>
>         mutex_lock(&usb_port_peer_mutex);
>
> +       for (port1 = hdev->maxchild; port1 > 0; --port1)
> +               usb_hub_remove_port_device(hub, port1);
> +
>         /* Avoid races with recursively_mark_NOTATTACHED() */
>         spin_lock_irq(&device_state_lock);
> -       port1 = hdev->maxchild;
>         hdev->maxchild = 0;
>         usb_set_intfdata(intf, NULL);
>         spin_unlock_irq(&device_state_lock);
>
> -       for (; port1 > 0; --port1)
> -               usb_hub_remove_port_device(hub, port1);
> -
>         mutex_unlock(&usb_port_peer_mutex);
>
>         if (hub->hdev->speed == USB_SPEED_HIGH)
>

I tried this patch and it worked. I agree this patch is better and it
avoids introducing new locks.

Best,
Yue

  reply	other threads:[~2024-04-16  9:06 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-11  6:52 [Linux kernel bug] general protection fault in disable_store Sam Sun
2024-04-11  6:58 ` Greg KH
2024-04-11  7:19   ` Sam Sun
2024-04-11 15:24 ` Alan Stern
2024-04-12 13:08   ` Sam Sun
2024-04-12 14:40     ` Alan Stern
2024-04-12 16:26       ` Sam Sun
2024-04-12 18:11         ` Alan Stern
2024-04-12 18:32           ` Alan Stern
2024-04-13  5:08           ` Sam Sun
2024-04-15 14:47             ` Alan Stern
2024-04-16  9:05               ` Sam Sun [this message]
2024-04-16 16:35                 ` Alan Stern
2024-04-17  7:39                   ` Sam Sun
2024-04-17 14:23                     ` Alan Stern

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='CAEkJfYMSwuikpBJudOaFYrxgf9e=_O4nig6sTPLLAtpdEKQuyQ@mail.gmail.com' \
    --to=samsun1006219@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=hkallweit1@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@linux.intel.com \
    --cc=ricardo@marliere.net \
    --cc=royluo@google.com \
    --cc=stern@rowland.harvard.edu \
    --cc=swboyd@chromium.org \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=xrivendell7@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.