mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Anatol Pomozov <anatol.pomozov@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: joe@perches.com, rdunlap@infradead.org,
	Anatol Pomozov <anatol.pomozov@gmail.com>
Subject: [PATCH] core: Catch overflows in do_div() function
Date: Tue,  8 Oct 2013 09:10:22 -0700	[thread overview]
Message-ID: <1381248622-27809-1-git-send-email-anatol.pomozov@gmail.com> (raw)
In-Reply-To: <CAOMFOmXfw2DkesOYip9VFDdUQgVN48qbJfuertPaSCz5aGdaeA@mail.gmail.com>

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@gmail.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


  parent reply	other threads:[~2013-10-08 16:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-30 17:21 do_div() silently truncates "base" to 32bit Anatol Pomozov
2013-08-30 21:23 ` Randy Dunlap
2013-08-30 22:14   ` Anatol Pomozov
2013-08-30 22:48     ` Randy Dunlap
2013-08-30 23:28       ` Joe Perches
2013-08-31  0:50         ` Anatol Pomozov
2013-09-04 15:32           ` Anatol Pomozov
2013-09-04 17:20             ` Randy Dunlap
2013-10-08 16:10 ` Anatol Pomozov [this message]
2013-10-08 16:18   ` [PATCH] core: Catch overflows in do_div() function Joe Perches
2013-10-08 16:45     ` Richard Weinberger
2013-10-08 16:51       ` Joe Perches
2013-10-08 17:28       ` Anatol Pomozov
2013-10-08 17:40         ` Anatol Pomozov
2013-10-08 17:15   ` Eric Dumazet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1381248622-27809-1-git-send-email-anatol.pomozov@gmail.com \
    --to=anatol.pomozov@gmail.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®