linux-kbuild.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 1/7] x86/kasan: generate KASAN_SHADOW_OFFSET in Makefile
       [not found] <1437756119-12817-1-git-send-email-a.ryabinin@samsung.com>
@ 2015-07-24 16:41 ` Andrey Ryabinin
  2015-07-27 16:40   ` Catalin Marinas
  0 siblings, 1 reply; 3+ messages in thread
From: Andrey Ryabinin @ 2015-07-24 16:41 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, linux-arm-kernel
  Cc: Arnd Bergmann, Linus Walleij, David Keitel, Alexander Potapenko,
	Andrew Morton, Dmitry Vyukov, linux-mm, linux-kernel,
	Alexey Klimov, Andrey Ryabinin, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, x86, Michal Marek, linux-kbuild

ARM64 has several different address space layouts and its
going to have one more at least. Different address space layouts
have different shadow offsets, so every new layout require adding
new default value for CONFIG_KASAN_SHADOW_OFFSET.
It's possible to generate KASAN_SHADOW_OFFSET in Makefile, so
the shadow address for every possible layout will be auto-generated.

However, we should do this in x86 too, because generic code
depend on having CONFIG_KASAN_SHADOW_OFFSET.
There is no functional changes here.

Signed-off-by: Andrey Ryabinin <a.ryabinin@samsung.com>
---
 arch/x86/Kconfig             |  5 -----
 arch/x86/Makefile            |  2 ++
 arch/x86/include/asm/kasan.h | 21 +++++++++++++--------
 include/linux/kasan.h        |  1 -
 scripts/Makefile.kasan       |  2 +-
 5 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index b3a1a5d..6d6dd6f 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -255,11 +255,6 @@ config ARCH_SUPPORTS_OPTIMIZED_INLINING
 config ARCH_SUPPORTS_DEBUG_PAGEALLOC
 	def_bool y
 
-config KASAN_SHADOW_OFFSET
-	hex
-	depends on KASAN
-	default 0xdffffc0000000000
-
 config HAVE_INTEL_TXT
 	def_bool y
 	depends on INTEL_IOMMU && ACPI
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 118e6de..c666989 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -39,6 +39,8 @@ ifdef CONFIG_X86_NEED_RELOCS
         LDFLAGS_vmlinux := --emit-relocs
 endif
 
+KASAN_SHADOW_OFFSET := 0xdffffc0000000000
+
 ifeq ($(CONFIG_X86_32),y)
         BITS := 32
         UTS_MACHINE := i386
diff --git a/arch/x86/include/asm/kasan.h b/arch/x86/include/asm/kasan.h
index 74a2a8d..88881f6 100644
--- a/arch/x86/include/asm/kasan.h
+++ b/arch/x86/include/asm/kasan.h
@@ -1,17 +1,22 @@
 #ifndef _ASM_X86_KASAN_H
 #define _ASM_X86_KASAN_H
 
-/*
- * Compiler uses shadow offset assuming that addresses start
- * from 0. Kernel addresses don't start from 0, so shadow
- * for kernel really starts from compiler's shadow offset +
- * 'kernel address space start' >> KASAN_SHADOW_SCALE_SHIFT
- */
-#define KASAN_SHADOW_START      (KASAN_SHADOW_OFFSET + \
-					(0xffff800000000000ULL >> 3))
+#define KASAN_SHADOW_START      (0xffffec0000000000ULL)
 /* 47 bits for kernel address -> (47 - 3) bits for shadow */
 #define KASAN_SHADOW_END        (KASAN_SHADOW_START + (1ULL << (47 - 3)))
 
+/*
+ * This value is used to map an address to the corresponding shadow
+ * address by the following formula:
+ *	shadow_addr = (address >> 3) + KASAN_SHADOW_OFFSET;
+ *
+ * (1 << 61) shadow addresses - [KASAN_SHADOW_OFFSET,KASAN_SHADOW_END]
+ * cover all 64-bits of virtual addresses. So KASAN_SHADOW_OFFSET
+ * should satisfy the following equation:
+ *      KASAN_SHADOW_OFFSET = KASAN_SHADOW_END - (1ULL << 61)
+ */
+#define KASAN_SHADOW_OFFSET (KASAN_SHADOW_END - (1UL << (64 - 3)))
+
 #ifndef __ASSEMBLY__
 
 #ifdef CONFIG_KASAN
diff --git a/include/linux/kasan.h b/include/linux/kasan.h
index 5486d77..6fb1c7d 100644
--- a/include/linux/kasan.h
+++ b/include/linux/kasan.h
@@ -10,7 +10,6 @@ struct vm_struct;
 #ifdef CONFIG_KASAN
 
 #define KASAN_SHADOW_SCALE_SHIFT 3
-#define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL)
 
 #include <asm/kasan.h>
 #include <linux/sched.h>
diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan
index 3f874d2..19d9a61 100644
--- a/scripts/Makefile.kasan
+++ b/scripts/Makefile.kasan
@@ -8,7 +8,7 @@ endif
 CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address
 
 CFLAGS_KASAN := $(call cc-option, -fsanitize=kernel-address \
-		-fasan-shadow-offset=$(CONFIG_KASAN_SHADOW_OFFSET) \
+		-fasan-shadow-offset=$(KASAN_SHADOW_OFFSET) \
 		--param asan-stack=1 --param asan-globals=1 \
 		--param asan-instrumentation-with-call-threshold=$(call_threshold))
 
-- 
2.4.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v4 1/7] x86/kasan: generate KASAN_SHADOW_OFFSET in Makefile
  2015-07-24 16:41 ` [PATCH v4 1/7] x86/kasan: generate KASAN_SHADOW_OFFSET in Makefile Andrey Ryabinin
@ 2015-07-27 16:40   ` Catalin Marinas
  2015-07-27 17:52     ` Andrey Ryabinin
  0 siblings, 1 reply; 3+ messages in thread
From: Catalin Marinas @ 2015-07-27 16:40 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Will Deacon, linux-arm-kernel, Alexey Klimov, Arnd Bergmann,
	linux-mm, Linus Walleij, x86, linux-kernel, linux-kbuild,
	David Keitel, Ingo Molnar, Alexander Potapenko, Michal Marek,
	H. Peter Anvin, Andrew Morton, Thomas Gleixner, Dmitry Vyukov

On Fri, Jul 24, 2015 at 07:41:53PM +0300, Andrey Ryabinin wrote:
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index b3a1a5d..6d6dd6f 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -255,11 +255,6 @@ config ARCH_SUPPORTS_OPTIMIZED_INLINING
>  config ARCH_SUPPORTS_DEBUG_PAGEALLOC
>  	def_bool y
>  
> -config KASAN_SHADOW_OFFSET
> -	hex
> -	depends on KASAN
> -	default 0xdffffc0000000000
> -
>  config HAVE_INTEL_TXT
>  	def_bool y
>  	depends on INTEL_IOMMU && ACPI
> diff --git a/arch/x86/Makefile b/arch/x86/Makefile
> index 118e6de..c666989 100644
> --- a/arch/x86/Makefile
> +++ b/arch/x86/Makefile
> @@ -39,6 +39,8 @@ ifdef CONFIG_X86_NEED_RELOCS
>          LDFLAGS_vmlinux := --emit-relocs
>  endif
>  
> +KASAN_SHADOW_OFFSET := 0xdffffc0000000000

To keep things simple for x86, can you not just define:

KASAN_SHADOW_OFFSET := $(CONFIG_KASAN_SHADOW_OFFSET)

or, even better, in scripts/Makefile.kasan:

KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET)

and set it under arch/arm64/Makefile only.

-- 
Catalin

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4 1/7] x86/kasan: generate KASAN_SHADOW_OFFSET in Makefile
  2015-07-27 16:40   ` Catalin Marinas
@ 2015-07-27 17:52     ` Andrey Ryabinin
  0 siblings, 0 replies; 3+ messages in thread
From: Andrey Ryabinin @ 2015-07-27 17:52 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: Will Deacon, linux-arm-kernel, Alexey Klimov, Arnd Bergmann,
	linux-mm, Linus Walleij, x86, linux-kernel, linux-kbuild,
	David Keitel, Ingo Molnar, Alexander Potapenko, Michal Marek,
	H. Peter Anvin, Andrew Morton, Thomas Gleixner, Dmitry Vyukov

On 07/27/2015 07:40 PM, Catalin Marinas wrote:
> On Fri, Jul 24, 2015 at 07:41:53PM +0300, Andrey Ryabinin wrote:
>> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
>> index b3a1a5d..6d6dd6f 100644
>> --- a/arch/x86/Kconfig
>> +++ b/arch/x86/Kconfig
>> @@ -255,11 +255,6 @@ config ARCH_SUPPORTS_OPTIMIZED_INLINING
>>  config ARCH_SUPPORTS_DEBUG_PAGEALLOC
>>  	def_bool y
>>  
>> -config KASAN_SHADOW_OFFSET
>> -	hex
>> -	depends on KASAN
>> -	default 0xdffffc0000000000
>> -
>>  config HAVE_INTEL_TXT
>>  	def_bool y
>>  	depends on INTEL_IOMMU && ACPI
>> diff --git a/arch/x86/Makefile b/arch/x86/Makefile
>> index 118e6de..c666989 100644
>> --- a/arch/x86/Makefile
>> +++ b/arch/x86/Makefile
>> @@ -39,6 +39,8 @@ ifdef CONFIG_X86_NEED_RELOCS
>>          LDFLAGS_vmlinux := --emit-relocs
>>  endif
>>  
>> +KASAN_SHADOW_OFFSET := 0xdffffc0000000000
> 
> To keep things simple for x86, can you not just define:
> 
> KASAN_SHADOW_OFFSET := $(CONFIG_KASAN_SHADOW_OFFSET)
> 
> or, even better, in scripts/Makefile.kasan:
> 
> KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET)
> 
> and set it under arch/arm64/Makefile only.
> 

Yes, this much better.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-07-27 17:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1437756119-12817-1-git-send-email-a.ryabinin@samsung.com>
2015-07-24 16:41 ` [PATCH v4 1/7] x86/kasan: generate KASAN_SHADOW_OFFSET in Makefile Andrey Ryabinin
2015-07-27 16:40   ` Catalin Marinas
2015-07-27 17:52     ` Andrey Ryabinin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).