From patchwork Fri Oct 2 22:15:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11814663 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C8792618 for ; Fri, 2 Oct 2020 22:15:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 99C7C20719 for ; Fri, 2 Oct 2020 22:15:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="jxxjLAVh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725780AbgJBWPg (ORCPT ); Fri, 2 Oct 2020 18:15:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725774AbgJBWPe (ORCPT ); Fri, 2 Oct 2020 18:15:34 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 920E6C0613D0 for ; Fri, 2 Oct 2020 15:15:32 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id y14so1722184pgf.12 for ; Fri, 02 Oct 2020 15:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZbgeNKSFkQV6HyhEuVenlb7h0oRDKk8aNnzV1dp+u/c=; b=jxxjLAVhqgNV8pV6V+zph33zFLdgUf+5TWx4YYjqEojQm4I0eEVVBoM1H6Hp5FvfLC QYt82Esp0qBHXqXKM0Ax1a4r6Iik1ZtaxQhprJrY1fFkOiOVtoeTgRczHdsY/OgOI75P A9p1ol+7i5xnMeVnG4sek2DBQoZgTRm4BDBek= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZbgeNKSFkQV6HyhEuVenlb7h0oRDKk8aNnzV1dp+u/c=; b=dir1jUmxZ7IM1Eqwnx591vA8ej3sZJhiv5SrYF8WYY+tWtPgt6JcxQhBnx5pP/PvSH Qw2Y/ESMDsp7aBWc6lusvJEknmi3BfIE4ECklJn1JrMMXBci9kGFt5PTS0TdIwPV3yH5 a1Hemw6IPWD/wTdT8YWjCH/koq0yNMiqQmaXTj506YcQF7cSpmz4VPciGFzLPiSNys8A gU1p8454AfaQ2hdM71gyjyvhwN1IRBzjazTBo0/pFSoeUYu4UQ8DCFMCvGL/UnCUy6iM j8zhTTZctEbdTbhaQ8jFY4s1NwRkIZNwadvHi0Gd85a13tCyA2jW0hXo0lyHCiE41Pmd SArw== X-Gm-Message-State: AOAM533ZUn1BryNkQVblXdpnvqdPJr4CApds36xtTQ0HaFfb09688hCo cTwuubaN3cKmoy3Mc1U4hQ3fng== X-Google-Smtp-Source: ABdhPJwSla2mXu1bnKfnCi7nfqWrHkn3nEgEq/mYJgCSxqxrMOE9rx9AIP2Kdh7JzaQK5Mb0rgOzNQ== X-Received: by 2002:a63:454f:: with SMTP id u15mr4144313pgk.198.1601676932082; Fri, 02 Oct 2020 15:15:32 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id j25sm3071266pfn.212.2020.10.02.15.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 15:15:29 -0700 (PDT) From: Kees Cook To: Andrew Morton Cc: Kees Cook , Linus Torvalds , Ard Biesheuvel , Arnd Bergmann , Masahiro Yamada , Michal Marek , Nathan Chancellor , Nick Desaulniers , Marco Elver , Randy Dunlap , Dmitry Vyukov , George Popescu , Herbert Xu , Peter Oberparleiter , Andrey Ryabinin , clang-built-linux@googlegroups.com, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] ubsan: Move cc-option tests into Kconfig Date: Fri, 2 Oct 2020 15:15:24 -0700 Message-Id: <20201002221527.177500-2-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201002221527.177500-1-keescook@chromium.org> References: <20201002221527.177500-1-keescook@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Instead of doing if/endif blocks with cc-option calls in the UBSAN Makefile, move all the tests into Kconfig and use the Makefile to collect the results. Suggested-by: Linus Torvalds Link: https://lore.kernel.org/lkml/CAHk-=wjPasyJrDuwDnpHJS2TuQfExwe=px-SzLeN8GFMAQJPmQ@mail.gmail.com/ Signed-off-by: Kees Cook Reviewed-by: Nathan Chancellor Tested-by: Nathan Chancellor --- lib/Kconfig.ubsan | 48 +++++++++++++++++++++++++++++++++++++++- scripts/Makefile.ubsan | 50 ++++++++++++++---------------------------- 2 files changed, 64 insertions(+), 34 deletions(-) diff --git a/lib/Kconfig.ubsan b/lib/Kconfig.ubsan index 58f8d03d037b..c0b801871e0b 100644 --- a/lib/Kconfig.ubsan +++ b/lib/Kconfig.ubsan @@ -36,10 +36,17 @@ config UBSAN_KCOV_BROKEN See https://bugs.llvm.org/show_bug.cgi?id=45831 for the status in newer releases. +config CC_HAS_UBSAN_BOUNDS + def_bool $(cc-option,-fsanitize=bounds) + +config CC_HAS_UBSAN_ARRAY_BOUNDS + def_bool $(cc-option,-fsanitize=array-bounds) + config UBSAN_BOUNDS bool "Perform array index bounds checking" default UBSAN depends on !UBSAN_KCOV_BROKEN + depends on CC_HAS_UBSAN_ARRAY_BOUNDS || CC_HAS_UBSAN_BOUNDS help This option enables detection of directly indexed out of bounds array accesses, where the array size is known at compile time. @@ -47,11 +54,17 @@ config UBSAN_BOUNDS to the {str,mem}*cpy() family of functions (that is addressed by CONFIG_FORTIFY_SOURCE). +config CC_ARG_UBSAN_BOUNDS + string + default "-fsanitize=array-bounds" if CC_HAS_UBSAN_ARRAY_BOUNDS + default "-fsanitize=bounds" + depends on UBSAN_BOUNDS + config UBSAN_LOCAL_BOUNDS bool "Perform array local bounds checking" depends on UBSAN_TRAP - depends on CC_IS_CLANG depends on !UBSAN_KCOV_BROKEN + depends on $(cc-option,-fsanitize=local-bounds) help This option enables -fsanitize=local-bounds which traps when an exception/error is detected. Therefore, it should be enabled only @@ -69,6 +82,38 @@ config UBSAN_MISC own Kconfig options. Disable this if you only want to have individually selected checks. +config UBSAN_SHIFT + def_bool UBSAN_MISC + depends on $(cc-option,-fsanitize=shift) + +config UBSAN_DIV_ZERO + def_bool UBSAN_MISC + depends on $(cc-option,-fsanitize=integer-divide-by-zero) + +config UBSAN_UNREACHABLE + def_bool UBSAN_MISC + depends on $(cc-option,-fsanitize=unreachable) + +config UBSAN_SIGNED_OVERFLOW + def_bool UBSAN_MISC + depends on $(cc-option,-fsanitize=signed-integer-overflow) + +config UBSAN_UNSIGNED_OVERFLOW + def_bool UBSAN_MISC + depends on $(cc-option,-fsanitize=unsigned-integer-overflow) + +config UBSAN_OBJECT_SIZE + def_bool UBSAN_MISC + depends on $(cc-option,-fsanitize=object-size) + +config UBSAN_BOOL + def_bool UBSAN_MISC + depends on $(cc-option,-fsanitize=bool) + +config UBSAN_ENUM + def_bool UBSAN_MISC + depends on $(cc-option,-fsanitize=enum) + config UBSAN_SANITIZE_ALL bool "Enable instrumentation for the entire kernel" depends on ARCH_HAS_UBSAN_SANITIZE_ALL @@ -89,6 +134,7 @@ config UBSAN_ALIGNMENT bool "Enable checks for pointers alignment" default !HAVE_EFFICIENT_UNALIGNED_ACCESS depends on !UBSAN_TRAP + depends on $(cc-option,-fsanitize=alignment) help This option enables the check of unaligned memory accesses. Enabling this option on architectures that support unaligned diff --git a/scripts/Makefile.ubsan b/scripts/Makefile.ubsan index 9716dab06bc7..72862da47baf 100644 --- a/scripts/Makefile.ubsan +++ b/scripts/Makefile.ubsan @@ -1,37 +1,21 @@ # SPDX-License-Identifier: GPL-2.0 -export CFLAGS_UBSAN := +# -fsanitize=* options makes GCC less smart than usual and +# increases the number of 'maybe-uninitialized' false-positives. +ubsan-cflags-$(CONFIG_UBSAN) += $(call cc-disable-warning, maybe-uninitialized) -ifdef CONFIG_UBSAN_ALIGNMENT - CFLAGS_UBSAN += $(call cc-option, -fsanitize=alignment) -endif +# Enable available and selected UBSAN features. +ubsan-cflags-$(CONFIG_UBSAN_ALIGNMENT) += -fsanitize=alignment +ubsan-cflags-$(CONFIG_UBSAN_BOUNDS) += $(CONFIG_CC_ARG_UBSAN_BOUNDS) +ubsan-cflags-$(CONFIG_UBSAN_LOCAL_BOUNDS) += -fsanitize=local-bounds +ubsan-cflags-$(CONFIG_UBSAN_SHIFT) += -fsanitize=shift +ubsan-cflags-$(CONFIG_UBSAN_DIV_ZERO) += -fsanitize=integer-divide-by-zero +ubsan-cflags-$(CONFIG_UBSAN_UNREACHABLE) += -fsanitize=unreachable +ubsan-cflags-$(CONFIG_UBSAN_SIGNED_OVERFLOW) += -fsanitize=signed-integer-overflow +ubsan-cflags-$(CONFIG_UBSAN_UNSIGNED_OVERFLOW) += -fsanitize=unsigned-integer-overflow +ubsan-cflags-$(CONFIG_UBSAN_OBJECT_SIZE) += -fsanitize=object-size +ubsan-cflags-$(CONFIG_UBSAN_BOOL) += -fsanitize=bool +ubsan-cflags-$(CONFIG_UBSAN_ENUM) += -fsanitize=enum +ubsan-cflags-$(CONFIG_UBSAN_TRAP) += -fsanitize-undefined-trap-on-error -ifdef CONFIG_UBSAN_BOUNDS - ifdef CONFIG_CC_IS_CLANG - CFLAGS_UBSAN += -fsanitize=array-bounds - else - CFLAGS_UBSAN += $(call cc-option, -fsanitize=bounds) - endif -endif - -ifdef CONFIG_UBSAN_LOCAL_BOUNDS - CFLAGS_UBSAN += -fsanitize=local-bounds -endif - -ifdef CONFIG_UBSAN_MISC - CFLAGS_UBSAN += $(call cc-option, -fsanitize=shift) - CFLAGS_UBSAN += $(call cc-option, -fsanitize=integer-divide-by-zero) - CFLAGS_UBSAN += $(call cc-option, -fsanitize=unreachable) - CFLAGS_UBSAN += $(call cc-option, -fsanitize=signed-integer-overflow) - CFLAGS_UBSAN += $(call cc-option, -fsanitize=object-size) - CFLAGS_UBSAN += $(call cc-option, -fsanitize=bool) - CFLAGS_UBSAN += $(call cc-option, -fsanitize=enum) -endif - -ifdef CONFIG_UBSAN_TRAP - CFLAGS_UBSAN += $(call cc-option, -fsanitize-undefined-trap-on-error) -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) +export CFLAGS_UBSAN := $(ubsan-cflags-y) From patchwork Fri Oct 2 22:15:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11814655 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C4254618 for ; Fri, 2 Oct 2020 22:15:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C1C1208C7 for ; Fri, 2 Oct 2020 22:15:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="NspRsNBo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725747AbgJBWPc (ORCPT ); Fri, 2 Oct 2020 18:15:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725562AbgJBWPc (ORCPT ); Fri, 2 Oct 2020 18:15:32 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A866C0613D0 for ; Fri, 2 Oct 2020 15:15:32 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id 34so1714654pgo.13 for ; Fri, 02 Oct 2020 15:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=V0SUsmWACvD3dNMBDG6SPv9xQ8I4+FrehwcPDr9x9nQ=; b=NspRsNBoQmAwlT7ORJjoYtbzCkS8Mem1PHd5ELyCp11qlcVrFG/e9NIs9mzirqBWRb sy2KeczTIFS+05DESF5CXcTDsPhucuYeI88jXAgsYuq8GCfBtZ3/bX0BRQ7aw9M6uYNy uz+algmJ3/4kBFBTVxv4JjL7VqNnzzFzjRQ0w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=V0SUsmWACvD3dNMBDG6SPv9xQ8I4+FrehwcPDr9x9nQ=; b=RjIwrqGjJnWMbBNQ8EJuVQLl8HIHSYrBzXlE6ReRZc39l+ZlaVFpsPjyQ/F0j9ghSW RpFS4v9sJrBUjOcUM+RAkG/rE/kmIFUTQweF2t1+jkwJxZN1xs3mIYGfmAFSbk60qlao hLXHVwQeP9eYCbmucb6i1ZvdY4R0d3lfgTVkH3tZj2KhmXTo6DTS0zLG46G7WHFQ3G7f Sv6hIJItb6h5FeAgMdxfX8ztsD/S79/9tdEp9rC7MIf4MD97JrctEFt3sRSaQZOv6th6 3PYPuuJyEtq6Dh33Sg7XyHrbaw6CTnP9YEf4iNuVrxsqxYUQEoRQ1fZIgiXJ+efsD3rD qY4A== X-Gm-Message-State: AOAM530hKBiD/YnyCTFBn9T3uBR9co7Zo6qDXzd0/j0hbnNpuYkizWLx BMzB8umlbXhUKXFfp9ykdnPA0w== X-Google-Smtp-Source: ABdhPJwUyVVoH5EXUD3PrxRHDmHm6dp6faop7SkvnztMQv9qaPMVwZugN89ctYIKMniZcrQvA9CcJQ== X-Received: by 2002:a63:794e:: with SMTP id u75mr4097073pgc.233.1601676931560; Fri, 02 Oct 2020 15:15:31 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id k4sm3349568pfp.189.2020.10.02.15.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 15:15:29 -0700 (PDT) From: Kees Cook To: Andrew Morton Cc: Kees Cook , Linus Torvalds , Ard Biesheuvel , Arnd Bergmann , Masahiro Yamada , Michal Marek , Nathan Chancellor , Nick Desaulniers , Marco Elver , Randy Dunlap , Dmitry Vyukov , George Popescu , Herbert Xu , Peter Oberparleiter , Andrey Ryabinin , clang-built-linux@googlegroups.com, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] ubsan: Disable object-size sanitizer under GCC Date: Fri, 2 Oct 2020 15:15:25 -0700 Message-Id: <20201002221527.177500-3-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201002221527.177500-1-keescook@chromium.org> References: <20201002221527.177500-1-keescook@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org GCC's -fsanitize=object-size (as part of CONFIG_UBSAN_MISC) greatly increases stack utilization. Do not allow this under GCC. Suggested-by: Linus Torvalds Link: https://lore.kernel.org/lkml/CAHk-=wjPasyJrDuwDnpHJS2TuQfExwe=px-SzLeN8GFMAQJPmQ@mail.gmail.com/ Signed-off-by: Kees Cook Reviewed-by: Nathan Chancellor --- lib/Kconfig.ubsan | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Kconfig.ubsan b/lib/Kconfig.ubsan index c0b801871e0b..aeb2cdea0b94 100644 --- a/lib/Kconfig.ubsan +++ b/lib/Kconfig.ubsan @@ -104,6 +104,9 @@ config UBSAN_UNSIGNED_OVERFLOW config UBSAN_OBJECT_SIZE def_bool UBSAN_MISC + # gcc hugely expands stack usage with -fsanitize=object-size + # https://lore.kernel.org/lkml/CAHk-=wjPasyJrDuwDnpHJS2TuQfExwe=px-SzLeN8GFMAQJPmQ@mail.gmail.com/ + depends on !CC_IS_GCC depends on $(cc-option,-fsanitize=object-size) config UBSAN_BOOL From patchwork Fri Oct 2 22:15:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11814659 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 89926112E for ; Fri, 2 Oct 2020 22:15:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 680A120719 for ; Fri, 2 Oct 2020 22:15:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="DQVnedVC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725775AbgJBWPe (ORCPT ); Fri, 2 Oct 2020 18:15:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725769AbgJBWPd (ORCPT ); Fri, 2 Oct 2020 18:15:33 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CAEEC0613E3 for ; Fri, 2 Oct 2020 15:15:33 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id j8so50154pjy.5 for ; Fri, 02 Oct 2020 15:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lFN4zJJOAxPrUtWe6T2NWxoPvGYNWmt8xiSR4tEk7Xo=; b=DQVnedVCMrlyIBVeUrp9oJui2OTAjnE1hnY+RkK1tyss0PkR4sdHxA/IKXkQH9c6Sh bYl3z5fp98ppPZIL90zkL26tvN0mEM3XK3gwTh747XMH+VzNnYjExcaoh7MNRv0l/ewg s1GW+3jl0Olq7FCtH586NGEAyuoqij0CiQUmk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lFN4zJJOAxPrUtWe6T2NWxoPvGYNWmt8xiSR4tEk7Xo=; b=jh+iT+4Wp+Cy+lxhG2qaRjoiFBF5+eyTFlQMhdhJ533uDItB74Um0NHv28yk3zSe0V LJUh+fo1L9bmpiHGAtttbG5mNsl8pN07+jmLwFMDuqu42H1wF0UinesiH8Zb1svuE+VC PBxgWMID6UVDVNHT9rf6WpqZkkmx/G8/5m0PqXlVsTeajeSA2XCdrjdT/U9fhoG9gJA5 b2KDuQWWAW7t2PjhzWvUPstkz7lJ2HQYo23F6hKCETR03g8plK/sbxoClECTNspEkl8m Jy1V/nul11eIARxaAKA5A/TBPW0Jqwt/xSPeZWNuBZY9NWhfBE7TMwJF1RC4GuasbFWv PDWw== X-Gm-Message-State: AOAM532ekr10mOiTsubxbN+DvAfo/JFWnVfS0RTYBVHnMSrHC5eeeToa 55T34YmzDci3zNaBNPUl6s6g3w== X-Google-Smtp-Source: ABdhPJzW4OR+PaSKxteuBOb7B5Lq/dL8VJesrDAtiFmhs3tlfU+OpJB977KxlRZ7LqAh+6+KIC5Igw== X-Received: by 2002:a17:90a:9505:: with SMTP id t5mr4886210pjo.121.1601676932889; Fri, 02 Oct 2020 15:15:32 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id fz22sm2557221pjb.46.2020.10.02.15.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 15:15:29 -0700 (PDT) From: Kees Cook To: Andrew Morton Cc: Kees Cook , Linus Torvalds , Ard Biesheuvel , Arnd Bergmann , Masahiro Yamada , Michal Marek , Nathan Chancellor , Nick Desaulniers , Marco Elver , Randy Dunlap , Dmitry Vyukov , George Popescu , Herbert Xu , Peter Oberparleiter , Andrey Ryabinin , clang-built-linux@googlegroups.com, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] ubsan: Force -Wno-maybe-uninitialized only for GCC Date: Fri, 2 Oct 2020 15:15:26 -0700 Message-Id: <20201002221527.177500-4-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201002221527.177500-1-keescook@chromium.org> References: <20201002221527.177500-1-keescook@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Clang handles 'maybe-uninitialized' better in the face of using UBSAN, so do not make this universally disabled for UBSAN builds. Signed-off-by: Kees Cook --- lib/Kconfig.ubsan | 6 ++++++ scripts/Makefile.ubsan | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Kconfig.ubsan b/lib/Kconfig.ubsan index aeb2cdea0b94..1fc07f936e06 100644 --- a/lib/Kconfig.ubsan +++ b/lib/Kconfig.ubsan @@ -36,6 +36,12 @@ config UBSAN_KCOV_BROKEN See https://bugs.llvm.org/show_bug.cgi?id=45831 for the status in newer releases. +config UBSAN_DISABLE_MAYBE_UNINITIALIZED + def_bool CC_IS_GCC + help + -fsanitize=* options makes GCC less smart than usual and + increases the number of 'maybe-uninitialized' false-positives. + config CC_HAS_UBSAN_BOUNDS def_bool $(cc-option,-fsanitize=bounds) diff --git a/scripts/Makefile.ubsan b/scripts/Makefile.ubsan index 72862da47baf..c5ef6bac09d4 100644 --- a/scripts/Makefile.ubsan +++ b/scripts/Makefile.ubsan @@ -1,8 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 -# -fsanitize=* options makes GCC less smart than usual and -# increases the number of 'maybe-uninitialized' false-positives. -ubsan-cflags-$(CONFIG_UBSAN) += $(call cc-disable-warning, maybe-uninitialized) +# The "maybe-uninitialized" warning can be very noisy. +ubsan-cflags-$(CONFIG_UBSAN_DISABLE_MAYBE_UNINITIALIZED) += \ + $(call cc-disable-warning, maybe-uninitialized) # Enable available and selected UBSAN features. ubsan-cflags-$(CONFIG_UBSAN_ALIGNMENT) += -fsanitize=alignment From patchwork Fri Oct 2 22:15:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11814661 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BA832618 for ; Fri, 2 Oct 2020 22:15:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9AF322072E for ; Fri, 2 Oct 2020 22:15:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="DhD8t5kr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725783AbgJBWPh (ORCPT ); Fri, 2 Oct 2020 18:15:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725773AbgJBWPd (ORCPT ); Fri, 2 Oct 2020 18:15:33 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC5ECC0613E2 for ; Fri, 2 Oct 2020 15:15:33 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id j8so50160pjy.5 for ; Fri, 02 Oct 2020 15:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/J1gHtjcOOv6Rq1ls75T0pkphOgixxdtxsRzhxRApII=; b=DhD8t5kr8ElFUdmH3JdVP9GXM33yLmm67FT7fIl5wwRBQKJJ/2B8l4IoqTbHRe71Lm rDMxMTHC1vGlbvnJqy//diKkTio5j2dEzjhWQuYbgIY6As/lRsNAcxn35knW+xPcOyUk Osj4zkWGzG57f/iA9OCnsuvHzDqlOO1JFlFDU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/J1gHtjcOOv6Rq1ls75T0pkphOgixxdtxsRzhxRApII=; b=inD0QMyB0Wrt9q/5YL44GpXFbJA9Na49KsNZhM8GJDDymJIzSgwwPPRp2g2seskkiu C2GsPj/w5xhNzT7Bp3F2EDtJ9DiijenvuFxWoGIMXs9DS+XhwjY5Mq7ckJ1eZhSizVIP deROUOqHFZEpvcUX2y7tOx0oq9pKcwImm6DhkP63eHmYujS0JeHF/9lZyC6fTYuh3JFh DXudjnUuW+nd/oS5MXCXS/qRqbxSArdINgavXGUOnbKp1T/heaIeZB3E+VjgLmWdsW1r pQ8UJFfKV1GHozGqgablkH0pGUCjeoFcns3JQIABqUg9AbS1uI4v4YgsfBL/CkD8PSfw YRWw== X-Gm-Message-State: AOAM5308P2nxRatatoyodAliUE0oNRpBUiMfLJMkAs+pNQZfuvJYWEFg 5idKtBPTsn6OkU1bvSag0NSZug== X-Google-Smtp-Source: ABdhPJynp5+FxeGECOIttGZMHkFLTgnPXv32Y6n64K/4v4HDOsUQ1brucRflNmhHdgLmUmfggxKPqA== X-Received: by 2002:a17:90a:800c:: with SMTP id b12mr4837503pjn.179.1601676933444; Fri, 02 Oct 2020 15:15:33 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id bt13sm2640065pjb.23.2020.10.02.15.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 15:15:29 -0700 (PDT) From: Kees Cook To: Andrew Morton Cc: Kees Cook , Linus Torvalds , Ard Biesheuvel , Arnd Bergmann , Masahiro Yamada , Michal Marek , Nathan Chancellor , Nick Desaulniers , Marco Elver , Randy Dunlap , Dmitry Vyukov , George Popescu , Herbert Xu , Peter Oberparleiter , Andrey Ryabinin , clang-built-linux@googlegroups.com, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] ubsan: Disable UBSAN_TRAP for all*config Date: Fri, 2 Oct 2020 15:15:27 -0700 Message-Id: <20201002221527.177500-5-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201002221527.177500-1-keescook@chromium.org> References: <20201002221527.177500-1-keescook@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Doing all*config builds attempts build as much as possible. UBSAN_TRAP effectively short-circuits lib/usban.c, so it should be disabled for COMPILE_TEST so that the lib/ubsan.c code gets built. Signed-off-by: Kees Cook Reviewed-by: Nathan Chancellor --- lib/Kconfig.ubsan | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Kconfig.ubsan b/lib/Kconfig.ubsan index 1fc07f936e06..b5b9da0b635a 100644 --- a/lib/Kconfig.ubsan +++ b/lib/Kconfig.ubsan @@ -14,6 +14,7 @@ if UBSAN config UBSAN_TRAP bool "On Sanitizer warnings, abort the running kernel code" + depends on !COMPILE_TEST depends on $(cc-option, -fsanitize-undefined-trap-on-error) help Building kernels with Sanitizer features enabled tends to grow