lkml.org 
[lkml]   [2019]   [Dec]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: build_path_from_dentry_optional_prefix() may schedule from invalid context
вс, 8 дек. 2019 г. в 16:34, Al Viro <viro@zeniv.linux.org.uk>:
>
> On Mon, Sep 30, 2019 at 10:32:16AM -0700, Pavel Shilovsky wrote:
> > сб, 21 сент. 2019 г. в 15:38, Al Viro <viro@zeniv.linux.org.uk>:
>
> > > IOW, kindly lose that nonsense. More importantly, why bother
> > > with that kmalloc()? Just __getname() in the very beginning
> > > and __putname() on failure (and for freeing the result afterwards).
> > >
> > > What's more, you are open-coding dentry_path_raw(), badly.
> > > The only differences are
> > > * use of dirsep instead of '/' and
> > > * a prefix slapped in the beginning.
> > >
> > > I'm fairly sure that
> > > char *buf = __getname();
> > > char *s;
> > >
> > > *to_free = NULL;
> > > if (unlikely(!buf))
> > > return NULL;
> > >
> > > s = dentry_path_raw(dentry, buf, PATH_MAX);
> > > if (IS_ERR(s) || s < buf + prefix_len)
> > > __putname(buf);
> > > return NULL; // assuming that you don't care about details
> > > }
> > >
> > > if (dirsep != '/') {
> > > char *p = s;
> > > while ((p = strchr(p, '/')) != NULL)
> > > *p++ = dirsep;
> > > }
> > >
> > > s -= prefix_len;
> > > memcpy(s, prefix, prefix_len);
> > >
> > > *to_free = buf;
> > > return s;
> > >
> > > would end up being faster, not to mention much easier to understand.
> > > With the caller expected to pass &to_free among the arguments and
> > > __putname() it once it's done.
> > >
> > > Or just do __getname() in the caller and pass it to the function -
> > > in that case freeing (in all cases) would be up to the caller.
> >
> > Thanks for pointing this out. Someone should look at this closely and
> > clean it up.
>
> Could you take a look through vfs.git#misc.cifs?

Looks good. I would only add the same or a similar comment as
fs/hostfs/hostfs_kern.c has when calling dentry_path_raw():

/*
* This function relies on the fact that dentry_path_raw() will place
* the path name at the end of the provided buffer.
*/

Otherwise it is not straightforward at the first glance how the code works.

Acked-by: Pavel Shilovsky <pshilov@microsoft.com>

--
Best regards,
Pavel Shilovsky

\
 
 \ /
  Last update: 2019-12-10 20:15    [W:0.067 / U:0.092 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site