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: 10478387 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 6595160383 for ; Wed, 20 Jun 2018 17:46:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5023F28E08 for ; Wed, 20 Jun 2018 17:46:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40B9628DFB; Wed, 20 Jun 2018 17:46:57 +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 EB7B528DFB for ; Wed, 20 Jun 2018 17:46:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754612AbeFTRq4 (ORCPT ); Wed, 20 Jun 2018 13:46:56 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:39043 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754609AbeFTRkS (ORCPT ); Wed, 20 Jun 2018 13:40:18 -0400 Received: by mail-wm0-f66.google.com with SMTP id p11-v6so971848wmc.4 for ; Wed, 20 Jun 2018 10:40:17 -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=dPTNtDJaKMdyyY7QhrWzpBNWKcSiGxFkfp4vUPhRjEFgVP0Kt7SDQbPypPMYU0Eqtw I0pDKKAO8RENW+J77EQZlcCwdWQ17O1QZAnb2NKcCZBYZAN23TRqKySVv1SvGp4Zj2Bq cWFDWPxjJl0E1tdYSjmiqLKsXupTQ/eUZDD4nT6csV3BoTx/57fu4DjcrfkmUmnimXva WcFDHXpybzLRDezT227XODtG4hXDUWDIkLVgZNfwJI3vxam81yLPtNI+qpTA6tfbrDPy nNO7lH3XdKENmYsdhsdyv/oyD/xJGA2GjSRTtdUFo44gfYUAfP2qVG3IG5u0edRZI4BQ qCEA== X-Gm-Message-State: APt69E17vkHoJDilnOM263ESTuhuo0M9y2l9+gTvp4fdDh9dXZVzfGTt e9S/V5AdtwgUCpqZtZEyzKKPIA== 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 Cc: Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Jann Horn , Mark Brand , Chintan Pandya , Andrey Konovalov 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: 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))