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: <20150821065103.GA4541@gmail.com>
Date:	Fri, 21 Aug 2015 08:51:03 +0200
From:	Ingo Molnar <mingo@...nel.org>
To:	Prarit Bhargava <prarit@...hat.com>
Cc:	linux-kernel@...r.kernel.org, Thomas Gleixner <tglx@...utronix.de>,
	Ingo Molnar <mingo@...hat.com>,
	"H. Peter Anvin" <hpa@...or.com>, x86@...nel.org,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>
Subject: Re: [PATCH] x86, bitops, variable_test_bit should return 1 not -1 on
 a match


* Prarit Bhargava <prarit@...hat.com> wrote:

> This issue was noticed while debugging a CPU hotplug issue.  On x86
> with (NR_CPUS > 1) the cpu_online() define is cpumask_test_cpu().
> cpumask_test_cpu() should return 1 if the cpu is set in cpumask and
> 0 otherwise.
> 
> However, cpumask_test_cpu() returns -1 if the cpu in the cpumask is
> set and 0 otherwise.  This happens because cpumask_test_cpu() calls
> test_bit() which is a define that will call variable_test_bit().
> 
> variable_test_bit() calls the assembler instruction sbb (Subtract
> with Borrow, " Subtracts the source from the destination, and subtracts 1
> extra if the Carry Flag is set. Results are returned in "dest".)
> 
> A bit match results in -1 being returned from variable_test_bit() if a
> match occurs, not 1 as the function is supposed to.  This can be easily
> resolved by adding a "!!" to force 0 or 1 as a return.
> 
> It looks like the code never does, for example, (test_bit() == 1) so this
> change should not have any impact.
> 
> Cc: Thomas Gleixner <tglx@...utronix.de>
> Cc: Ingo Molnar <mingo@...hat.com>
> Cc: "H. Peter Anvin" <hpa@...or.com>
> Cc: x86@...nel.org
> Cc: linux-kernel@...r.kernel.org
> Signed-off-by: Prarit Bhargava <prarit@...hat.com>
> ---
>  arch/x86/include/asm/bitops.h |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
> index cfe3b95..a87a5fb 100644
> --- a/arch/x86/include/asm/bitops.h
> +++ b/arch/x86/include/asm/bitops.h
> @@ -320,7 +320,7 @@ static inline int variable_test_bit(long nr, volatile const unsigned long *addr)
>  		     : "=r" (oldbit)
>  		     : "m" (*(unsigned long *)addr), "Ir" (nr));
>  
> -	return oldbit;
> +	return !!oldbit;
>  }
>  
>  #if 0 /* Fool kernel-doc since it doesn't do macros yet */

Ok, I think this is a good fix to improve the robustness of this primitive, unless 
someone objects.

I tried to find the CPU hotplug code that broke with cpu_online() returning -1 but 
failed - all current mainline usage sites seem to be testing for nonzero in one 
way or another. Could you please point it out?

Thanks,

	Ingo
--
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