From patchwork Tue Nov 6 17:30:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10670911 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 327991923 for ; Tue, 6 Nov 2018 17:30:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1ACD82AB13 for ; Tue, 6 Nov 2018 17:30:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 164AD2ABAD; Tue, 6 Nov 2018 17:30:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E90442ABC5 for ; Tue, 6 Nov 2018 17:30:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389668AbeKGC5J (ORCPT ); Tue, 6 Nov 2018 21:57:09 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:39566 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389692AbeKGC5I (ORCPT ); Tue, 6 Nov 2018 21:57:08 -0500 Received: by mail-wr1-f67.google.com with SMTP id r10-v6so14465270wrv.6 for ; Tue, 06 Nov 2018 09:30:52 -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=zR59Oh4f3YmUUjWQVuUWbISM47BcdXN0TxZaGQsGruw=; b=KYgRkNeECJs3IElsm0p/zMKWz/tzGt+6DJSzEuOn81O+jW9wjUl7WlsyE44DwW2UBJ IGjSnu8L6/Px81VwxB66DoNIWe9Fv13N1ZxhAB1MOHFuxbZpt5gBXpIC08ZcsnoU//06 p6ZwWNCogZ6ijzbJ2QLRUniM6z71avQSO6O3Dpg2UYO2qU8fsC6elqb+ah3SvDv1lQ0v D9t2T4M5r4m1nXUM/NX8cheOTr7DtYbhC9LBM/lc/47TWAtYevFH5WcZYmfAbmPPZwG6 CHwa7OZJXdLdFCnVq1AdWznvOE+WGHUxDfCZ5LT1J7r+8k29rGlpDeXzjJ8OYkGlKfR9 I2CA== 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=zR59Oh4f3YmUUjWQVuUWbISM47BcdXN0TxZaGQsGruw=; b=MP/DpwWmlftuzY7U/9KWKQIlnPNT0vSaI6I/888EFQWid2CvqHXkXm6ZczffbH0auH OYVceWhlRQQza/EiptIAnM7YX4f5Lo/C7+f9LU0RLSBr2DcPZcRvxSWufnxRZAM/+rbz oD+u3++CglKwD/jf2CGO6ExZhnjyNo73bJnXqFdgj+XBTUhA8oSLjZeJPcvLiAdY/cL3 xEQtFCMNVsEk1tZ9C34+vWUjmUfSPRJ4S/HqNwThpi3WG7X6oAqUvNQJfOnQUqzLEXtL 4Qc1SIppLRI6CG6SEN3P2pPaFum199mMmjuSg8zNx49KqRhGx2G5Zwto0ZU/IJ8QuAmT fUUA== X-Gm-Message-State: AGRZ1gJJw0KL1eX+hRKN9AEEhSlUf62Gxvz4ict9uTeysY/EsRBw0ZvF qDXUJl2fiIAl+cNW0RHFhtU6/w== X-Google-Smtp-Source: AJdET5eezPyu5zivf/GdDpGQTMhCVkl0xj8xUSgzntxDQd3ItQFM5kt+5hhSTXC4DgW6e/T6ozoIbw== X-Received: by 2002:adf:9589:: with SMTP id p9-v6mr24794256wrp.270.1541525451174; Tue, 06 Nov 2018 09:30:51 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id z17-v6sm16328416wrm.65.2018.11.06.09.30.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 09:30:50 -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 v10 06/22] kasan, arm64: adjust shadow size for tag-based mode Date: Tue, 6 Nov 2018 18:30:21 +0100 Message-Id: <86d1b17c755d8bfd6e44e6869a16f4a409e7bd06.1541525354.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: References: MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 2 +- arch/arm64/include/asm/memory.h | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 6cb9fc7e9382..9887492381d9 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -94,7 +94,7 @@ endif # 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_SCALE_SHIFT := $(if $(CONFIG_KASAN_SW_TAGS), 4, 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..0f1e024a951f 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -74,12 +74,17 @@ #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 +#ifdef CONFIG_KASAN_GENERIC #define KASAN_SHADOW_SCALE_SHIFT 3 +#endif +#ifdef CONFIG_KASAN_SW_TAGS +#define KASAN_SHADOW_SCALE_SHIFT 4 +#endif +#ifdef CONFIG_KASAN #define KASAN_SHADOW_SIZE (UL(1) << (VA_BITS - KASAN_SHADOW_SCALE_SHIFT)) #define KASAN_THREAD_SHIFT 1 #else