From patchwork Thu Aug 9 19:20:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10561801 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AAA3C1057 for ; Thu, 9 Aug 2018 19:22:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A07A2580E for ; Thu, 9 Aug 2018 19:22:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D0502654B; Thu, 9 Aug 2018 19:22:53 +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 3E01C2580E for ; Thu, 9 Aug 2018 19:22:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727508AbeHIVrk (ORCPT ); Thu, 9 Aug 2018 17:47:40 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:35850 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727483AbeHIVrk (ORCPT ); Thu, 9 Aug 2018 17:47:40 -0400 Received: by mail-wr1-f65.google.com with SMTP id h9-v6so6106460wro.3 for ; Thu, 09 Aug 2018 12:21:25 -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 :mime-version:content-transfer-encoding; bh=lFiGSfRezZmnQnY92qgEO5G22hCK6sbxZ9zHPdYvrq4=; b=Nos1UDYofE5iwALIoGSkS0Q+oJZ6uWFtPCiNTKNWA9uq8ORDDXJvnDw5AyUJEdsjel dQOGsHXIkwOloSfAXwZjqYrk8IgXuz81I1YuA0MsaDYiQffMvtVseiOIFglGjFxRkHYa Yw/RfC4EQ6qPnIFsWJ8rOrCIV/S0JcmOve0hgF8hmGdu8H9iQMHV3wTsSvAggJuHXhQZ uVbjF50RnjwGVm5u+W7uX2UN1mNoHUpAT4UXxtWh+aMPeILzRP20CNrrvsA9ZLJmj1y1 PmTVJ5ZQjTK/8qyt99la6l0kSmKDHJ2qgqYwtC5HSfCAD9ksGSESs+Nq25oG6F8sMMFp CgQg== 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=lFiGSfRezZmnQnY92qgEO5G22hCK6sbxZ9zHPdYvrq4=; b=lxI24LmzYyeuzLeNe0obH0nBms4oWnLdQvW+8qQF4AeP9qpvNY0kn3IfWtKHwiqwB/ G/zi0ENLlcsvb2XTFewMJRR0nDrksMgKGkDZ4GCQqPsWVxueR1IuRQXvrTQ3x1A6OqMD tqZzGlNmKxGrs7cuQjYIj++vu0l+vPdkOU3UbAsgJDMJ7ne0oiZsgLgprVDWOlK5r4Jb oYnmzZvI8f1YEIe1615ENkONz49EuDnbyEMV/yGCiB3mj/FiRf694W7f1hnM1mgVef71 M6kDHvF/RpVGqo0/1DeZsK8HIKRKuy3KDODNmNCjs9e1xMmI99xu9vxdnxUwyogPEu2W ojGw== X-Gm-Message-State: AOUpUlFFI/cSUkPYB0am3B852GGu6DIQtg2R9JwY9ks5cs1Awbhr/2Xj cK4LhX4l4wNDAvT10i5UiBXqiQ== X-Google-Smtp-Source: AA+uWPzI7yJOFtEcYKJKQsLAaH/2GfV75jLtgqXee01D7GLmz1Df6TG6DdqoLCgZWUJM/bkd4L7VLQ== X-Received: by 2002:a5d:4007:: with SMTP id n7-v6mr2347871wrp.258.1533842484618; Thu, 09 Aug 2018 12:21:24 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id o14-v6sm14738797wmd.35.2018.08.09.12.21.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 12:21:23 -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 , Vishwath Mohan , Andrey Konovalov Subject: [PATCH v5 06/18] khwasan, arm64: untag virt address in __kimg_to_phys and _virt_addr_is_linear Date: Thu, 9 Aug 2018 21:20:58 +0200 Message-Id: <3e8180bbbc82be79412be86316c5b7ea6470b7dc.1533842385.git.andreyknvl@google.com> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog In-Reply-To: References: MIME-Version: 1.0 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))