From patchwork Thu Dec 21 13:46:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 122572 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp910937qgn; Thu, 21 Dec 2017 05:48:50 -0800 (PST) X-Google-Smtp-Source: ACJfBot7UIZzvaVkZGQ3bUL7gSBkLsN7SG3vV+WF23mbswcDBUmi2LIC9deI7Ndx+H91Zxjhzhhm X-Received: by 10.101.98.1 with SMTP id d1mr9418424pgv.18.1513864130265; Thu, 21 Dec 2017 05:48:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513864130; cv=none; d=google.com; s=arc-20160816; b=FRm7koctcM51hW7QR3rkRg4AYyyHZeGAKlV0q/V5yH1ELRutorLFo2mTcVT60sgJg5 GPKMYScNHrsyHEYUm6GyYpk+GUm53DQQ7Q++c6gkJy+JqEqT6WxtFKjPyNGwQCLTChpb sXgBIKJ8tq3equ2mN5d84jWVLwJSc9dUByL+HLtPc5mAzuuaEss6MG+gXI5lsRdvIv27 YFajYD+lrO+942Ox9V0yHRIyN99VufmDT745s+Bm4GbV5jr3WbuJIM94d09H5HHywzAn 9fTn1UoGCydJrzitLV114pZRkpNcTh2h2gbIo7V5cbbpEUPYC1hUIXFNFyxhksxqDVqf 4j8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=4utCdXtVBt0TF65fth/yy7AW/FLTDY1cRJxVtU1qOjg=; b=iMESN+T71/H8dztE6v+fbKOVvz9cXKauCh87P64bKN/rmBSBSo0vJZGzbS+mttmfF0 tS9kUT/BEbtcOTbDe4HETI/ti6q5zf9OBSuw8kY1Z+KiQT6nHGP4nLX8cik4RpFRCfWx BG07MZrlHZcLc/CM/yEfVJNwJixnFu4wOLHSRXucjfIbwOSlOyegQ4i7Uf2Sy8VjVevr DkTIuSldoCHL4HL9LQzaB1WjYUb2JiYQGvhgFuo4KsOmPHS4a6RMdTeZfbEGx8du95pi nmPnP8g07FPIX2ZlNnf2Xk6fhMbJsv+ZjWj8o788lg635NRdxTyNHDzzFrUsfS6Aq4mw tEcg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 f90si14770482plb.102.2017.12.21.05.48.50; Thu, 21 Dec 2017 05:48:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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 stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752613AbdLUNss (ORCPT + 10 others); Thu, 21 Dec 2017 08:48:48 -0500 Received: from mout.kundenserver.de ([212.227.126.131]:59005 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750983AbdLUNsr (ORCPT ); Thu, 21 Dec 2017 08:48:47 -0500 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue006 [212.227.15.129]) with ESMTPA (Nemesis) id 0LuFsJ-1fABjs48j1-011m9g; Thu, 21 Dec 2017 14:48:00 +0100 From: Arnd Bergmann To: Andrew Morton Cc: Arnd Bergmann , stable@vger.kernel.org, Mauro Carvalho Chehab , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , kasan-dev@googlegroups.com, Masahiro Yamada , Michal Marek , Ingo Molnar , Byungchul Park , "Paul E. McKenney" , Peter Zijlstra , Geert Uytterhoeven , Josh Poimboeuf , Thomas Gleixner , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org Subject: [PATCH] [v4] kasan: rework Kconfig settings Date: Thu, 21 Dec 2017 14:46:39 +0100 Message-Id: <20171221134744.2295529-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:evYB8KE6K1Lps9PZ3v+Xq/JX49RWYwFGbH1f1NpgWHn89iMTCUA 0a5H+WC9VdfUOanX4tvg0wjwi7j++kgXBBQlrsXnubIQPFf/05djXUjssTMIN1x7JqBN0Pe +P/cbt0XBwRJ80me1Kkl0VOw2WkUxDhgrRyVeZmuMHI1zh00+8SpIyfmutl+hhxEa6T6tlV odnMrikuqjP11gdIoXAtg== X-UI-Out-Filterresults: notjunk:1; V01:K0:U0d+hQqTUmI=:0oGsB4nMpQjIXCDK+8d0b9 5Pxh0b8wOZrpRafQLr+t+xq3XfYsC2fKUiUw9yZTGHr/gTVJR6q1r7j++KIdM2GA+gDZ36CKm lX0QwQ55EcpqGdEOkXEenK8/pVIdLqjx6ar8mRBpCz6lFjo3WUF8T0iybK1n0Fflx99Lrhu0+ ppBT3svLOkakwR8NpaKX7VuGQL5aAP4wzR5z6Js8Ywll91aUtBl0QLLWyaOUyazm00k+VvNG0 9ASzY7QzR5tr1e4l/D7jtCLx6KuI1BaypOOolntXlxiHzCBTcC84FCvW82VigMqHAJ4LKgbX9 IU/wdYB9+XgMuO0wjv83jFn0jikCzXj3aDNE0MMIlz6a2ENcEc1hYYpBU+/le6xjQJlJTt8eW i5/PI26o/ccEt/rQe6ZyPV2KiviVSl7GgoehZYTkrOm8RIqReCqLvAtXdVRdaaL97kyasJlld IADaGl52w5lq7+XZQnVUU3WC9p/By2tO9AB4Yct3A/Du3JsqwcJp6lydzGM740wdKBnD+wm9B 4BoPJe24zkyUcADF9RND9XxIb3xbx3Nad/F34is4p/qmA/NslmPAiM9tEhnMLgjrY/BOVxytf vhQyu+62Ujmw0CtOGtWUy5eQI/1byM52eVVnIWbX0eX9Ld/GWONWgVgDCPgPW8e/B6MQIGkVP jebqXxvq+V59l/NzwEwi4razJXQyRmxFOyqxzQQNrwm7WM5nY8MlAg4uqzop0l5t82+r4i+eH JOG4OS3MsvA+ujuYTEw6zBk9AOLNGH6jWYDqjg== Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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/gpu/drm/i915/gvt/handlers.c:2434:1: warning: the frame size of 46176 bytes is larger than 3072 bytes drivers/net/wireless/ralink/rt2x00/rt2800lib.c:5650:1: warning: the frame size of 23632 bytes is larger than 3072 bytes lib/atomic64_test.c:250:1: warning: the frame size of 11200 bytes is larger than 3072 bytes drivers/gpu/drm/i915/gvt/handlers.c:2621:1: warning: the frame size of 9208 bytes is larger than 3072 bytes drivers/media/dvb-frontends/stv090x.c:3431:1: warning: the frame size of 6816 bytes is larger than 3072 bytes fs/fscache/stats.c:287:1: warning: the frame size of 6536 bytes is larger than 3072 bytes To reduce this risk, -fsanitize-address-use-after-scope is now split out into a separate CONFIG_KASAN_EXTRA Kconfig option, 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. All patches to get the frame size below 2048 bytes with CONFIG_KASAN=y and CONFIG_KASAN_EXTRA=n have been merged by maintainers now, 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. I arbitrarily raise the warning limit for KASAN_EXTRA to 3072 to reduce the noise, but an allmodconfig kernel still has around 50 warnings on gcc-7. 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 (without CONFIG_KASAN). With earlier versions of this patch series, I also had patches to address the warnings we get with KASAN and/or KASAN_EXTRA, using a "noinline_if_stackbloat" annotation. That annotation now got replaced with a gcc-8 bugfix (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715) and a workaround for older compilers, which means that KASAN_EXTRA is now just as bad as before and will lead to an instant stack overflow in a few extreme cases. This reverts parts of commit commit 3f181b4 ("lib/Kconfig.debug: disable -Wframe-larger-than warnings with KASAN=y"). Two patches in linux-next should be merged first to avoid introducing warnings in an allmodconfig build: 3cd890dbe2a4 ("media: dvb-frontends: fix i2c access helpers for KASAN") 16c3ada89cff ("media: r820t: fix r820t_write_reg for KASAN") Cc: stable@vger.kernel.org Cc: Mauro Carvalho Chehab Cc: Andrey Ryabinin Cc: Alexander Potapenko Cc: Dmitry Vyukov Cc: kasan-dev@googlegroups.com Signed-off-by: Arnd Bergmann --- --- lib/Kconfig.debug | 2 +- lib/Kconfig.kasan | 11 +++++++++++ scripts/Makefile.kasan | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) -- 2.9.0 Acked-by: Andrey Ryabinin diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 811e5019b36a..84b4ffa67596 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 1280 if (!64BIT && PARISC) default 1024 if (!64BIT && !PARISC) diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan index e39de4191480..8613a6fc4bda 100644 --- a/lib/Kconfig.kasan +++ b/lib/Kconfig.kasan @@ -21,6 +21,17 @@ 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 && DEBUG_KERNEL && !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. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 has more + + choice prompt "Instrumentation type" depends on KASAN diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan index 1ce7115aa499..02f4d2974073 100644 --- a/scripts/Makefile.kasan +++ b/scripts/Makefile.kasan @@ -30,5 +30,8 @@ else endif endif +ifdef CONFIG_KASAN_EXTRA CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope) endif + +endif