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]
Message-Id: <1449156616-11474-1-git-send-email-sasha.levin@oracle.com>
Date:	Thu,  3 Dec 2015 10:30:16 -0500
From:	Sasha Levin <sasha.levin@...cle.com>
To:	torvalds@...ux-foundation.org
Cc:	linux-kernel@...r.kernel.org, Sasha Levin <sasha.levin@...cle.com>
Subject: [PATCH] linux/log2.h: Fix roundup_pow_of_two(0)

Passing 0 to roundup_pow_of_two would lead to wrapping around and trying to
find the last set bit on (unsigned long)(-1), which is obviously wrong.

Instead, deal with this case by rounding it up to the closest power of two
(2 ** 0).

Signed-off-by: Sasha Levin <sasha.levin@...cle.com>
---
 include/linux/log2.h |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/log2.h b/include/linux/log2.h
index fd7ff3d..b6bdf0c 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -60,6 +60,9 @@ bool is_power_of_2(unsigned long n)
 static inline __attribute__((const))
 unsigned long __roundup_pow_of_two(unsigned long n)
 {
+	if (n == 0)
+		return 1UL << 0;
+
 	return 1UL << fls_long(n - 1);
 }
 
-- 
1.7.10.4

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