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]
Message-ID: <20200527152340.GA19985@localhost.localdomain>
Date:   Wed, 27 May 2020 18:23:40 +0300
From:   Alexey Dobriyan <adobriyan@...il.com>
To:     "Eric W. Biederman" <ebiederm@...ssion.com>
Cc:     Kaitao Cheng <pilgrimtao@...il.com>, christian@...uner.io,
        akpm@...ux-foundation.org, gladkov.alexey@...il.com, guro@...com,
        walken@...gle.com, avagin@...il.com, khlebnikov@...dex-team.ru,
        linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org
Subject: Re: [PATCH] proc/base: Skip assignment to len when there is no error
 on d_path in do_proc_readlink.

On Wed, May 27, 2020 at 09:41:53AM -0500, Eric W. Biederman wrote:
> Kaitao Cheng <pilgrimtao@...il.com> writes:
> 
> > we don't need {len = PTR_ERR(pathname)} when IS_ERR(pathname) is false,
> > it's better to move it into if(IS_ERR(pathname)){}.
> 
> Please look at the generated code.
> 
> I believe you will find that your change will generate worse assembly.

I think patch is good.

Super duper CPUs which speculate thousands instructions forward won't
care but more embedded ones do. Or in other words 1 unnecessary instruction
on common path is more important for slow CPUs than for fast CPUs.

This style separates common path from error path more cleanly.

And finally "len" here is local, so the issue barely deserves mention
but if target is in memory code like this happens:

	static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)
	{
	        struct fd f = fdget(fd);
	        struct socket *sock;
	
	        *err = -EBADF;
	        if (f.file) {
	
			// unconditionally write to *err as well.

	                sock = sock_from_file(f.file, err);
	                if (likely(sock)) {
	                        *fput_needed = f.flags;
	                        return sock;
	                }
	                fdput(f);
	        }
	        return NULL;
	}

so current style promotes more memory dirtying than necessary.

There is another place like this in sk_buff.c (search for ENOBUFS).

> >  	pathname = d_path(path, tmp, PAGE_SIZE);
> > -	len = PTR_ERR(pathname);
> > -	if (IS_ERR(pathname))
> > +	if (IS_ERR(pathname)) {
> > +		len = PTR_ERR(pathname);
> >  		goto out;
> > +	}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ