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: 10561835 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 1628296FA for ; Thu, 9 Aug 2018 19:26:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 036D22B911 for ; Thu, 9 Aug 2018 19:26:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB3CC2B929; Thu, 9 Aug 2018 19:26:03 +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 99C882B911 for ; Thu, 9 Aug 2018 19:26:03 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=Df2t8pd40c80DA7ptZH0ZKIbrZ2DotlVNrlSo8aIEtI=; b=JGclLEOFwrIyhx KWcIMb8tB1sJrSEsZ+Ks95/ShF/mTIGeVsNVXJixptGiv9VMdFXunKLEFAI9ObtNURBx/gWIlk5IV BhDfI8daI0tvVuxdsISZPdlf4DrWi2RRNHGQqlffCdT5rkY4rjY3ygw1hb+OwX06+GkhQ3CsZgLFy LQHFwqeaaUELY1rCXtYoBAGHqY9OsPGHZAfBVhUU3ePdy/s+gmHdaJRKzsDI7gztq7WkVlru1iWw/ QmbxHsslpTyVGKLKSxQue0jTsEEZslpxKwNOISGMGhYpXgsllEAJmc3NTRO8Mu1tbPfFa9NqZXRgD UJx7MzhAZNMnzaeMiIkA==; 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 1fnqZL-0005bM-At; Thu, 09 Aug 2018 19:25:59 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fnqV6-00006r-LE for linux-arm-kernel@lists.infradead.org; Thu, 09 Aug 2018 19:21:40 +0000 Received: by mail-wr1-x443.google.com with SMTP id b15-v6so6068007wrv.10 for ; Thu, 09 Aug 2018 12:21:26 -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=lj3wGtT9CzyA9T8KZ1mqZb3KMjKcg1P26UZWAUoBuHX9yf9WfwzHiPIb+D4K/QeJgp 0Jk1irkeAdVSQnU8+wkFVo4tGJdLTsirlQLWOGXux8MY0PdxqURC9u6TuxpdQ9xz/PWK mjxgPf5DE9a/ntNr1DHpghrvqEl70KnPgeD+1t8RPmO8vKH+rvd1Do6JwHYKlbe4R1zE S7o2F/WjEDxTIMkKJuuC/UpvmQS0pgiZur3kEjOVcKVsPRIUzgGblErQ3vjv0UzTyvOH gP0/UahDFvPCFj5TWp3cKGOAcr6ebsq7SmayJ/6rJEN0H0/rfyLupe1t4fYULkZeSHnK Qc2g== X-Gm-Message-State: AOUpUlHbq5o6gpUVtMHno8AWxx6JrOytLGiX7a5FCxkrNNjdrSZpIvRk Qa+Pm22ty+BHEw/2g3plADUykg== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180809_122137_040172_8E8326E1 X-CRM114-Status: GOOD ( 13.19 ) 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: Vishwath Mohan , Chintan Pandya , Jacob Bramley , Jann Horn , Ruben Ayrapetyan , Andrey Konovalov , Lee Smith , Kostya Serebryany , Mark Brand , Ramana Radhakrishnan , Evgeniy Stepanov 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))