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: <1381248622-27809-1-git-send-email-anatol.pomozov@gmail.com>
Date:	Tue,  8 Oct 2013 09:10:22 -0700
From:	Anatol Pomozov <anatol.pomozov@...il.com>
To:	linux-kernel@...r.kernel.org
Cc:	joe@...ches.com, rdunlap@...radead.org,
	Anatol Pomozov <anatol.pomozov@...il.com>
Subject: [PATCH] core: Catch overflows in do_div() function

If second parameter passed to this function was 64 then it silently
truncates to 32 bits. Catch such situation.

Signed-off-by: Anatol Pomozov <anatol.pomozov@...il.com>
---
 include/asm-generic/div64.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/asm-generic/div64.h b/include/asm-generic/div64.h
index 8f4e319..84339a0 100644
--- a/include/asm-generic/div64.h
+++ b/include/asm-generic/div64.h
@@ -17,6 +17,7 @@
  *       beware of side effects!
  */
 
+#include <linux/bug.h>
 #include <linux/types.h>
 #include <linux/compiler.h>
 
@@ -25,6 +26,7 @@
 # define do_div(n,base) ({					\
 	uint32_t __base = (base);				\
 	uint32_t __rem;						\
+	BUG_ON(sizeof(base) > 4 && base >= (1UL<<32));		\
 	__rem = ((uint64_t)(n)) % __base;			\
 	(n) = ((uint64_t)(n)) / __base;				\
 	__rem;							\
@@ -40,6 +42,7 @@ extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
 # define do_div(n,base) ({				\
 	uint32_t __base = (base);			\
 	uint32_t __rem;					\
+	BUG_ON(sizeof(base) > 4 && base >= (1UL<<32));	\
 	(void)(((typeof((n)) *)0) == ((uint64_t *)0));	\
 	if (likely(((n) >> 32) == 0)) {			\
 		__rem = (uint32_t)(n) % __base;		\
-- 
1.8.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