From patchwork Tue Jun 26 13:15:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10489007 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9F07560532 for ; Tue, 26 Jun 2018 13:20:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2DE48289EE for ; Tue, 26 Jun 2018 13:20:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27A92289CB; Tue, 26 Jun 2018 13:20:24 +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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 24CB6289B4 for ; Tue, 26 Jun 2018 13:20:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935299AbeFZNUF (ORCPT ); Tue, 26 Jun 2018 09:20:05 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:34360 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935435AbeFZNPp (ORCPT ); Tue, 26 Jun 2018 09:15:45 -0400 Received: by mail-wm0-f67.google.com with SMTP id l15-v6so15266392wmc.1 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=nI1FHHn07WB6+m8iDupWXEZuIIMNceyADDdnyH2yT1lsEFRC63PbVmGR/54NltPttr +qDoN8/Z5kqCD//FBh/20ZlnTiTKvtNz55oKwsp4hB6fP7OiCJa+XhR4pWsdm/yTghXO yHYNE+R9LnL0G9aznoe50SR2J0BLYPANY66ax2wD3nBS2XEjCXstMlibneymRP+lN3Mo nnAWH6gTb9xNyNdY0aI4RoEbTbEuYhtXK0+aILofahweFnFfB7K9/BWKmN3AihWjFsqw hrLG35nmbgIIYrJKARb17M7Fl/n4t0VBhqmzbytTQlZ2XLSZd/KlXsDSsTWNTQQch8OZ 3bkA== X-Gm-Message-State: APt69E0TKCTl/DZ1dk9fuX68DorqKJxmFGyfCepkLaqocg6W+n+OgjEa ozu07XE6iLCLanE+YgrPS7oyuA== X-Google-Smtp-Source: AAOMgpc3ljCQJRHXmxShHNHjl+H2ddHM0ibRaOTiGaw7lWPk/LXHQOWxlEdaNCrvLh4lWWyfMD6HVg== 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-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP __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))