From patchwork Thu Jun 22 17:13:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 106229 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp232797qgd; Thu, 22 Jun 2017 10:16:34 -0700 (PDT) X-Received: by 10.84.215.140 with SMTP id l12mr4116881pli.133.1498151794846; Thu, 22 Jun 2017 10:16:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498151794; cv=none; d=google.com; s=arc-20160816; b=J2IxTBgNkosQT94FDE+LTYzLm2TgxQSq2zAO4s/s1Rd/0Q2DH7Ivxi8XULKAO9Fj6c 5DsfljVpXhR99XbQTJrnWxqi0xcj5roWS4fz2WispKP+G6HTekTOONW1NIMsFkXWRUqs MrUllgSFbNQwIK836zUdGJDRGPtJXh8zqrloOfzh3zFNJrd18ecQQkvrumOSJEW80wgW cc8A+IFxcdTz4Dt3NXzlRZy4ihtj5+RWSN0AAAVFYqiW2WqWdGkWYb8Tic1Txi4laC5r cvImGjCZhFGVIuThbTroEd0wQJTOhImJ1gS+rv/Sldj6/8jyWeHVKPp113y0KZ1bQcQi Ft0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=XQcHqDi22nknf2BD5+1xJ0RBVFs+Lc7QAPRD+TzkIbY=; b=ZC/GJRBb6PDmHayw3pGY172cyefpDRqCqC0hyOZmvmx97QG4DA4D3IOXI1oJFgMCse cmRHOMrgBhxlMTFywyvyjcAjVeMAWVt2qzJb1E/jWAaGP3ZTk6jzO2oQW7gbLrquWOwv szaBnnb/z6AAFrNDRTbVca5nZEl42ViubNQEVieC9hcKlCtl+TYH0VyXnxC+e+5167sx yRA+1GV+YjLPtbKjaocmR0WP1l4jDc7OJU8hwBiNeHidWwNOGk3Qo3IcGTYzqRF0rCQW e2zZnMJXoHOhBpTz5LbyCJVX+stmvrkcKOVmuBw3zCT65vUr5IzHRX10mKgC/Vrq5SuS 3PwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e6si1653354plk.0.2017.06.22.10.16.33; Thu, 22 Jun 2017 10:16:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753806AbdFVRP4 (ORCPT + 25 others); Thu, 22 Jun 2017 13:15:56 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:51869 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751193AbdFVRPw (ORCPT ); Thu, 22 Jun 2017 13:15:52 -0400 Received: from wuerfel.lan ([5.56.224.194]) by mrelayeu.kundenserver.de (mreue103 [212.227.15.145]) with ESMTPA (Nemesis) id 0Li23m-1e9kIa3fbm-00nAPh; Thu, 22 Jun 2017 19:14:11 +0200 From: Arnd Bergmann To: Andrew Morton Cc: kasan-dev@googlegroups.com, Dmitry Vyukov , Alexander Potapenko , Andrey Ryabinin , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Arend van Spriel , Arnd Bergmann , Masahiro Yamada , Michal Marek , Kees Cook , Ingo Molnar , "David S . Miller" , linux-kbuild@vger.kernel.org, Samuel Thibault , Greg Kroah-Hartman , Jiri Slaby Subject: [PATCH v3 11/11] kasan: rework Kconfig settings Date: Thu, 22 Jun 2017 19:13:55 +0200 Message-Id: <20170622171355.267192-12-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170622171355.267192-1-arnd@arndb.de> References: <20170622171355.267192-1-arnd@arndb.de> X-Provags-ID: V03:K0:QM7Tm9d6OYTrmK16Y29EsAivMspoI9xGIxK6aKCV3EfBQ7Tg4ud z0RxpA7p5Dsoo1Khv0IXQir3evt4x8hH6DFXcMoDl0C46Y137h3iTiVG7UJiVy+NZN/ephz UjoXsj1iA88KVH1SyPaklPUQ7Gp5CaBcQUuCMfSXqkSt/QlrJur2evT3aSJaUb69RP3EA/I 1UmXhPM+vS8R7JRr+J6zA== X-UI-Out-Filterresults: notjunk:1; V01:K0:TUZ17pH1WFY=:lvLfq/q/MAThNJarsoH5aw wqbZJbXHNvwvYIUdWH7a7DDLexP/W5j+lgHS9w2zkZTLmyw12qcdLzEmCHE0HEHe3eh0Yeqcn q4L2Aiu/0mHwVKP9FgdHIpc7hi7+MxtBh6N7TLPDD/Af2U3W3WGqdoqYGpx3+/JBreai9Qt/E lK4cxR68P4YBUbc23axdDIyBjD3AexZO3nqtxSZlz7u6zsT0zUnHVkutF+ylmarK5NdHCVTDD q981SqQtV07hhFEkv6rqJwL3sW/OUaL5BDwR6ZvDdydZc7f4zs/Z3d1+tUI0RGFAc/hDDnHer p0jyEQyiBCbZVIgV//LNlgEE3Su+1iuqXob3JNecDrKtblKYvh1rTMV5CZtHnM/EUeFj1sBMS sNJ4ndcn3XiNZwDbbApR39ajG+lDVI2SGMpz2qE4lzChyxwHKEzha7YwWv2pMPYtoHcTdUgCN Sp/kYCSIA2A8lMHTJaHkbuxWLBh79BQffib23lymEjyj/+RlRO/3nOTAqvxgYr+2qn8k1H/hw uncBWVWrf7UbnSb46HqpxWcc4AsEiUBkyUKcjRaY4YxALSd8iaOQeObIatksYWHL1tjvdb4Fe +WwAJmhPGFb/5kfBewKIOuvcoWY4k5gCbcFFtTlFUtAm3Gh8QatFgwmfaU6mxUoyr48ADi8nf BHzRHgJmTLQN+V4UPMq+f0zOw9E4Y3LusaaSUFshKz3NM+DHeHMWImVVLvMCmMcOLt9E= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We get a lot of very large stack frames using gcc-7.0.1 with the default -fsanitize-address-use-after-scope --param asan-stack=1 options, which can easily cause an overflow of the kernel stack, e.g. drivers/acpi/nfit/core.c:2686:1: warning: the frame size of 4080 bytes is larger than 2048 bytes [-Wframe-larger-than=] drivers/gpu/drm/amd/amdgpu/si.c:1756:1: warning: the frame size of 7304 bytes is larger than 2048 bytes [-Wframe-larger-than=] drivers/gpu/drm/i915/gvt/handlers.c:2200:1: warning: the frame size of 43752 bytes is larger than 2048 bytes [-Wframe-larger-than=] drivers/gpu/drm/vmwgfx/vmwgfx_drv.c:952:1: warning: the frame size of 6032 bytes is larger than 2048 bytes [-Wframe-larger-than=] drivers/isdn/hardware/avm/b1.c:637:1: warning: the frame size of 13200 bytes is larger than 2048 bytes [-Wframe-larger-than=] drivers/media/dvb-frontends/stv090x.c:3089:1: warning: the frame size of 5880 bytes is larger than 2048 bytes [-Wframe-larger-than=] drivers/media/i2c/cx25840/cx25840-core.c:4964:1: warning: the frame size of 93992 bytes is larger than 2048 bytes [-Wframe-larger-than=] drivers/net/wireless/ralink/rt2x00/rt2800lib.c:4994:1: warning: the frame size of 23928 bytes is larger than 2048 bytes [-Wframe-larger-than=] drivers/staging/dgnc/dgnc_tty.c:2788:1: warning: the frame size of 7072 bytes is larger than 2048 bytes [-Wframe-larger-than=] fs/ntfs/mft.c:2762:1: warning: the frame size of 7432 bytes is larger than 2048 bytes [-Wframe-larger-than=] lib/atomic64_test.c:242:1: warning: the frame size of 12648 bytes is larger than 2048 bytes [-Wframe-larger-than=] To reduce this risk, -fsanitize-address-use-after-scope is now split out into a separate Kconfig option, vhich cannot be selected at the same time as KMEMCHECK, leading to stack frames that are smaller than 2 kilobytes most of the time on x86_64. An earlier version of this patch also prevented combining KASAN_EXTRA with KASAN_INLINE, but that is no longer necessary with gcc-7.0.1. A lot of warnings with KASAN_EXTRA go away if we disable KMEMCHECK, as -fsanitize-address-use-after-scope seems to understand the builtin memcpy, but adds checking code around an extern memcpy call. I had to work around a circular dependency, as DEBUG_SLAB/SLUB depended on !KMEMCHECK, while KASAN did it the other way round. Now we handle both the same way. All patches to get the frame size below 2048 bytes with CONFIG_KASAN=y and CONFIG_KASAN_EXTRA=n have been submitted along with this patch, so we can bring back that default now. KASAN_EXTRA=y still causes lots of warnings but now defaults to !COMPILE_TEST to disable it in allmodconfig, and it remains disabled in all other defconfigs since it is a new option. This reverts parts of commit commit 3f181b4 ("lib/Kconfig.debug: disable -Wframe-larger-than warnings with KASAN=y"). I experimented a bit more with smaller stack frames and have another follow-up series that reduces the warning limit for 64-bit architectures to 1280 bytes and 1536 when CONFIG_KASAN (but not KASAN_EXTRA) is enabled, this requires another ~25 patches to address the additional warnings. I also have patches for all KASAN_EXTRA warnings, but we should look at those separately and then decide whether to remove it completely, leaving out -fsanitize-address-use-after-scope. Signed-off-by: Arnd Bergmann --- lib/Kconfig.debug | 4 ++-- lib/Kconfig.kasan | 11 ++++++++++- lib/Kconfig.kmemcheck | 1 + scripts/Makefile.kasan | 3 +++ 4 files changed, 16 insertions(+), 3 deletions(-) -- 2.9.0 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index ddbef2cac189..02ec4a4da7b1 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -217,7 +217,7 @@ config ENABLE_MUST_CHECK config FRAME_WARN int "Warn for stack frames larger than (needs gcc 4.4)" range 0 8192 - default 0 if KASAN + default 3072 if KASAN_EXTRA default 2048 if GCC_PLUGIN_LATENT_ENTROPY default 1024 if !64BIT default 2048 if 64BIT @@ -500,7 +500,7 @@ config DEBUG_OBJECTS_ENABLE_DEFAULT config DEBUG_SLAB bool "Debug slab memory allocations" - depends on DEBUG_KERNEL && SLAB && !KMEMCHECK + depends on DEBUG_KERNEL && SLAB && !KMEMCHECK && !KASAN help Say Y here to have the kernel do limited verification on memory allocation as well as poisoning memory on free to catch use of freed diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan index bd38aab05929..4d17a8f4742f 100644 --- a/lib/Kconfig.kasan +++ b/lib/Kconfig.kasan @@ -5,7 +5,7 @@ if HAVE_ARCH_KASAN config KASAN bool "KASan: runtime memory debugger" - depends on SLUB || (SLAB && !DEBUG_SLAB) + depends on SLUB || SLAB select CONSTRUCTORS select STACKDEPOT help @@ -20,6 +20,15 @@ config KASAN Currently CONFIG_KASAN doesn't work with CONFIG_DEBUG_SLAB (the resulting kernel does not boot). +config KASAN_EXTRA + bool "KAsan: extra checks" + depends on KASAN && !COMPILE_TEST + help + This enables further checks in the kernel address sanitizer, for now + it only includes the address-use-after-scope check that can lead + to excessive kernel stack usage, frame size warnings and longer + compile time. + choice prompt "Instrumentation type" depends on KASAN diff --git a/lib/Kconfig.kmemcheck b/lib/Kconfig.kmemcheck index 846e039a86b4..58b9f3f81dc8 100644 --- a/lib/Kconfig.kmemcheck +++ b/lib/Kconfig.kmemcheck @@ -7,6 +7,7 @@ menuconfig KMEMCHECK bool "kmemcheck: trap use of uninitialized memory" depends on DEBUG_KERNEL depends on !X86_USE_3DNOW + depends on !KASAN depends on SLUB || SLAB depends on !CC_OPTIMIZE_FOR_SIZE depends on !FUNCTION_TRACER diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan index 9576775a86f6..3b3148faf866 100644 --- a/scripts/Makefile.kasan +++ b/scripts/Makefile.kasan @@ -29,5 +29,8 @@ else endif endif +ifdef CONFIG_KASAN_EXTRA CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope) endif + +endif