From patchwork Wed Aug 29 11:35:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10580019 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 6D2ED17DE for ; Wed, 29 Aug 2018 11:37:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C5202AA9C for ; Wed, 29 Aug 2018 11:37:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FAD82AB91; Wed, 29 Aug 2018 11:37:02 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 07D0B2AA9C for ; Wed, 29 Aug 2018 11:37:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728494AbeH2PcI (ORCPT ); Wed, 29 Aug 2018 11:32:08 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:55494 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728503AbeH2PcH (ORCPT ); Wed, 29 Aug 2018 11:32:07 -0400 Received: by mail-wm0-f68.google.com with SMTP id f21-v6so4935359wmc.5 for ; Wed, 29 Aug 2018 04:35:38 -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=ScyVG8/8R+wHPT40gRo57Kpvm4BCgl84gWeZYScmJuw=; b=wTs5ODdO4PrsRaq9SSLTEZ7b10s0WzDZC6bvpJQCQ8IlNuv8Tm13ZusPLCWI9u5B6h dnuPVb6nNahHsbJlKRNbyTLXNJ/IrGoLuhN0DBBkhShgRKNswPDo36xTMxq9+X8I7ByY Z81NYIk6kveEH6yEiQK5WwgIHPjxiGp1gTsfDHqRN4/FjAOY4vYjr/1t6prtIAlo4x8y C9VP5vf6Ywf4tNQ72tAz0ab4zeeMok9lxjqUAxNz9ZlYoT8Dwgd0SsM6S5SRkdvlI+fi kBtB/ZVfI13XLo2seU5UAo9VpCDwoSqBWnOlSmXFjGovS8hYAI20T+2ppjFYW1flvuWs kqxQ== 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=ScyVG8/8R+wHPT40gRo57Kpvm4BCgl84gWeZYScmJuw=; b=fsbUle4c6L93p470pAHIRCtVgkpQbvHUtCIQ3eohNC5QC0A5uR7rClgAj93CNOZTLS xFDZRX8fKpyaM0E4rZJjc67tgovchbccAwNRFx9O7g6c1iua6DeQJKNuzEj9q2iPEW4G RvMqg4lyIH5nRGSmEDhjHfa3dGtFOKxBchfBy8/vb714RTcZn+75CELqLEh1VNR2c6C8 j62+vsFb1a6zY3pnxfWKJK3cVvWhbzTXTWIbIgeEmVhlgWnsJbdNf7iDRUAqu3nCO4wV 6PZgaqX44nSUMIpmq/rr//QJBzWrsRbwvwvgQov8/xL2uNND7BOn2DYrzBFJXzQZSaA4 5ewQ== X-Gm-Message-State: APzg51DMAaVXpC0v22Dz5Jiwr2DFRPmpkRlklw0JNVgGNhYj3sW5LwUx fB2q5yjKD+NAJ8kVEba6BaAkGQ== X-Google-Smtp-Source: ANB0VdZKr6B7zINhz15rEPoFBPLoEFhgTfNWmBJ1/WdmOFNn442wB60NAMI8yonkTKESWF427Y1E1A== X-Received: by 2002:a1c:1182:: with SMTP id 124-v6mr4036911wmr.75.1535542537152; Wed, 29 Aug 2018 04:35:37 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id s10-v6sm7800454wmd.22.2018.08.29.04.35.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Aug 2018 04:35:36 -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 v6 06/18] khwasan, arm64: untag virt address in __kimg_to_phys and _virt_addr_is_linear Date: Wed, 29 Aug 2018 13:35:10 +0200 Message-Id: <19d757c2cafc277f0143a8ac34e179061f3487f5.1535462971.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.0.rc0.228.g281dcd1b4d0-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 f5e262ee76c1..f5e2953b7009 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) /* @@ -232,7 +239,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); \ @@ -308,7 +320,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))