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: <alpine.LFD.2.00.1006091408430.4506@i5.linux-foundation.org>
Date:	Wed, 9 Jun 2010 14:21:13 -0700 (PDT)
From:	Linus Torvalds <torvalds@...ux-foundation.org>
To:	Salman <sqazi@...gle.com>
cc:	peterz@...radead.org, akpm@...ux-foundation.org, mingo@...e.hu,
	linux-kernel@...r.kernel.org, tytso@...gle.com
Subject: Re: [PATCH] Fix a race in pid generation that causes pids to be
 reused immediately.



On Wed, 9 Jun 2010, Salman wrote:
> +/*
> + * If we started walking pids at 'base', is 'a' seen before 'b'?
> + *
> + */
> +static int pid_before(int base, int a, int b)
> +{
> +	int a_lt_b = (a < b);
> +	int min_a_b = min(a, b);
> +	int max_a_b = max(a, b);
> +
> +	if ((base <= min_a_b) || (base >= max_a_b))
> +		return a_lt_b;
> +
> +	return !a_lt_b;
> +}

Ok, so that's a very confusing expression. I'm sure it gets the right 
value, but it's not exactly straightforward, is it?

Wouldn't it be nicer to write it out in a more straightforward way? 
Something like

	/* a and b in order? base must not be between them */
	if (a <= b)
		return (base <= a || base >= b);
	/* b < a? We reach 'a' first iff base is between them */
	return base >= b && base <= a;

would seem to be equivalent and easier to explain, no?

And when you write it that way, it looks like the compiler should be able 
to trivially CSE the five comparisons down to just three (notice how the 
"base <= a" and "base >= b" comparisons are repeated. Which I'm sure some 
super-optimizing compiler can do from your version too, but mine seems 
more straightforward.

But maybe I did that thing wrong, and I just confused myself. I have _not_ 
checked the logic deeply, somebody else should definitely double-check me.

		Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ