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: <CAO_48GEqxOOOZupGLAa92HXcnbe6_3ZfLvaJsDnv9_XFTTFe6w@mail.gmail.com>
Date:   Wed, 10 Jun 2020 20:44:37 +0530
From:   Sumit Semwal <sumit.semwal@...aro.org>
To:     Arnd Bergmann <arnd@...db.de>
Cc:     Linux Media Mailing List <linux-media@...r.kernel.org>,
        dri-devel <dri-devel@...ts.freedesktop.org>,
        Chenbo Feng <fengc@...gle.com>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        Linaro MM SIG <linaro-mm-sig@...ts.linaro.org>,
        Charan Teja Reddy <charante@...eaurora.org>,
        syzbot+3643a18836bce555bff6@...kaller.appspotmail.com,
        "# 3.4.x" <stable@...r.kernel.org>
Subject: Re: [PATCH] dma-buf: Move dma_buf_release() from fops to dentry_ops

On Wed, 10 Jun 2020 at 14:57, Arnd Bergmann <arnd@...db.de> wrote:
>
> On Wed, Jun 10, 2020 at 10:33 AM Sumit Semwal <sumit.semwal@...aro.org> wrote:
> >
> > Charan Teja reported a 'use-after-free' in dmabuffs_dname [1], which
> > happens if the dma_buf_release() is called while the userspace is
> > accessing the dma_buf pseudo fs's dmabuffs_dname() in another process,
> > and dma_buf_release() releases the dmabuf object when the last reference
> > to the struct file goes away.
> >
> > I discussed with Arnd Bergmann, and he suggested that rather than tying
> > the dma_buf_release() to the file_operations' release(), we can tie it to
> > the dentry_operations' d_release(), which will be called when the last ref
> > to the dentry is removed.
> >
> > The path exercised by __fput() calls f_op->release() first, and then calls
> > dput, which eventually calls d_op->d_release().
> >
> > In the 'normal' case, when no userspace access is happening via dma_buf
> > pseudo fs, there should be exactly one fd, file, dentry and inode, so
> > closing the fd will kill of everything right away.
> >
> > In the presented case, the dentry's d_release() will be called only when
> > the dentry's last ref is released.
> >
> > Therefore, lets move dma_buf_release() from fops->release() to
> > d_ops->d_release().
> >
> > Many thanks to Arnd for his FS insights :)
> >
> > [1]: https://lore.kernel.org/patchwork/patch/1238278/
> >
> > Fixes: bb2bb9030425 ("dma-buf: add DMA_BUF_SET_NAME ioctls")
> > Reported-by: syzbot+3643a18836bce555bff6@...kaller.appspotmail.com
> > Cc: <stable@...r.kernel.org> [5.3+]
> > Cc: Arnd Bergmann <arnd@...db.de>
> > Reported-by: Charan Teja Reddy <charante@...eaurora.org>
> > Signed-off-by: Sumit Semwal <sumit.semwal@...aro.org>
>
> The patch looks correct to me.
>
> Reviewed-by: Arnd Bergmann <arnd@...db.de>
>
> Obviously this should still be verified against the original report if possible.
Thanks, Arnd!
>
> >  drivers/dma-buf/dma-buf.c | 13 +++++++------
> >  1 file changed, 7 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> > index 01ce125f8e8d..92ba4b6ef3e7 100644
> > --- a/drivers/dma-buf/dma-buf.c
> > +++ b/drivers/dma-buf/dma-buf.c
> > @@ -54,8 +54,11 @@ static char *dmabuffs_dname(struct dentry *dentry, char *buffer, int buflen)
> >                              dentry->d_name.name, ret > 0 ? name : "");
> >  }
> >
> > +static void dma_buf_release(struct dentry *dentry);
> > +
> >  static const struct dentry_operations dma_buf_dentry_ops = {
> >         .d_dname = dmabuffs_dname,
> > +       .d_release = dma_buf_release,
> >  };
>
> I'd suggest rearranging the file to avoid the forward declaration, even
> if it makes it a little harder to review the change, the resulting code
> will remain organized more logically.
Got it, will update it in v2.
>
> >  static struct vfsmount *dma_buf_mnt;
> > @@ -77,14 +80,14 @@ static struct file_system_type dma_buf_fs_type = {
> >         .kill_sb = kill_anon_super,
> >  };
> >
> > -static int dma_buf_release(struct inode *inode, struct file *file)
> > +static void dma_buf_release(struct dentry *dentry)
> >  {
> >         struct dma_buf *dmabuf;
> >
> > -       if (!is_dma_buf_file(file))
> > -               return -EINVAL;
> > +       if (dentry->d_op != &dma_buf_dentry_ops)
> > +               return;
>
> I think the check here is redundant and it's clearer without it.
Ok, will remove.
>
>           Arnd

Best,
Sumit.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ