Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp53308imu; Tue, 27 Nov 2018 08:57:42 -0800 (PST) X-Google-Smtp-Source: AJdET5fMhs8P1vbSmAHZgqqbT2LaNne/SXazJi2HQmTy5zhK0Pshg8VRkD3RhK+vsRN38UFKRI9R X-Received: by 2002:a62:25c2:: with SMTP id l185-v6mr34633502pfl.64.1543337862662; Tue, 27 Nov 2018 08:57:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543337862; cv=none; d=google.com; s=arc-20160816; b=x+ZR+sXgwX99okgvLaIXAODp6DsiKNlgRGRyYg+nnEUIG/gkAbnwnbUMCVNRR6kJbE JpyHDdRwzjuuj7FKNBYAq2vxb/XcpSB2DoN2fhSHOTrV5SUAtWaYArE7KFIhdrEbTOck OiWovvWc1m9sf7YJ/5zFQtJsuOhUG1ylQNPf4qilOUt9UOQcd4xl/QAPjBDuHL5Lbwhg 8tMOCIXTgV3Ve4AjSDYtxyt3mOY1xvk5Ec5cAHhEYmz95whUwcrdwNXidv3VcMOwched XH9CWo8KUupEh1gAqqZY1B0x5cHSBv/SBig4m3QSCxGb/+SSmSIYnUIXR1f8qeOaosgK cJkA== 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=xTUWDQtoCoS0aCkqKcHlSfKscpiq6EmalPX21Pfc5fY=; b=nls4m2OEYJrlQSvLVvDINpbVhxGMnrKBTcesMZLKVXVJdusq6h87nVcegcjuXEEd4I yQs7Fp6WuLrTYmCvhtYWmzveUiawG6VPtWtaiis+HK3VI2RqW+MKO+X14JFb3oLNPQGr rolpSNKPQS0MF17qAHK1wkBerm/qsdKZoVAbgsI2KNeLGgzY8qnT0RpVKA2InACeKNO4 7uV+FDWnn3ZKd2BreS5T+9c5o7kfdsbxUlpptSHHBsghRnkfL3+tO62xzwNDJBPlm76/ 1dwUVnC4PRtw9tXSjHtTETcutqMtWAbB1nMLCZ/Z15wZo7m4QpVff/CSifsyBJTjm6No i5jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dwUU3Biv; 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 n5si3776964pgh.422.2018.11.27.08.57.26; Tue, 27 Nov 2018 08:57:42 -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=dwUU3Biv; 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 S1731637AbeK1Dyd (ORCPT + 99 others); Tue, 27 Nov 2018 22:54:33 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:38822 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731585AbeK1Dyc (ORCPT ); Tue, 27 Nov 2018 22:54:32 -0500 Received: by mail-wm1-f67.google.com with SMTP id k198so23064509wmd.3 for ; Tue, 27 Nov 2018 08:56:00 -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=xTUWDQtoCoS0aCkqKcHlSfKscpiq6EmalPX21Pfc5fY=; b=dwUU3BivFrGTU0l5vocuel01QRAE+v2OGhkebJVpy0mfJmO48WW8JjO/aQRDNIxlzp 7Q7mQuPIYO6ENLlB1vL2wNEuEIHZp+ISZDSJKEFWk4t6VwdTO034MsDUqOMVSpnvYHaG EJcyDLbTK9jrS7IEcf09GuU+VgeRwknC0Tlm4O/P5QswfFrC1hiDKmoKuUuLwhOvaaB1 eOqzl7HmKc1Hk+kdVzfJIn3rAmpOXnEkoLkjR1OyF9bg+r+lmbARfTC79ZfPy4UEbmPK TLasPIfGNrBaUGy9nXGM879QdxieJEgd31QTd/Q6LhFdvEscYdJa6SZolCyN4ZLBGe0E +eCQ== 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=xTUWDQtoCoS0aCkqKcHlSfKscpiq6EmalPX21Pfc5fY=; b=JYTw4Wn8P7IKQ4UiekS34Fxfh1kve/z9AeGxesVvjS7t7GScLV1rHRrGfIQFwTMvXk CLaogg4RbWZ9jM2TWab1Ec+uqdrT+UXf9BnnjGSujJ0ur+fYFHG43AUqrXH+4tx7wUuX 4cK47N1NRBqpUxmDfGy+NBWOKJmAbcYlPK3Iw6IthjjwwXhehwYP9T8ku8ri/Ndig1x4 tgArXECN2qTkkzsSBFafi5ytjI5NVN4IpSSaH4PnLY/1ygaKEDTA1oMqiJ9KvuoLNxCv mDgyoo9/5B+10PPSPvu4aivm2Syrjo9KJVhNFXuiKaURIcE85MDtLxwA3UjI2+qSYg+O 4C2g== X-Gm-Message-State: AA+aEWZTPoGEeRZsNlnMbYKX2aO/1rUATcgtw/AkTxtkYoeIMfSHeAkA a+l0WdQnwLgoS/FgBVqqFHEdTw== X-Received: by 2002:a1c:9692:: with SMTP id y140mr12993788wmd.67.1543337759395; Tue, 27 Nov 2018 08:55:59 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:3180:41f8:3010:ff61]) by smtp.gmail.com with ESMTPSA id k73sm6383099wmd.36.2018.11.27.08.55.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 08:55:58 -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 v12 06/25] kasan, arm64: adjust shadow size for tag-based mode Date: Tue, 27 Nov 2018 17:55:24 +0100 Message-Id: <95fa472a03a8ff268e24b8730ebd108922824e74.1543337629.git.andreyknvl@google.com> X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-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.rc0.387.gc7a69e6b6c-goog