Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10635305imu; Thu, 6 Dec 2018 04:28:46 -0800 (PST) X-Google-Smtp-Source: AFSGD/VTRFRmWmbHSaG9Mc692q8KyBhAmxLpZ4QMwSsRbk7EYyKa0b/Oq5U4FjwzoAufAWPSM8WS X-Received: by 2002:a63:4926:: with SMTP id w38mr22981546pga.353.1544099326915; Thu, 06 Dec 2018 04:28:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544099326; cv=none; d=google.com; s=arc-20160816; b=oaEerAkrgfQYHpWEX9dTm3zuMNk9noLQV+elmw3mVYZlW+5J8MdnHob1Nks4q8jqxN 2+NcotglAx+tePxYs7NC7L2MCTHLoPmlIThDPAdMDItzukjNe1PzKBlpXVPKFBc96Vmp pdL9ftaw/cHZk9pQKEei9f8z/qsQ2ULWXC+Mymlnnnu6/GFEa7ccDK1wJEDw+wlQ+Fp5 bkFiVRstG4QrEdCqbxzbVnD1qF+tNpBxN0Ju0rsI3znCIaXHyxQ3D6P8yE3G7cLxV+XU u1HcHEGQtXYZEBZd4MFiyS30NLzbgQCgHgGLjCmYhxVnB2kK6pSfZCtQxSKYP2bXf8F6 pR1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kdXJRxv4fyHhhgwNYAW9KeDDpz520moerszNmxFBOyU=; b=TvQqbjLn7dTmZpNXF2/pWheElVbHo7gCWxCyb+WnRxY3vDoajo7uHTIXchyjNArs89 a6a5G/4lI3sCur9QMKRDgLncRFAhhdGCquVwAWhBTxfArZRDR7/t7aXxv/E3pWG84oHN Rw1L473ZmJBcf5wajuG75QpYxtEcolUHJJjILexWzFQkWL5ONa8Fj4FD0xV2fPWPqd2h rADDRngDJTPL7uObDW6MRyBXzABvbrHyKJeUnh4NX1SaMlWZFDnBa/LeIXFpIK4/XJtF 2sgKuZkFOg8ohX8oX0gV6+Yo7hUDizS8pCGAOvtVFufyqHMuPrm9iGjCyMkmPkBR6/up jQkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tSllCbYh; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b21si201959pfb.89.2018.12.06.04.28.28; Thu, 06 Dec 2018 04:28:46 -0800 (PST) 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; dkim=pass header.i=@google.com header.s=20161025 header.b=tSllCbYh; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729628AbeLFMZC (ORCPT + 99 others); Thu, 6 Dec 2018 07:25:02 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37635 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729571AbeLFMZA (ORCPT ); Thu, 6 Dec 2018 07:25:00 -0500 Received: by mail-wr1-f68.google.com with SMTP id j10so306030wru.4 for ; Thu, 06 Dec 2018 04:24:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kdXJRxv4fyHhhgwNYAW9KeDDpz520moerszNmxFBOyU=; b=tSllCbYhK8CTwm062EuJ9YxzX5azvNPGwSixQNdttv0wG7HbPvJ4HWqvcMlUyhbXFI qfiFNFadH9dyUfmPDcs07QkW+5tVlzIzfHGL34eDJb+aCwpLDI+2Jq5bSjS1DLLPtZSY QFM+Ke7eo58l5DlGpf90kwlk+F8UGcaPSuYzmSUtZxOfKt7BqigtuJmeH3dzl6XZlk3b 783OT0Gs76sD8FegLNM/9btM6Wz3FXl34UjM6CMRJGkzceNPCf13AnIagkuNdqYjAyt7 RRwXrFNgjBuXIhljtYHX/uaiR16N7FvbWMvVcpbfwmpfzQrZi0JChiYAum3bkh0bt5QX zWyQ== 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=kdXJRxv4fyHhhgwNYAW9KeDDpz520moerszNmxFBOyU=; b=kSfEWKTKidSGxUo2FCFP2MKXs27ZlMO7dH3D7CVbziIcgL16XmIiqgGfdYwnhS+ZuM jQBUmOZ5154nsgN+1ngaGwihIuOlLQYE1d3vHn37jTUDV2JO+Kq2cWudRIKXmpUZA08E jReqk2/vhUuBho0ZcrIn4DJDoBX1o/Koy544k6n8gK7iq3EVrJDEKpPghFoznQS0l7uU Vue8B9Y757wRMuVAID14VQFDBdCAOUCYTKV4jXMv4mnUvzwoknfwPHm/ZZTVs3v+vCst ujSqV3Bewmm7j/qd/7DVF3koNehFdOl1b6o9u40uI/dxzavB9R15+WN28ARK4DXU8v9u AD1A== X-Gm-Message-State: AA+aEWYoXZHgSwXj43Z3pEh/EUkc7jsu8c06OvhbB1B1uDsw6CAlXW7c MrjY7Ek1di7CVLdAx+0/8t5uzw== X-Received: by 2002:a5d:6a42:: with SMTP id t2mr27012161wrw.50.1544099097573; Thu, 06 Dec 2018 04:24:57 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:3180:41f8:3010:ff61]) by smtp.gmail.com with ESMTPSA id j8sm339988wrt.40.2018.12.06.04.24.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Dec 2018 04:24:56 -0800 (PST) From: Andrey Konovalov To: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Catalin Marinas , Will Deacon , Christoph Lameter , Andrew Morton , Mark Rutland , Nick Desaulniers , Marc Zyngier , Dave Martin , Ard Biesheuvel , "Eric W . Biederman" , Ingo Molnar , Paul Lawrence , Geert Uytterhoeven , Arnd Bergmann , "Kirill A . Shutemov" , Greg Kroah-Hartman , Kate Stewart , Mike Rapoport , kasan-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sparse@vger.kernel.org, linux-mm@kvack.org, linux-kbuild@vger.kernel.org Cc: Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Jann Horn , Mark Brand , Chintan Pandya , Vishwath Mohan , Andrey Konovalov Subject: [PATCH v13 06/25] kasan, arm64: adjust shadow size for tag-based mode Date: Thu, 6 Dec 2018 13:24:24 +0100 Message-Id: <308b6bd49f756bb5e533be93c6f085ba99b30339.1544099024.git.andreyknvl@google.com> X-Mailer: git-send-email 2.20.0.rc1.387.gf8505762e3-goog In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tag-based KASAN uses 1 shadow byte for 16 bytes of kernel memory, so it requires 1/16th of the kernel virtual address space for the shadow memory. This commit sets KASAN_SHADOW_SCALE_SHIFT to 4 when the tag-based KASAN mode is enabled. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- arch/arm64/Makefile | 11 ++++++++++- arch/arm64/include/asm/memory.h | 7 +++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 6cb9fc7e9382..99e7d08c6083 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -91,10 +91,19 @@ else TEXT_OFFSET := 0x00080000 endif +ifeq ($(CONFIG_KASAN_SW_TAGS), y) +KASAN_SHADOW_SCALE_SHIFT := 4 +else +KASAN_SHADOW_SCALE_SHIFT := 3 +endif + +KBUILD_CFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT) +KBUILD_CPPFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT) +KBUILD_AFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT) + # KASAN_SHADOW_OFFSET = VA_START + (1 << (VA_BITS - KASAN_SHADOW_SCALE_SHIFT)) # - (1 << (64 - KASAN_SHADOW_SCALE_SHIFT)) # in 32-bit arithmetic -KASAN_SHADOW_SCALE_SHIFT := 3 KASAN_SHADOW_OFFSET := $(shell printf "0x%08x00000000\n" $$(( \ (0xffffffff & (-1 << ($(CONFIG_ARM64_VA_BITS) - 32))) \ + (1 << ($(CONFIG_ARM64_VA_BITS) - 32 - $(KASAN_SHADOW_SCALE_SHIFT))) \ diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index b96442960aea..05fbc7ffcd31 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -74,12 +74,11 @@ #define KERNEL_END _end /* - * KASAN requires 1/8th of the kernel virtual address space for the shadow - * region. KASAN can bloat the stack significantly, so double the (minimum) - * stack size when KASAN is in use. + * Generic and tag-based KASAN require 1/8th and 1/16th of the kernel virtual + * address space for the shadow region respectively. They can bloat the stack + * significantly, so double the (minimum) stack size when they are in use. */ #ifdef CONFIG_KASAN -#define KASAN_SHADOW_SCALE_SHIFT 3 #define KASAN_SHADOW_SIZE (UL(1) << (VA_BITS - KASAN_SHADOW_SCALE_SHIFT)) #define KASAN_THREAD_SHIFT 1 #else -- 2.20.0.rc1.387.gf8505762e3-goog