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] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 28 Jun 2021 05:20:16 +0000
From:   Justin He <Justin.He@....com>
To:     Al Viro <viro@...iv.linux.org.uk>,
        Linus Torvalds <torvalds@...ux-foundation.org>
CC:     Petr Mladek <pmladek@...e.com>,
        Steven Rostedt <rostedt@...dmis.org>,
        Sergey Senozhatsky <senozhatsky@...omium.org>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Rasmus Villemoes <linux@...musvillemoes.dk>,
        Jonathan Corbet <corbet@....net>,
        Heiko Carstens <hca@...ux.ibm.com>,
        Vasily Gorbik <gor@...ux.ibm.com>,
        Christian Borntraeger <borntraeger@...ibm.com>,
        "Eric W . Biederman" <ebiederm@...ssion.com>,
        "Darrick J. Wong" <darrick.wong@...cle.com>,
        "Peter Zijlstra (Intel)" <peterz@...radead.org>,
        Ira Weiny <ira.weiny@...el.com>,
        Eric Biggers <ebiggers@...gle.com>,
        "Ahmed S. Darwish" <a.darwish@...utronix.de>,
        "open list:DOCUMENTATION" <linux-doc@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        linux-s390 <linux-s390@...r.kernel.org>,
        linux-fsdevel <linux-fsdevel@...r.kernel.org>, nd <nd@....com>
Subject: RE: [PATCH 07/14] d_path: lift -ENAMETOOLONG handling into callers of
 prepend_path()



> -----Original Message-----
> From: Justin He
> Sent: Friday, June 25, 2021 5:18 PM
> To: Al Viro <viro@...iv.linux.org.uk>; Linus Torvalds <torvalds@...ux-
> foundation.org>
> Cc: Petr Mladek <pmladek@...e.com>; Steven Rostedt <rostedt@...dmis.org>;
> Sergey Senozhatsky <senozhatsky@...omium.org>; Andy Shevchenko
> <andriy.shevchenko@...ux.intel.com>; Rasmus Villemoes
> <linux@...musvillemoes.dk>; Jonathan Corbet <corbet@....net>; Heiko
> Carstens <hca@...ux.ibm.com>; Vasily Gorbik <gor@...ux.ibm.com>; Christian
> Borntraeger <borntraeger@...ibm.com>; Eric W . Biederman
> <ebiederm@...ssion.com>; Darrick J. Wong <darrick.wong@...cle.com>; Peter
> Zijlstra (Intel) <peterz@...radead.org>; Ira Weiny <ira.weiny@...el.com>;
> Eric Biggers <ebiggers@...gle.com>; Ahmed S. Darwish
> <a.darwish@...utronix.de>; open list:DOCUMENTATION <linux-
> doc@...r.kernel.org>; Linux Kernel Mailing List <linux-
> kernel@...r.kernel.org>; linux-s390 <linux-s390@...r.kernel.org>; linux-
> fsdevel <linux-fsdevel@...r.kernel.org>
> Subject: RE: [PATCH 07/14] d_path: lift -ENAMETOOLONG handling into callers
> of prepend_path()
> 
> Hi Al
> 
> > -----Original Message-----
> > From: Al Viro <viro@....linux.org.uk> On Behalf Of Al Viro
> > Sent: Wednesday, May 19, 2021 8:49 AM
> > To: Linus Torvalds <torvalds@...ux-foundation.org>
> > Cc: Justin He <Justin.He@....com>; Petr Mladek <pmladek@...e.com>; Steven
> > Rostedt <rostedt@...dmis.org>; Sergey Senozhatsky
> > <senozhatsky@...omium.org>; Andy Shevchenko
> > <andriy.shevchenko@...ux.intel.com>; Rasmus Villemoes
> > <linux@...musvillemoes.dk>; Jonathan Corbet <corbet@....net>; Heiko
> > Carstens <hca@...ux.ibm.com>; Vasily Gorbik <gor@...ux.ibm.com>;
> Christian
> > Borntraeger <borntraeger@...ibm.com>; Eric W . Biederman
> > <ebiederm@...ssion.com>; Darrick J. Wong <darrick.wong@...cle.com>; Peter
> > Zijlstra (Intel) <peterz@...radead.org>; Ira Weiny <ira.weiny@...el.com>;
> > Eric Biggers <ebiggers@...gle.com>; Ahmed S. Darwish
> > <a.darwish@...utronix.de>; open list:DOCUMENTATION <linux-
> > doc@...r.kernel.org>; Linux Kernel Mailing List <linux-
> > kernel@...r.kernel.org>; linux-s390 <linux-s390@...r.kernel.org>; linux-
> > fsdevel <linux-fsdevel@...r.kernel.org>
> > Subject: [PATCH 07/14] d_path: lift -ENAMETOOLONG handling into callers
> of
> > prepend_path()
> >
> > The only negative value ever returned by prepend_path() is -ENAMETOOLONG
> > and callers can recognize that situation (overflow) by looking at the
> > sign of buflen.  Lift that into the callers; we already have the
> > same logics (buf if buflen is non-negative, ERR_PTR(-ENAMETOOLONG)
> > otherwise)
> > in several places and that'll become a new primitive several commits down
> > the road.
> >
> > Make prepend_path() return 0 instead of -ENAMETOOLONG.  That makes for
> > saner calling conventions (0/1/2/3/-ENAMETOOLONG is obnoxious) and
> > callers actually get simpler, especially once the aforementioned
> > primitive gets added.
> >
> > In prepend_path() itself we switch prepending the / (in case of
> > empty path) to use of prepend() - no need to open-code that, compiler
> > will do the right thing.  It's exactly the same logics as in
> > __dentry_path().
> >
> > Signed-off-by: Al Viro <viro@...iv.linux.org.uk>
> > ---
> >  fs/d_path.c | 39 +++++++++++----------------------------
> >  1 file changed, 11 insertions(+), 28 deletions(-)
> >
> > diff --git a/fs/d_path.c b/fs/d_path.c
> > index 72b8087aaf9c..327cc3744554 100644
> > --- a/fs/d_path.c
> > +++ b/fs/d_path.c
> > @@ -127,8 +127,7 @@ static int prepend_path(const struct path *path,
> >  		}
> >  		parent = dentry->d_parent;
> >  		prefetch(parent);
> > -		error = prepend_name(&bptr, &blen, &dentry->d_name);
> > -		if (error)
> > +		if (unlikely(prepend_name(&bptr, &blen, &dentry->d_name) < 0))
> >  			break;
> >
> >  		dentry = parent;
> > @@ -149,12 +148,9 @@ static int prepend_path(const struct path *path,
> >  	}
> >  	done_seqretry(&mount_lock, m_seq);
> >
> > -	if (error >= 0 && bptr == *buffer) {
> > -		if (--blen < 0)
> > -			error = -ENAMETOOLONG;
> > -		else
> > -			*--bptr = '/';
> > -	}
> > +	if (blen == *buflen)
> > +		prepend(&bptr, &blen, "/", 1);
> > +
> >  	*buffer = bptr;
> >  	*buflen = blen;
> >  	return error;
> > @@ -181,16 +177,11 @@ char *__d_path(const struct path *path,
> >  	       char *buf, int buflen)
> >  {
> >  	char *res = buf + buflen;
> > -	int error;
> >
> >  	prepend(&res, &buflen, "", 1);
> > -	error = prepend_path(path, root, &res, &buflen);
> > -
> > -	if (error < 0)
> > -		return ERR_PTR(error);
> > -	if (error > 0)
> > +	if (prepend_path(path, root, &res, &buflen) > 0)
> >  		return NULL;
> > -	return res;
> > +	return buflen >= 0 ? res : ERR_PTR(-ENAMETOOLONG);
> >  }
> >
> >  char *d_absolute_path(const struct path *path,
> > @@ -198,16 +189,11 @@ char *d_absolute_path(const struct path *path,
> >  {
> >  	struct path root = {};
> >  	char *res = buf + buflen;
> > -	int error;
> >
> >  	prepend(&res, &buflen, "", 1);
> > -	error = prepend_path(path, &root, &res, &buflen);
> > -
> > -	if (error > 1)
> > -		error = -EINVAL;
> > -	if (error < 0)
> > -		return ERR_PTR(error);
> > -	return res;
> > +	if (prepend_path(path, &root, &res, &buflen) > 1)
> > +		return ERR_PTR(-EINVAL);
> > +	return buflen >= 0 ? res : ERR_PTR(-ENAMETOOLONG);
> 
> This patch is *correct*.
> But do you mind changing like:
> if (buflen >= 0 || error == 1)
> 	return res;
> else
> 	return ERR_PTR(-ENAMETOOLONG);
> 
> The reason why I comment here is that I will change the
> prepend_name in __prepend_path to prepend_name_with_len.
> The latter will go through all the dentries recursively instead
> of returning false if p.len<0.
> So (error == 1 && buflen < 0) is possible.
Please ignore it, this is not relevant to this patch itself, I can
draft a new patch if it is needed.

Hence:
Reviewed-by: Jia He <justin.he@....com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ