Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp296233pxj; Thu, 17 Jun 2021 02:59:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvWJU/R7ujhwjP/e7HDWP+G8KOPPdXQIRmlEItVEGHk7wHZKwjRo9i2pj8goPSU+ZCC/3Y X-Received: by 2002:a05:6602:38d:: with SMTP id f13mr3148242iov.109.1623923982992; Thu, 17 Jun 2021 02:59:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623923982; cv=none; d=google.com; s=arc-20160816; b=NL7o3dSdWPgjEyfci6v174USAFNIvnWKjlE39ZA9SPNurQti1CuLLD9IEYqWR4ZtJs GaPDUfI2t0T34Hqp9/cZWp3PjGupbS//irK0RRRuCEmPPI7PdzKFAQZMvne9wPAZVcyE FsyvBHj0xda4iRYvoqZdFtAUilr6bcF+ovolZf8cIJcGvO07BrFvDiVeFLArPoR8wTA/ PgGcmuWJyDJcVh+YU4d155VxkpACQa+vQtdyKGzfyME/7ix60DEbCvy0YHcoHcgHvVts WsfiIVcUkEO2/HM4FxpGMWY4lCW2pMLMrOGbFAWcpm6cN3/19KAKi0e6FVErPR+DdIYO WUtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1nSYxJY0N3aZr/pdi8HOrkpkeyyKzwB00+Ef/RsvCEU=; b=KheVjIlZGDWZ2BLxiN47b8FWdRp4c17CzvpH+ZQVE9ciyg4EwdynMZCeYptL36BOPZ YzBnYX7/0F87FZUBF04ZrQqqZCTJ5gZEk/w+tZnlyQUOK8bVg/ET6cArfC4wWRAdyft8 3YEgWb2WGl9Oz0106ojXfowZJMXUCZ7oSw5f+3FPnbC32Ur6Mxb+AaRyxJifAJxzPb7x VK25Xe6AYYD5gaBsP8XpSBp1OLOC3y7P/TOt3PnfHEO9gLL9XewUJdFvZdZwl9OF86eU Jqjyk86amAdkVQAtT9Pam3DMd9MEDoXm0gCRcv5zp5575aId3VDQFBEuHXpjZdg1ySeF ER6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@axtens.net header.s=google header.b=VxBhETKa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h13si5597337iop.97.2021.06.17.02.59.31; Thu, 17 Jun 2021 02:59:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@axtens.net header.s=google header.b=VxBhETKa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231501AbhFQJcu (ORCPT + 99 others); Thu, 17 Jun 2021 05:32:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231398AbhFQJcu (ORCPT ); Thu, 17 Jun 2021 05:32:50 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01144C061574 for ; Thu, 17 Jun 2021 02:30:43 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id t9so4476372pgn.4 for ; Thu, 17 Jun 2021 02:30:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1nSYxJY0N3aZr/pdi8HOrkpkeyyKzwB00+Ef/RsvCEU=; b=VxBhETKa1BkglHL6eiGuDKau5qIlvO2SE6buqTTYwaSC4Qq5gYa8/0Iu8HTz88B0+o bv8FuQFbSiqr5YoaoJu0h/DwAkJzkeYN4j9I34Y3qNg1dnVP4NtMb2C4vKeoWXhrcSFi LAMbptK+3YwoGNurib7Mg7XZAtIEpcnkIpe6s= 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=1nSYxJY0N3aZr/pdi8HOrkpkeyyKzwB00+Ef/RsvCEU=; b=Vv4YwxCQHV6NOA3JaJBYap71mYqZs1sMnaRq6oWMwa8IGjsFyz3NPNHtMwFl9ALHA8 pYgpgMkfVrJKLAb7wz6WU20RxLlomVRFpBR5u6umeIk/1U7SsOUOZQzHudkVt/NuZx6u PHWagonrJ8NiArfuPurRB2HU47u97qmiyHQQlIWFudvUdobL+KukXZrneP4+tbeG99Xp RJ2KE0tnX6/3a+9RigRZnr5dcFGXXQ1wYgab7KWxYxQ3Zkm592HgtRxU7TOAZ8DyPdLA ILDUCWR2KskP0FUHUAUTotPUXEMX4iZyw8schCOjb1twouMKWjB/e7IoJJJddH1RHD/W BmcQ== X-Gm-Message-State: AOAM531imh1y1LalQmI4OcXtr0cf04wE3uArGWLygWYbAT9yhISKJ87p wVu9QvhGDQpsyAP1ZO228Z1DSLl2qaZfEA== X-Received: by 2002:a62:380c:0:b029:2f7:4057:c3ed with SMTP id f12-20020a62380c0000b02902f74057c3edmr4363473pfa.21.1623922242435; Thu, 17 Jun 2021 02:30:42 -0700 (PDT) Received: from localhost ([203.206.29.204]) by smtp.gmail.com with ESMTPSA id a23sm4404876pff.43.2021.06.17.02.30.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:30:42 -0700 (PDT) From: Daniel Axtens To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, elver@google.com, akpm@linux-foundation.org, andreyknvl@gmail.com Cc: linuxppc-dev@lists.ozlabs.org, christophe.leroy@csgroup.eu, aneesh.kumar@linux.ibm.com, bsingharora@gmail.com, Daniel Axtens Subject: [PATCH v15 1/4] kasan: allow an architecture to disable inline instrumentation Date: Thu, 17 Jun 2021 19:30:29 +1000 Message-Id: <20210617093032.103097-2-dja@axtens.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617093032.103097-1-dja@axtens.net> References: <20210617093032.103097-1-dja@axtens.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For annoying architectural reasons, it's very difficult to support inline instrumentation on powerpc64.* Add a Kconfig flag to allow an arch to disable inline. (It's a bit annoying to be 'backwards', but I'm not aware of any way to have an arch force a symbol to be 'n', rather than 'y'.) We also disable stack instrumentation in this case as it does things that are functionally equivalent to inline instrumentation, namely adding code that touches the shadow directly without going through a C helper. * on ppc64 atm, the shadow lives in virtual memory and isn't accessible in real mode. However, before we turn on virtual memory, we parse the device tree to determine which platform and MMU we're running under. That calls generic DT code, which is instrumented. Inline instrumentation in DT would unconditionally attempt to touch the shadow region, which we won't have set up yet, and would crash. We can make outline mode wait for the arch to be ready, but we can't change what the compiler inserts for inline mode. Reviewed-by: Marco Elver Signed-off-by: Daniel Axtens --- lib/Kconfig.kasan | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan index cffc2ebbf185..cb5e02d09e11 100644 --- a/lib/Kconfig.kasan +++ b/lib/Kconfig.kasan @@ -12,6 +12,15 @@ config HAVE_ARCH_KASAN_HW_TAGS config HAVE_ARCH_KASAN_VMALLOC bool +config ARCH_DISABLE_KASAN_INLINE + bool + help + Sometimes an architecture might not be able to support inline + instrumentation but might be able to support outline instrumentation. + This option allows an architecture to prevent inline and stack + instrumentation from being enabled. + + config CC_HAS_KASAN_GENERIC def_bool $(cc-option, -fsanitize=kernel-address) @@ -130,6 +139,7 @@ config KASAN_OUTLINE config KASAN_INLINE bool "Inline instrumentation" + depends on !ARCH_DISABLE_KASAN_INLINE help Compiler directly inserts code checking shadow memory before memory accesses. This is faster than outline (in some workloads @@ -141,6 +151,7 @@ endchoice config KASAN_STACK bool "Enable stack instrumentation (unsafe)" if CC_IS_CLANG && !COMPILE_TEST depends on KASAN_GENERIC || KASAN_SW_TAGS + depends on !ARCH_DISABLE_KASAN_INLINE default y if CC_IS_GCC help The LLVM stack address sanitizer has a know problem that @@ -154,6 +165,9 @@ config KASAN_STACK but clang users can still enable it for builds without CONFIG_COMPILE_TEST. On gcc it is assumed to always be safe to use and enabled by default. + If the architecture disables inline instrumentation, this is + also disabled as it adds inline-style instrumentation that + is run unconditionally. config KASAN_SW_TAGS_IDENTIFY bool "Enable memory corruption identification" -- 2.30.2