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: <1454346499-31868-1-git-send-email-aryabinin@virtuozzo.com>
Date:	Mon, 1 Feb 2016 20:08:19 +0300
From:	Andrey Ryabinin <aryabinin@...tuozzo.com>
To:	<akpm@...ux-foundation.org>
CC:	<krinkin.m.u@...il.com>, <ying.huang@...ux.intel.com>,
	<davej@...emonkey.org.uk>, <x86@...nel.org>,
	<linux-kernel@...r.kernel.org>,
	Andrey Ryabinin <aryabinin@...tuozzo.com>
Subject: [PATCH -mm] ubsan, x86: disable alignemnt checks for arch/x86/*

On 01/30/2016 03:36 AM, Mike Krinkin wrote:
> option CONFIG_UBSAN_ALIGNMENT breaks x86-64 kernel with lockdep enabled,
> i. e kernel with CONFIG_UBSAN_ALIGNMENT fails to load without even any
> error message.
>
> The problem is that ubsan callbacks use spinlocks and might be called
> before lockdep is initialized.

There is also report from kernel test robot:
[    0.000000] WARNING: lockdep init error: lock 'report_lock' was acquired before lockdep_init().
[    0.000000] Call stack leading to lockdep invocation was:
[    0.000000]  [<b9e30ec5>] save_stack_trace+0x26/0x16d
[    0.000000]  [<b9f98054>] __lock_acquire+0x237/0x15a4
[    0.000000]  [<b9f994db>] lock_acquire+0x11a/0x1a9
[    0.000000]  [<bae228f9>] _raw_spin_lock_irqsave+0x39/0x49
[    0.000000]  [<ba5df852>] ubsan_prologue+0x1e/0x51
[    0.000000]  [<ba5dfb02>] __ubsan_handle_type_mismatch+0xbd/0x14a
[    0.000000]  [<bbca63c3>] reserve_ebda_region+0x8b/0x1bb
[    0.000000]  [<bbca632c>] i386_start_kernel+0xf6/0x102
[    0.000000]  [<ffffffff>] 0xffffffff

Let's disable aligment checks for x86-specific code since those are not
useful.
Changes around CFLAGS_UBSAN in this patch needed to be sure that cflags
from 'subdir-ccflags-' appears only after CFLAGS_UBSAN.

Signed-off-by: Andrey Ryabinin <aryabinin@...tuozzo.com>
Reported-by: kernel test robot <ying.huang@...ux.intel.com>
Reported-by: Mike Krinkin <krinkin.m.u@...il.com>
---
 Makefile               | 2 +-
 arch/x86/Kbuild        | 2 ++
 scripts/Makefile.lib   | 4 ++--
 scripts/Makefile.ubsan | 5 +++++
 4 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 6c1a3c2..1da29a0 100644
--- a/Makefile
+++ b/Makefile
@@ -411,7 +411,7 @@ export MAKE AWK GENKSYMS INSTALLKERNEL PERL PYTHON UTS_MACHINE
 export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
 
 export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
-export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV CFLAGS_KASAN CFLAGS_UBSAN
+export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV CFLAGS_KASAN
 export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
 export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
 export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
diff --git a/arch/x86/Kbuild b/arch/x86/Kbuild
index 1538562..f1348ce 100644
--- a/arch/x86/Kbuild
+++ b/arch/x86/Kbuild
@@ -21,3 +21,5 @@ obj-y += platform/
 obj-y += net/
 
 obj-$(CONFIG_KEXEC_FILE) += purgatory/
+
+subdir-ccflags-$(CONFIG_UBSAN_ALIGNMENT) := $(call cc-option, -fno-sanitize=alignment)
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 2edbcad..d7342cf 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -132,8 +132,8 @@ endif
 
 ifeq ($(CONFIG_UBSAN),y)
 _c_flags += $(if $(patsubst n%,, \
-		$(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \
-		$(CFLAGS_UBSAN))
+		$(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)),, \
+		$(DISABLE_UBSAN))
 endif
 
 # If building the kernel in a separate objtree expand all occurrences
diff --git a/scripts/Makefile.ubsan b/scripts/Makefile.ubsan
index 77ce538..91c1dd3 100644
--- a/scripts/Makefile.ubsan
+++ b/scripts/Makefile.ubsan
@@ -18,4 +18,9 @@ endif
       # -fsanitize=* options makes GCC less smart than usual and
       # increase number of 'maybe-uninitialized false-positives
       CFLAGS_UBSAN += $(call cc-option, -Wno-maybe-uninitialized)
+
+      KBUILD_CFLAGS += $(CFLAGS_UBSAN)
+      export DISABLE_UBSAN
+      DISABLE_UBSAN := $(call cc-option, -fno-sanitize=undefined)
+      DISABLE_UBSAN += $(call cc-option, -Wmaybe-uninitialized)
 endif
-- 
2.4.10

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ