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]
Message-ID: <ZHjtAdHAwH7CAyAE@dev-linux.lan>
Date:   Thu, 1 Jun 2023 12:09:53 -0700
From:   Sukrut Bellary <sukrut.bellary@...ux.com>
To:     Dan Carpenter <dan.carpenter@...aro.org>
Cc:     Srinivas Kandagatla <srinivas.kandagatla@...aro.org>,
        Abel Vesa <abel.vesa@...aro.org>,
        Amol Maheshwari <amahesh@....qualcomm.com>,
        Arnd Bergmann <arnd@...db.de>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        linux-arm-msm@...r.kernel.org, linux-kernel@...r.kernel.org,
        kernel-janitors@...r.kernel.org,
        Shuah Khan <skhan@...uxfoundation.org>
Subject: Re: [PATCH] misc: fastrpc: Fix double free of 'buf' in error path

On Thu, Jun 01, 2023 at 10:00:43AM +0300, Dan Carpenter wrote:
> On Wed, May 31, 2023 at 09:45:38PM -0700, Sukrut Bellary wrote:
> > On Fri, May 19, 2023 at 03:57:59PM -0700, Sukrut Bellary wrote:
> > > On Fri, May 19, 2023 at 11:39:59AM +0100, Srinivas Kandagatla wrote:
> > > > 
> > > > 
> > > > On 19/05/2023 11:22, Dan Carpenter wrote:
> > > > > > ----------------------->cut<---------------------------
> > > > > > diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> > > > > > index f60bbf99485c..3fdd326e1ae8 100644
> > > > > > --- a/drivers/misc/fastrpc.c
> > > > > > +++ b/drivers/misc/fastrpc.c
> > > > > > @@ -1891,7 +1891,8 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl,
> > > > > > char __user *argp)
> > > > > >                                        &args[0]);
> > > > > >          if (err) {
> > > > > >                  dev_err(dev, "mmap error (len 0x%08llx)\n", buf->size);
> > > > > > -               goto err_invoke;
> > > > > > +               fastrpc_buf_free(buf);
> > > > > > +               return err;
> > > > > >          }
> > > > > > 
> > > > > >          /* update the buffer to be able to deallocate the memory on the DSP
> > > > > > */
> > > > > > @@ -1930,11 +1931,7 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl,
> > > > > > char __user *argp)
> > > > > >          return 0;
> > > > > > 
> > > > > >   err_assign:
> > > > > > -       fastrpc_req_munmap_impl(fl, buf);
> > > > > > -err_invoke:
> > > > > > -       fastrpc_buf_free(buf);
> > > > > > -
> > > > > > -       return err;
> > > > > > +       return fastrpc_req_munmap_impl(fl, buf);
> > > > > 
> > > > > This will return success if copy_to_user() fails.
> > > > > 
> > > > that is true, using return value of fastrpc_req_munmap_impl does not really
> > > > make sense here we should just return err in either case to the user.
> > > >
> > >
> > 
> > I have one follow-up question before I send the v2 patch.
> > With the following approach, I do see one issue.
> > 
> > ----------------------->cut<---------------------------
> > diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> > index f60bbf99485c..3fdd326e1ae8 100644
> > --- a/drivers/misc/fastrpc.c
> > +++ b/drivers/misc/fastrpc.c
> > @@ -1891,7 +1891,8 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl,
> > char __user *argp)
> >                                       &args[0]);
> >         if (err) {
> >                 dev_err(dev, "mmap error (len 0x%08llx)\n", buf->size);
> > -               goto err_invoke;
> > +               fastrpc_buf_free(buf);
> > +               return err;
> >         }
> > 
> >         /* update the buffer to be able to deallocate the memory on the DSP */
> > @@ -1930,11 +1931,7 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl,
> > char __user *argp)
> >         return 0;
> > 
> >  err_assign:
> > -       fastrpc_req_munmap_impl(fl, buf);
> > -err_invoke:
> > -       fastrpc_buf_free(buf);
> > -
> > -       return err;
> > +       fastrpc_req_munmap_impl(fl, buf);
> > +       return err;
> >  }
> > ----------------------->cut<---------------------------
> > 
> > In this, if qcom_scm_assign_mem() fails, the buf is not added to the list.
> > But the call to fastrpc_req_munmap_impl() tries to delete the buf
> > from the list.
> > 
> > To avoid this, we can use the following approach.
> 
> The list is initialized in __fastrpc_buf_alloc().
> 
> 	INIT_LIST_HEAD(&buf->node);
> 
> So calling list_del(&buf->node); is fine.  It's not necessary but it's
> not harmful.
>

OK, Thanks Dan. I will submit the v2 with 1st approach.

Regards,
Sukrut Bellary

> regards,
> dan carpenter
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ