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]
Date:	Tue, 15 Sep 2015 14:21:20 -0700
From:	Andrew Morton <akpm@...ux-foundation.org>
To:	Tejun Heo <tj@...nel.org>
Cc:	John Stultz <john.stultz@...aro.org>,
	LKML <linux-kernel@...r.kernel.org>,
	Ingo Molnar <mingo@...nel.org>,
	"Steven Rostedt (Red Hat)" <rostedt@...dmis.org>,
	Peter Zijlstra <peterz@...radead.org>,
	Masami Hiramatsu <masami.hiramatsu.pt@...achi.com>,
	Michal Nazarewicz <mina86@...a86.com>,
	Prarit Bhargava <prarit@...hat.com>,
	Richard Cochran <richardcochran@...il.com>,
	Thomas Gleixner <tglx@...utronix.de>,
	"Theodore Ts'o" <tytso@....edu>,
	Andreas Dilger <adilger.kernel@...ger.ca>,
	Dave Chinner <dchinner@...hat.com>,
	Joe Perches <joe@...ches.com>,
	Linus Torvalds <torvalds@...ux-foundation.org>
Subject: Re: [RFC][PATCH 0/5] Fixes for abs() usage on 64bit values

On Mon, 14 Sep 2015 23:46:32 -0400 Tejun Heo <tj@...nel.org> wrote:

> Anyways, let's please get abs() working for all types, one way or the
> other.

That would be by far the best solution, of course.

This seems to work OK:

--- a/include/linux/kernel.h~a
+++ a/include/linux/kernel.h
@@ -207,8 +207,11 @@ extern int _cond_resched(void);
  * for those.
  */
 #define abs(x) ({						\
-		long ret;					\
-		if (sizeof(x) == sizeof(long)) {		\
+		s64 ret;					\
+		if (sizeof(x) == sizeof(s64)) {			\
+			s64 __x = (x);				\
+			ret = (__x < 0) ? -__x : __x;		\
+		} else if (sizeof(x) == sizeof(long)) {		\
 			long __x = (x);				\
 			ret = (__x < 0) ? -__x : __x;		\
 		} else {					\

Test case:

--- /dev/null
+++ a/lib/xx.c
@@ -0,0 +1,33 @@
+#include <linux/kernel.h>
+
+#define newabs(x) ({						\
+		s64 ret;					\
+		if (sizeof(x) == sizeof(s64)) {			\
+			s64 __x = (x);				\
+			ret = (__x < 0) ? -__x : __x;		\
+		} else if (sizeof(x) == sizeof(long)) {		\
+			long __x = (x);				\
+			ret = (__x < 0) ? -__x : __x;		\
+		} else {					\
+			int __x = (x);				\
+			ret = (__x < 0) ? -__x : __x;		\
+		}						\
+		ret;						\
+	})
+
+#define oldabs(x) ({						\
+		long ret;					\
+		if (sizeof(x) == sizeof(long)) {		\
+			long __x = (x);				\
+			ret = (__x < 0) ? -__x : __x;		\
+		} else {					\
+			int __x = (x);				\
+			ret = (__x < 0) ? -__x : __x;		\
+		}						\
+		ret;						\
+	})
+
+int foo(int x)
+{
+	return oldabs(x);
+}
diff -puN lib/Makefile~b lib/Makefile
--- a/lib/Makefile~b
+++ a/lib/Makefile
@@ -13,7 +13,7 @@ lib-y := ctype.o string.o vsprintf.o cmd
 	 sha1.o md5.o irq_regs.o argv_split.o \
 	 proportions.o flex_proportions.o ratelimit.o show_mem.o \
 	 is_single_threaded.o plist.o decompress.o kobject_uevent.o \
-	 earlycpio.o seq_buf.o nmi_backtrace.o
+	 earlycpio.o seq_buf.o nmi_backtrace.o xx.o
 
 obj-$(CONFIG_ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS) += usercopy.o
 lib-$(CONFIG_MMU) += ioremap.o


on i386, xx.o's text is 68 bytes with either newabs() or oldabs().


lib/percpu_counter.o's text does get larger with newabs().  That's
because __percpu_counter_compare() is doing abs() on an s64, doh.

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