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-next>] [day] [month] [year] [list]
Date:   Sat, 19 Jan 2019 16:14:50 +0100
From:   Florian La Roche <florian.laroche@...glemail.com>
To:     linux-kernel@...r.kernel.org
Cc:     Crt Mori <cmo@...exis.com>, Joe Perches <joe@...ches.com>,
        Davidlohr Bueso <dave@...olabs.net>,
        Will Deacon <will.deacon@....com>,
        Peter Zijlstra <peterz@...radead.org>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        Florian La Roche <Florian.LaRoche@...glemail.com>
Subject: fix int_sqrt() for very large numbers

If an input number x for int_sqrt() has the highest bit set, then
__ffs(x) is 64. (1UL << 64) is an overflow and breaks the algorithm.

Just subtracting 1 is an even better guess for the initial
value of m and that's what also used to be done in earlier
versions of this code.

best regards,

Florian La Roche

Signed-off-by: Florian La Roche <Florian.LaRoche@...glemail.com>
---
 lib/int_sqrt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/int_sqrt.c b/lib/int_sqrt.c
index 14436f4ca6bd..ea00e84dc272 100644
--- a/lib/int_sqrt.c
+++ b/lib/int_sqrt.c
@@ -23,7 +23,7 @@ unsigned long int_sqrt(unsigned long x)
 	if (x <= 1)
 		return x;
 
-	m = 1UL << (__fls(x) & ~1UL);
+	m = 1UL << ((__fls(x) - 1) & ~1UL);
 	while (m != 0) {
 		b = y + m;
 		y >>= 1;
@@ -52,7 +52,7 @@ u32 int_sqrt64(u64 x)
 	if (x <= ULONG_MAX)
 		return int_sqrt((unsigned long) x);
 
-	m = 1ULL << (fls64(x) & ~1ULL);
+	m = 1ULL << ((fls64(x) - 1) & ~1ULL);
 	while (m != 0) {
 		b = y + m;
 		y >>= 1;
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ