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: 10488941 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 4312D604D3 for ; Tue, 26 Jun 2018 13:16:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2DCB428909 for ; Tue, 26 Jun 2018 13:16:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1EB932893E; Tue, 26 Jun 2018 13:16:43 +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=-2.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B9A402893B for ; Tue, 26 Jun 2018 13:16:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=J58Jk4sowpqGdC0Z0oUfBabhofSNEtYa3GNr+eeYSh0=; b=lEM7BullSjXCw8oM+znLvBho3R iyDH4BmkCrrE+QJWOn/lKRCIuWYog4LYJ50gRvm5lQoYjtUQHa4tzwcDQ21SWsiedU8Z7oVCVE9/r zQjYi8FXeusTc8eAjV99i88QxCDBDg+q0Y0tbeq0YKWvY7MiZoSX1troPwFOPviWG8PzwL+6jROvb fMr1shVNOYWHpPL4500e7Giq6iYTWNLODfhX94M0pcZWJe/OsFzpkmlFinoZr1CYUDvjWVabkIRBy 6xTi/qiW/7ZfrnquvUdnDAEJHfcErJ+4Ig8ftqIF853tPkPNqmQfcGT7Hu5nj5RmmcBzkYda4OUn4 xQJftcxw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fXnpf-0007dJ-Hw; Tue, 26 Jun 2018 13:16:31 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fXnow-0007An-OC for linux-arm-kernel@lists.infradead.org; Tue, 26 Jun 2018 13:15:48 +0000 Received: by mail-wm0-x242.google.com with SMTP id p126-v6so1906434wmb.2 for ; Tue, 26 Jun 2018 06:15:45 -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=OBXJxc4axoOpAacYKjuqKc7py/EzRXtCv6DnEpUznsOStrUtN1/E1QhNFE2vji43NV J5RA0FataepCoa9tTGxtC6qPB8eT+mn1kkjtmSCtVq8rkMTeZQNSUmcKRv8hvaU4VYlT Klgs43by1tUIQMoh+u43iGILm5p/sgSeRNakGWN4PCq2bPEmV+SgqN0NpvNAsDM56H29 x0LfPFx+HacDG+1F08ipw3BKOybujmJerNjtOZW8OxS0pW1fPW1c+VGC2szuEdYHfVcb kVD2Y5GvUjCquyqYFlpSJolvyo8n4mnOt2Has2LXsEC7DhkOzi36TUpmVVWfk++7/eYC 4TLw== X-Gm-Message-State: APt69E1OrNa3aJM5SN9NoZ8GgN/vC4c8BPc2orFV8rIA+obtpw1fqThg lkvJ+qsrB0TlE/ADmcVjlDLHiA== 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 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: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180626_061546_826129_E3B89C56 X-CRM114-Status: GOOD ( 12.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Chintan Pandya , Jacob Bramley , Jann Horn , Ruben Ayrapetyan , Andrey Konovalov , Lee Smith , Kostya Serebryany , Mark Brand , Ramana Radhakrishnan , Evgeniy Stepanov MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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))