From patchwork Wed Jun 20 17:39:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10478397 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 C576860383 for ; Wed, 20 Jun 2018 17:47:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0E0628DFB for ; Wed, 20 Jun 2018 17:47:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4BD728E15; Wed, 20 Jun 2018 17:47: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=-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 4113028DFB for ; Wed, 20 Jun 2018 17:47:22 +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=uymBuGzdwyTkm7pDxm9Tm+LMad+aDc2G5mXT/kyd3Qg=; b=MjZhu8GWZGbBz0w9O2OYKNeFSm ak+ozBSG5EGsQDJaE1dn3zjm0anLZFauWYWeO/IO6JFSV2VBDPm5gHpJN0nETxf5GnxuBZetWzbT0 /psuKXueKTWMbIlT0gazYdxeOEd0TDHBQZ9JCTmGnT/zJ4CTF4OwDqOkhA9EikxthQTxE5mbUt1zn tqtB+M/IM9+6SotNjostE2F/52mimUXiPUb/MT2LiMsz3z/m0dwh606p36y+wPYpjWZ/Zgrm2uBz4 MgSHsC51kd+mla1KWpEw9BObzHbsM8vCDoiPlT09Y2qLyy2Pbu015/7tMaZrd5ENf+cOGD3VoVioh E1FwkNHQ==; 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 1fVhCQ-0006ui-4H; Wed, 20 Jun 2018 17:47:18 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fVh5j-0001b6-RC for linux-arm-kernel@lists.infradead.org; Wed, 20 Jun 2018 17:40:40 +0000 Received: by mail-wm0-x241.google.com with SMTP id p11-v6so971849wmc.4 for ; Wed, 20 Jun 2018 10:40:18 -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=3JRyQhTdC+u2oogyIrlq2ZoH/8cj6t0szX7aMWVFrqI=; b=ul87aooq1BZG/ua2mVfhzy4uN/qXMn1UhnfPhLPsnejOFWAGkdptsDs3M1oTmI1nAl C21Guh3/JlIPOD09uCLOi/BPVDdoVIByJeGnb5+0zYUBeO6K0u2ykMy0COZIgmOz1RLu Zxb22xpZgwMuVJmAHzA/tiOzc8lJ9vj2KFxeTCFLKLfgUpo+M+Tm1wglu7mRA2K0TqbF hvnFePrjRgmAQEcYRrMUgCtAycpp9xYn8sBFpPHZv1KPp5HCnPdX3LCPU/yxR8qpU4IX TouAVK6EgxY9z8IBnh4SoOd7uxcao0fDK+ctG8NFDPZ/DgOTBe6PYuJ0kohJsQdfPC9g TxrA== 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=3JRyQhTdC+u2oogyIrlq2ZoH/8cj6t0szX7aMWVFrqI=; b=JZy2aStUhNGGe3QsfBZ3FdWZrGqQmrXWN2fqxzce6J9pDdVVkwWoIpcMQR3odD8VZ7 QumtnuzNI4BvyRGYQNAPSr40YUK/hWB2Bi+NSTVycpKPJZVm97oQn4GOO4LGLkBy5EJF gYugqoPWp5ZwZGmtPlqC9rTEsHFA7clI2eLV73vnsK2VfJuSk2uQ9qliOfgnB3noUwYE ymNWQy31zwvElHn0KGqiGOZLgK4Y95h251Gl40hDzRBGQg884YmX/Dz7KBJZzXwqnSW6 2orqYreqp7c37VmSQugDwHtSx4S5waGodvkjffqJ14OHAn4yZq/mg1Xcpurr7eUXZYhL cLwA== X-Gm-Message-State: APt69E1zbcviGzBUonEZtn6iVMvasNcYWzvpHI3urgPl3KpshWUfQUOM 2MigmxaRkEBqeTmIBrWOhqz/uQ== X-Google-Smtp-Source: ADUXVKIVlEK10pHjqrgIg6B9IiEh/Scv3BRLQ1sYbPsfzIp6woFogpBtw12wTtllSZMEyn06q6NkAA== X-Received: by 2002:a1c:4787:: with SMTP id m7-v6mr2601468wmi.92.1529516416725; Wed, 20 Jun 2018 10:40:16 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id f18-v6sm4388598wro.1.2018.06.20.10.40.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jun 2018 10:40:15 -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 v3 06/17] khwasan, arm64: untag virt address in __kimg_to_phys and _virt_addr_is_linear Date: Wed, 20 Jun 2018 19:39:52 +0200 Message-Id: <44b51b47d2d0517332f37c39cb7ea0016dcf032e.1529515183.git.andreyknvl@google.com> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180620_104023_917942_989C5CB1 X-CRM114-Status: GOOD ( 13.49 ) 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))