Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/2] Fix some incompatibilites between KASAN and FORTIFY_SOURCE
@ 2020-01-15  6:37 Daniel Axtens
  2020-01-15  6:37 ` [PATCH 1/2] kasan: stop tests being eliminated as dead code with FORTIFY_SOURCE Daniel Axtens
  2020-01-15  6:37 ` [PATCH 2/2] string.h: fix incompatibility between FORTIFY_SOURCE and KASAN Daniel Axtens
  0 siblings, 2 replies; 11+ messages in thread
From: Daniel Axtens @ 2020-01-15  6:37 UTC (permalink / raw)
  To: linux-kernel, linux-mm, kasan-dev
  Cc: linux-s390, linux-xtensa, x86, linuxppc-dev, linux-arm-kernel,
	Daniel Axtens

3 KASAN self-tests fail on a kernel with both KASAN and FORTIFY_SOURCE:
memchr, memcmp and strlen. I have observed this on x86 and powerpc.

When FORTIFY_SOURCE is on, a number of functions are replaced with
fortified versions, which attempt to check the sizes of the
operands. However, these functions often directly invoke __builtin_foo()
once they have performed the fortify check.

This breaks things in 2 ways:

 - the three function calls are technically dead code, and can be
   eliminated. When __builtin_ versions are used, the compiler can detect
   this.

 - Using __builtins may bypass KASAN checks if the compiler decides to
   inline it's own implementation as sequence of instructions, rather than
   emit a function call that goes out to a KASAN-instrumented
   implementation.

The patches address each reason in turn.

As a result, we're also able to remove a snippet of code copy-pasted
between every KASAN implementation that tries (largely unsuccessfully) to
disable FORTIFY_SOURCE under KASAN.

Daniel Axtens (2):
  kasan: stop tests being eliminated as dead code with FORTIFY_SOURCE
  string.h: fix incompatibility between FORTIFY_SOURCE and KASAN

 arch/arm64/include/asm/string.h   |  4 ---
 arch/powerpc/include/asm/string.h |  4 ---
 arch/s390/include/asm/string.h    |  4 ---
 arch/x86/include/asm/string_64.h  |  4 ---
 arch/xtensa/include/asm/string.h  |  3 --
 include/linux/string.h            | 49 +++++++++++++++++++++++--------
 lib/test_kasan.c                  | 30 ++++++++++++-------
 7 files changed, 56 insertions(+), 42 deletions(-)

-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, back to index

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-15  6:37 [PATCH 0/2] Fix some incompatibilites between KASAN and FORTIFY_SOURCE Daniel Axtens
2020-01-15  6:37 ` [PATCH 1/2] kasan: stop tests being eliminated as dead code with FORTIFY_SOURCE Daniel Axtens
2020-01-15 14:43   ` Dmitry Vyukov
2020-01-15 14:47     ` Christophe Leroy
2020-01-15 14:57       ` Dmitry Vyukov
2020-01-16  5:34         ` Daniel Axtens
2020-01-15  6:37 ` [PATCH 2/2] string.h: fix incompatibility between FORTIFY_SOURCE and KASAN Daniel Axtens
2020-01-15 14:56   ` Dmitry Vyukov
2020-01-16  4:59     ` Daniel Axtens
2020-01-16  5:47       ` Dmitry Vyukov
2020-01-16 23:52   ` kbuild test robot

Linux-ARM-Kernel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/0 linux-arm-kernel/git/0.git
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/1 linux-arm-kernel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-kernel linux-arm-kernel/ https://lore.kernel.org/linux-arm-kernel \
		linux-arm-kernel@lists.infradead.org
	public-inbox-index linux-arm-kernel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-arm-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git