Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp5124970imm; Tue, 26 Jun 2018 06:21:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdfr2+T+VmmbKhGlCDCyULfhHH+efaVaEgyWh0TKq3Rk1GkRGZ0K1hB/eyXxeQ47IDF6Thz X-Received: by 2002:a62:f948:: with SMTP id g8-v6mr1538338pfm.107.1530019292380; Tue, 26 Jun 2018 06:21:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530019292; cv=none; d=google.com; s=arc-20160816; b=c1LsnOQBql3OWDWVcG76bM8CZ9DZsLLx9nBCSewxzJZygQOzbwXXc7owbbjYpj99h1 cw6pYScloO+q58tl5Jmn9zcHaxXwtkrx34CioLgQFEiK87x6f4veEgnQ2Td44U9E7v5h 60/EXdNuSGDgJXVNCBM2MNyYuYhqWylxCyc9HV05rttImkl21ky2Ttn7+0yDkn7dRUWL Lpv5gxQzN/5/wxQ3aAeqxoq25ut+AIsMR1x/uIYDIGPImDe5VR7UKUoIlLUkb5ysFfet j1uojrC8V6bMIA0YpDsxSv7KAPEXysLgFRuINPDQ8LG9C7GgnK/0t/6WJqdT8cCd7Soh f//A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=lwHXL9yxDliTZ8j2rjrSn8b8qpXunOQohZ4LL0WT38k=; b=0JiEKiOO96J+52gnXb5sQl3tdRHfx2kgsAijgr2pa2Q7fHkVtpScLhfgordmOB+Uwh o7BHKXvlKoL9ioUcM+djfAMA3DfgkaqZEZBYectGewTa5RGWzg2Qkwsp5V/achwTYcpi mZQJyd8EePH1BG211MUZ8ktOylRVoQAQ9mgH0nipRSVxjy3lXVQPBdpMcm8qW+d3+5XN SB+1zzOCOZnfkvZVoVusHm5Av2ZLuMlSoE0CORAznLR+JFaXExPNIj11ZTqXDWSMjSgP rQOi2ebN3XczZOGH98odTZORI64O7PinbsBcOiDuawE1+Nxy4oik/ZylLCSJwxKY5UYv G+fQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Nve+YD/7"; 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 d31-v6si1648223pld.23.2018.06.26.06.21.18; Tue, 26 Jun 2018 06:21:32 -0700 (PDT) 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="Nve+YD/7"; 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 S964996AbeFZNUG (ORCPT + 99 others); Tue, 26 Jun 2018 09:20:06 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:54000 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935436AbeFZNPp (ORCPT ); Tue, 26 Jun 2018 09:15:45 -0400 Received: by mail-wm0-f67.google.com with SMTP id x6-v6so1882397wmc.3 for ; Tue, 26 Jun 2018 06:15:44 -0700 (PDT) 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; bh=lwHXL9yxDliTZ8j2rjrSn8b8qpXunOQohZ4LL0WT38k=; b=Nve+YD/7m5Js0YQS/esJN8P01yI1dAMjGhoRGaAHutX94HfutQ0RgEce4umiFTfdE3 omPIGdAEt+/+V8dRhsA8P2eBW5CfM24mjVK2LS/XGe9LcM1NEYFWucEWedQmNC2ouiIp OAJzl3Y5hmHZg6/OhXBD6a83XawAUnqYkEP2ZLsS9LMoFhyhSLmjQR3lmQtmlVeBqQUK n1GqZ5TgKx4Fv1x5KkTQ/cMCKnPIUZMMDBJgW710qluD3iaJGB7BhhD6f5cXXC40w+ss hUch11syrQUh8gkbm56tC3MoFSkc1B/xIwMc1InX0tmxhor0Y59VrOWsaP587UVx5D/Y Ui6g== 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; bh=lwHXL9yxDliTZ8j2rjrSn8b8qpXunOQohZ4LL0WT38k=; b=gCTqI8pdKs/6qXNy29oYefBuwD69uDNMWtbMPb7TJ+Tviwa5L98Kk37KeFRnpfp7i/ VoLY4Pw1Sic5SuR5dbfWB+Wl3LSaLh49mQq2kQFPqq5inJE9lZBamsaZDcFnxSCJkI8M 2THb9Mq86F55H5dAARikKPgEGrH5n589c48aIoxaaxE6/0rr/tkpagyW8khTLGy1fjWJ 3lP8NzOJmtspt5eS6UlUBoXXAl/iRUm1kZMLZGuJzXKJuAZOqlrRSKXYmSA5uxQpqhDz 3Ziw+nOnQsFFjz1pnwa1EXo0GorlpI+3N7jB8JTGw9hm8ncRd05Bs3EgSVXUU7HJYZcv f25w== X-Gm-Message-State: APt69E3rKs7D+ZjbcigZ6qZNPE8ddPzGz/8F0nJU72nSDvOdHd54Uri5 I24SLu+9BxJzg++1v7jCLFlDiQ== X-Received: by 2002:a1c:6c09:: with SMTP id h9-v6mr1689664wmc.138.1530018943832; Tue, 26 Jun 2018 06:15:43 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id w15-v6sm2162639wrn.25.2018.06.26.06.15.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 06:15:42 -0700 (PDT) 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 , Andrey Konovalov Subject: [PATCH v4 06/17] khwasan, arm64: untag virt address in __kimg_to_phys and _virt_addr_is_linear Date: Tue, 26 Jun 2018 15:15:16 +0200 Message-Id: <643759831c3d951a572a14a374bd50b8d394f821.1530018818.git.andreyknvl@google.com> X-Mailer: git-send-email 2.18.0.rc2.346.g013aa6912e-goog In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org __kimg_to_phys (which is used by virt_to_phys) and _virt_addr_is_linear (which is used by virt_addr_valid) assume that the top byte of the address is 0xff, which isn't always the case with KHWASAN enabled. The solution is to reset the tag in those macros. Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/memory.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index 6d084431b7f7..e9e054dfb1fc 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -92,6 +92,13 @@ #define KASAN_THREAD_SHIFT 0 #endif +#ifdef CONFIG_KASAN_HW +#define KASAN_TAG_SHIFTED(tag) ((unsigned long)(tag) << 56) +#define KASAN_SET_TAG(addr, tag) (((addr) & ~KASAN_TAG_SHIFTED(0xff)) | \ + KASAN_TAG_SHIFTED(tag)) +#define KASAN_RESET_TAG(addr) KASAN_SET_TAG(addr, 0xff) +#endif + #define MIN_THREAD_SHIFT (14 + KASAN_THREAD_SHIFT) /* @@ -225,7 +232,12 @@ static inline unsigned long kaslr_offset(void) #define __is_lm_address(addr) (!!((addr) & BIT(VA_BITS - 1))) #define __lm_to_phys(addr) (((addr) & ~PAGE_OFFSET) + PHYS_OFFSET) + +#ifdef CONFIG_KASAN_HW +#define __kimg_to_phys(addr) (KASAN_RESET_TAG(addr) - kimage_voffset) +#else #define __kimg_to_phys(addr) ((addr) - kimage_voffset) +#endif #define __virt_to_phys_nodebug(x) ({ \ phys_addr_t __x = (phys_addr_t)(x); \ @@ -301,7 +313,13 @@ static inline void *phys_to_virt(phys_addr_t x) #endif #endif +#ifdef CONFIG_KASAN_HW +#define _virt_addr_is_linear(kaddr) (KASAN_RESET_TAG((u64)(kaddr)) >= \ + PAGE_OFFSET) +#else #define _virt_addr_is_linear(kaddr) (((u64)(kaddr)) >= PAGE_OFFSET) +#endif + #define virt_addr_valid(kaddr) (_virt_addr_is_linear(kaddr) && \ _virt_addr_valid(kaddr)) -- 2.18.0.rc2.346.g013aa6912e-goog