Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp56140imu; Tue, 27 Nov 2018 08:59:20 -0800 (PST) X-Google-Smtp-Source: AJdET5cYzQT5z2BViPVi28LMwJ7P6hVsuhIhYoeMPWxP2v6xiu778UF+3QMxcmpL/qVpbQpJVx7P X-Received: by 2002:a62:14d1:: with SMTP id 200mr33980561pfu.103.1543337960751; Tue, 27 Nov 2018 08:59:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543337960; cv=none; d=google.com; s=arc-20160816; b=UPQmzURMFRG15PUpji0ImOfUnk8L12lhrbtm9oVdcDu66BWy5nqZXsEFaoGqs2p8pv oTXc2GVROwSpNCnIvAxtNNpmPLnJaZWclai5mMD2fcCVo0epVopfuOAZ+FsPg6Jf12Nq m+kcDTlT/jCpC/GLDIGe56kkGmoDih5OsQZxJamlhKawqFYnZfin/6gzmZ/dlkZAxN3o FZBIB2QSPqWONqWv7Uy26wVl55SDrbAwttvpMh1FF3x37vYAd9Z9iiKdlbnB+X9TmteB 024RjTseajrP8z7BG1WeAr8xUavl+v1sh930C5HXlzh2iFGCnMvrkYbq90JPzdrerEQ5 n11A== 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=5TjQJgkFl+PVCxLsWj9vCgbjvK0haYDKUt+yI6asfBc=; b=t8gD+ISsIOII44aE0zteoQxHd+jgH+IRxPdDPvo4V7a2r45ifL0XlQ1oOJX+mklpXu 7zpJNLNShpjO0hNMPHktBF1HTliojJjKif6908sh4OqCJDt9MDqYtiZX7GNrCohE7lSv jSbbHth/1qcGK5Ayzj2g6kqfznRYF1uH5S0ZL4WdCJQF4XD4p54Mm4NWt5uGHzlqFAm1 mzbmKtBwRwDlt6Mp9d3QGfSkUyR1feE7ppmrhCehsq8MJQNZW63L0ZmzCYYjg9seGe3s 8LsmiIKtvXqgjXJWQ5mJXjz0wDFJA6fw8a6EqkgEdeDweEhD/2OFFwhXAm9qZdHBizJl AzZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Vq8xJz4L; 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 w23si4313968plq.198.2018.11.27.08.59.05; Tue, 27 Nov 2018 08:59:20 -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=Vq8xJz4L; 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 S1731732AbeK1Dys (ORCPT + 99 others); Tue, 27 Nov 2018 22:54:48 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:43436 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731716AbeK1Dyr (ORCPT ); Tue, 27 Nov 2018 22:54:47 -0500 Received: by mail-wr1-f66.google.com with SMTP id r10so23423829wrs.10 for ; Tue, 27 Nov 2018 08:56:15 -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=5TjQJgkFl+PVCxLsWj9vCgbjvK0haYDKUt+yI6asfBc=; b=Vq8xJz4L04oXAVPDvOzYuzz+wHl1QGBnQgoEk8zjm/CZt1EqPmCV4MXLs83CCDHriG nZQo2iAfvSYq4/G3CcCYjx4+keudcdowz/V+f1xuztB78kVIxdEUZPxUlxAPXdNGfB8r xuY642dJ4/Jr9SFclo8bI/fnE/NGVNXmJm4HZJ33i2h7k3awNqoEHgHv2j3ghoHSetBq N8DthHjipq15+ycjHXS4dovDb+hu7nsTOkP31YrSMZgr2yUOtGuEakHyfOu0gQJ0gQKp +mRR4yL+iYIE+weqA0Qvd988IjrsHCP9yGsIKBnEAOfNH/W7HPJ8EjTjXk2hbR05NzUV UPEQ== 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=5TjQJgkFl+PVCxLsWj9vCgbjvK0haYDKUt+yI6asfBc=; b=NybqzvlWOZnACvz9Q7V/C9tHZoihaI0A/0lOVjjsRbp3Obkj6FREN47EV/ZsLFyAMC XpsnlwqoIAvSdd8z+3MVC7Pi8XEILapZd22WjWkTpmYooHVaIrP+t+xYgtLkVzCUbKxp WU1L3dqdQu5sWgDDphQvo8icBRr3F2OVwSGpE5S1+mcWxHe6lnGtRmKDlJ/XF5Gd299m tY0a/1tolwqFKxdsIpQYNhWvQ+ysJk4Ux5oJuWE8yK0GZDhllVZPIVkXzlDiU0rR49Vw scphHhqNOXs7EXEh3TJrgSyWvUUalAuNoy/+yyMZN7mhln1W4p0U2JFnz3BuiIVfq4eg G+Sg== X-Gm-Message-State: AA+aEWb52/D+DxLB4l0YkT1k6DYs6I61KTAZmWmMfV4h4VyOeQ9QS2ZP viPZadEqA1Psu52/B60DZS6nrQ== X-Received: by 2002:adf:c711:: with SMTP id k17mr15658939wrg.197.1543337774345; Tue, 27 Nov 2018 08:56:14 -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.56.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 08:56:13 -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 14/25] kasan, arm64: enable top byte ignore for the kernel Date: Tue, 27 Nov 2018 17:55:32 +0100 Message-Id: <1ed03d53ee679cba52ba7118d2acbef948d21fcc.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 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 /* -- 2.20.0.rc0.387.gc7a69e6b6c-goog