lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Thu, 2 Jun 2022 14:05:10 +0100
From:   John Keeping <john@...anate.com>
To:     Michael Wu <michael@...winnertech.com>
Cc:     quic_linyyuan@...cinc.com, balbi@...nel.org,
        gregkh@...uxfoundation.org, axboe@...nel.dk,
        quic_pkondeti@...cinc.com, wcheng@...eaurora.org,
        quic_ugoswami@...cinc.com, andrew_gabbasov@...tor.com,
        plr.vincent@...il.com, gustavoars@...nel.org,
        linux-usb@...r.kernel.org, linux-kernel@...r.kernel.org,
        allwinner-opensource-support@...winnertech.com
Subject: Re: [PATCH] usb: f_fs: Fix crash during gadget function switching

On Thu, Jun 02, 2022 at 06:36:47PM +0800, Michael Wu wrote:
> On 5/31/2022 2:14 AM, John Keeping wrote:
> > On Tue, May 10, 2022 at 04:01:05PM +0800, Michael Wu wrote:
> > > On arm64 android12 and possibly other platforms, during the usb gadget
> > > function switching procedure (e.g. from mtp to midi), a synchronization
> > > issue could occur, which causes an use-after-free panic as shown below:
> > 
> > I assume this is the path through ffs_epfile_io() with !io_data->aio.
> > It looks like there is no check there for epfile->ep == ep which the
> > other paths do check.
> > 
> > Does the patch below fix the problem without needing to add a new
> > completion?
> > 
> 
> Hi John,
> Thanks for your suggestion. I've tested your patch and it did work -- When
> my issue occurs, (epfile->ep != ep) is satisfied, and the error is handled.
> 
> > -- >8 --
> > --- a/drivers/usb/gadget/function/f_fs.c
> > +++ b/drivers/usb/gadget/function/f_fs.c
> > @@ -1084,16 +1084,22 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
> >                           */
> >                          usb_ep_dequeue(ep->ep, req);
> >                          wait_for_completion(&done);
> > -                       interrupted = ep->status < 0;
> > +                       interrupted = true;
> >                  }
> > -               if (interrupted)
> > +               spin_lock_irq(&epfile->ffs->eps_lock);
> > +               if (epfile->ep != ep)
> > +                       ret = -ESHUTDOWN;
> > +               else if (interrupted && ep->status < 0)
> >                          ret = -EINTR;
> > -               else if (io_data->read && ep->status > 0)
> > -                       ret = __ffs_epfile_read_data(epfile, data, ep->status,
> > -                                                    &io_data->data);
> >                  else
> >                          ret = ep->status;
> > +               spin_unlock_irq(&epfile->ffs->eps_lock);
> > +
> > +               if (io_data->read && ret > 0)
> > +                       ret = __ffs_epfile_read_data(epfile, data, ret,
> > +                                                    &io_data->data);
> > +
> >                  goto error_mutex;
> >          } else if (!(req = usb_ep_alloc_request(ep->ep, GFP_ATOMIC))) {
> >                  ret = -ENOMEM;
> Tested-by: Michael Wu <michael@...winnertech.com>
> 
> 
> I also tested Linyu's patch [1][2]. It also works.
> Is there a preference on these solutions?

Linyu's patch is more complete and covers some cases that I missed with
this attempt, so let's drop this thread and focus on that series.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ