From patchwork Mon Nov 19 17:26:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10689007 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 5DF0B14E2 for ; Mon, 19 Nov 2018 17:27:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 412A72A2B8 for ; Mon, 19 Nov 2018 17:27:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3169429C87; Mon, 19 Nov 2018 17:27:05 +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 B062B29C87 for ; Mon, 19 Nov 2018 17:27:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404591AbeKTDv1 (ORCPT ); Mon, 19 Nov 2018 22:51:27 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:34598 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404312AbeKTDv1 (ORCPT ); Mon, 19 Nov 2018 22:51:27 -0500 Received: by mail-wm1-f68.google.com with SMTP id f1-v6so6549789wmg.1 for ; Mon, 19 Nov 2018 09:27:02 -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=dR8lcfOg/asfdxo/WfCVQzFad9LYpScILBiq6D3Qbc8=; b=b3lKnIQw33I69347c6fVByjZWZr7rDfZ6pO/Th+7IH/z4NfXLoPk6gkZ6U+EuX8ViZ YvJr7csFPYS3irKKPwFBlIUVwi664iOL1+0Zl2X2madbWgValetXf8gjws1+oU9Tu1ye OEwGw5UlVlxIv/bPEHYGYnySoUH32sHcN6B14z0CVpKxTCSstFOwYILAL0z/aC1+bVaI 7qjaP5iEylpKToNC3dh4SGcPFIAaCiniXcIq9QFyoplJCiGTFhrdjEKkYbqYwX2beBSj Q+4Eaq6aFNUnLw4H9+FNi6Msuzomb85hS5dxEpUktBeo4ZKCl8DjGrDQOJc1a87JAIXi 16vQ== 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=dR8lcfOg/asfdxo/WfCVQzFad9LYpScILBiq6D3Qbc8=; b=SRsOY34PffRy4c7A0Z2JXhBgQ+iEXrk5LJM/xj1UtxeLZOXDjsAWeiktl9v+bsbmVk 9Kk3ta/yrDJbZ+HnyRYjrENa9AI9h8jda2Z23HLXdlRxViSEGAy0pojUrzDNetwgcqD+ JANidmf3y4u/3D+DLtDcA6r/UKO7XYAVZfuj85d+Am0Ld2jG42zn5KP4ARd4iW20u6Ke kn/TGDrk3/xVvzN6pyv0nS6b6K1oF2G0kKnn7MQhonKyWnNh+ILelnLZTo6yeGsUdOXo 4SA1ub6arcQTUcpwLTzHs6p08gQyY2nQJQNeB1fRKvYZD8YlroCrjZ92O5i4/QwSJED0 s6sw== X-Gm-Message-State: AGRZ1gLjtySL1I8jR3izFO5L+E/JJZB0kIrBO20xPagEK91CM/NRyfwt QTnp3t+yI6FCFGliv7rbDocSqg== X-Google-Smtp-Source: AFSGD/WNR8o/WnEF0/GAJSPJLxjNxD3wmkq6whPNnsgmqmNKBmrpQx9bRReY6c/V+wChGBijG3HyMw== X-Received: by 2002:a1c:f916:: with SMTP id x22mr5632080wmh.87.1542648421670; Mon, 19 Nov 2018 09:27:01 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:3180:41f8:3010:ff61]) by smtp.gmail.com with ESMTPSA id l143-v6sm23685190wmb.23.2018.11.19.09.26.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Nov 2018 09:27:00 -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 v11 06/24] kasan, arm64: adjust shadow size for tag-based mode Date: Mon, 19 Nov 2018 18:26:22 +0100 Message-Id: <8122d5bedc46bb3655d576c922db3d722a231bf0.1542648335.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.1.1215.g8438c0b245-goog In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@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 | 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