From patchwork Mon Nov 19 17:26:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10689029 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 5E58D17FE for ; Mon, 19 Nov 2018 17:27:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 422A32A2B8 for ; Mon, 19 Nov 2018 17:27:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 351AF29C87; Mon, 19 Nov 2018 17:27:22 +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 B776929C87 for ; Mon, 19 Nov 2018 17:27:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404213AbeKTDvo (ORCPT ); Mon, 19 Nov 2018 22:51:44 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:34086 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404249AbeKTDvn (ORCPT ); Mon, 19 Nov 2018 22:51:43 -0500 Received: by mail-wr1-f66.google.com with SMTP id j2so4587265wrw.1 for ; Mon, 19 Nov 2018 09:27:18 -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=h+5rV8i8oHAlZCp9BrjdSXzDHw5vrl+aIvlpSNxpC04=; b=sv45BNyFXG98rVEUXSuOI+lgHZgjUg5xwoOUc83v5acd0OsW6+U+9c6hkGjllywz+Z +mYa8Pp6dMD6Dj3z132SayAzcPiFUezDhHFiQ6b9GZ1+HbO+gPvk7eJdLli6M6Pm7aDp yvTkTWg4GyPVv5+cToj21xhgO7l/fld8I0Po+a35SVrHXei9pZ/00mwpxSiNVxot6cr4 FbpSvNbS+Z8JySxL4rI2xopNeM8Kdax53vP1n8fNMR9QF+k5d/onDhRA6WKqOK7/U9+n FjPjGg+UKfsu7LexwgYtUDMbONwR2COyPbx03Ej7NiqCb4FbRj7Zs9j1nefbnhf2ePV2 qQ6g== 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=h+5rV8i8oHAlZCp9BrjdSXzDHw5vrl+aIvlpSNxpC04=; b=KpLSj5DZ0Cuio61QGh4XA38OTphv2/q6p4XsHa7MebS1ojTfTSJnQTBvxJisyVCPZk t1w6Bdk86uFUz7h/QSeERdii3tiXOcwNw1/T/x9d3qpMjOd1Xx57r94DGYVG2tUttlWc eCOOYCzFktJS3ZGm5sH5pw3tvE+P2ZusFAO5QwFpK9Sbpcm/YV2BAvBZRb0S5o/9JH9a 10xCVPCVh/f705zaQwqwOJrM+rhWbqflxJn49UUuir6yfRGYHs4JKwk3tnbVo53b4pOD /57xoNLJzKx3WlVys9JV+ZB/Lt418NrutXSBrMdRRAC06i1PowTKYBGvqGMMPo/jELWI bBTA== X-Gm-Message-State: AA+aEWby/++PkSsmhrAXQbRixmaosbR3ryr0ihHcgR5UQfSqb8mKINh7 OpWTQkiQXmCkljCsiBxZyn4AFg== X-Google-Smtp-Source: AFSGD/UOnJKpBQZNcwhfKdJD/c2SfY50D4CePkI6Yh7W+ALQWMH0I5DjVzv2hGxFtShtidsjDNfgcg== X-Received: by 2002:adf:891a:: with SMTP id s26mr944808wrs.44.1542648437776; Mon, 19 Nov 2018 09:27:17 -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.27.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Nov 2018 09:27:16 -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 14/24] kasan, arm64: enable top byte ignore for the kernel Date: Mon, 19 Nov 2018 18:26:30 +0100 Message-Id: <7194a50384cb755e389ccecda66942e15b7b76ad.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 the Top Byte Ignore feature of arm64 CPUs to store a pointer tag in the top byte of each pointer. This commit enables the TCR_TBI1 bit, which enables Top Byte Ignore for the kernel, when tag-based KASAN is used. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/pgtable-hwdef.h | 1 + arch/arm64/mm/proc.S | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index 1d7d8da2ef9b..d43b870c39b3 100644 --- a/arch/arm64/include/asm/pgtable-hwdef.h +++ b/arch/arm64/include/asm/pgtable-hwdef.h @@ -291,6 +291,7 @@ #define TCR_A1 (UL(1) << 22) #define TCR_ASID16 (UL(1) << 36) #define TCR_TBI0 (UL(1) << 37) +#define TCR_TBI1 (UL(1) << 38) #define TCR_HA (UL(1) << 39) #define TCR_HD (UL(1) << 40) #define TCR_NFD1 (UL(1) << 54) diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 2c75b0b903ae..d861f208eeb1 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -47,6 +47,12 @@ /* PTWs cacheable, inner/outer WBWA */ #define TCR_CACHE_FLAGS TCR_IRGN_WBWA | TCR_ORGN_WBWA +#ifdef CONFIG_KASAN_SW_TAGS +#define TCR_KASAN_FLAGS TCR_TBI1 +#else +#define TCR_KASAN_FLAGS 0 +#endif + #define MAIR(attr, mt) ((attr) << ((mt) * 8)) /* @@ -445,7 +451,7 @@ ENTRY(__cpu_setup) */ ldr x10, =TCR_TxSZ(VA_BITS) | TCR_CACHE_FLAGS | TCR_SMP_FLAGS | \ TCR_TG_FLAGS | TCR_KASLR_FLAGS | TCR_ASID16 | \ - TCR_TBI0 | TCR_A1 + TCR_TBI0 | TCR_A1 | TCR_KASAN_FLAGS tcr_set_idmap_t0sz x10, x9 /*