From patchwork Tue May 8 17:20: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: 10386617 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 3BC7F60353 for ; Tue, 8 May 2018 17:21:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27DB6290B3 for ; Tue, 8 May 2018 17:21:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18E09290B9; Tue, 8 May 2018 17:21:36 +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=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90E53290B3 for ; Tue, 8 May 2018 17:21:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2EC316B02C6; Tue, 8 May 2018 13:21:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2C3BD6B02C7; Tue, 8 May 2018 13:21:25 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13CA96B02C8; Tue, 8 May 2018 13:21:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm0-f69.google.com (mail-wm0-f69.google.com [74.125.82.69]) by kanga.kvack.org (Postfix) with ESMTP id A62D66B02C6 for ; Tue, 8 May 2018 13:21:24 -0400 (EDT) Received: by mail-wm0-f69.google.com with SMTP id e26-v6so4287196wmh.7 for ; Tue, 08 May 2018 10:21:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:in-reply-to:references; bh=QmNrLV2ouq37rJeTa4aJrb/A4HzlLl64fsXLaFH/79U=; b=aATJ+DQd09VKuc755+wF05+nEeJvEURXLnb0g03/OShGUV//3aCsSdMiszTj0MJV6w E4Yqpze4XnLVPnLXJsdFLpHRxxg4ilke+bv0N2b7IWotfhH1TW0YifeZ9WVPPrglCNRM 1Ot0frAdOo++YUJ5AFRCsuGSwXRJk9cyqexA8yuz6PvuOUL0FRHB1C51u+B+bOFezwOi w5mX1bKVkskzeH070eyNeznHoPNbEwD7ygZpX1TsEc7fZeH3d6Tj4/82O0qDnmoDEUgQ Yam7JVLONeTadUAdMtBgh6+2IHMEs72STBJ3F9VO3GTR5OWkyuH0jQhPIPuTPHtQ9675 0hVw== X-Gm-Message-State: ALQs6tCYorjpk2F9DmWwJvFeCd/DyeRo1Nfkps6tH5C909KGkoTkhBuQ dl3EdHgIQEU/+i/qT1P/kT46d/y4CEeL+iU3OmUx3TRloO/myTbU3/Dm26XwwuoWLdCx8ZAzsFr cLI9EySnWdznC5mrGlgvk1629kVf1pnSJGN44MDeV7rL0qAMPxl4UN+17JkfZcb7lPGsxMAb6kY 1GLAR8Ea4yNIfKaY2iYkEnzA+S+ca5IN6XnvUMBhNsPDJFI8AhgH/2+/GO2b//F/p6zhPcyrn/s vucO334hLB2pPmdvvRxFQRvPAL8gOIhwtBxRpcM7LksvcKcVzvtLusHejcuGmcpXwG2ECXimIeQ JaDyh/oFL/E6Kqu4dz485FEqfQP2eX937zr2MdjHaTcO14994KTdiyXZmLCXcLxP0qTI/nats1I / X-Received: by 2002:adf:9658:: with SMTP id c24-v6mr31010067wra.190.1525800084257; Tue, 08 May 2018 10:21:24 -0700 (PDT) X-Received: by 2002:adf:9658:: with SMTP id c24-v6mr31010017wra.190.1525800083523; Tue, 08 May 2018 10:21:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525800083; cv=none; d=google.com; s=arc-20160816; b=FbCpSTznz9gIDkeAtByYqTdl3lv4PDvTlIwsdf7QIHXCNHuFZiJrX0Jrmzm2tKxc7n 5A/2jiQIPSlbU9LIi8qVfjbaoU+dC9kttSuhQFPXiz4vnoBIyAww10CypZ+dFLGHBizE Cgwbc28cohDAX3fHPVuOj86te2wHOj1+rpw0IHEJfWhLm2aMxUJezhQVwI9bABAp3WRv BM8CcqNaZpNsblJYabBO8LNm8TgcOnF9U2Q7vTm9QKsONw7LMzc9SMwjXb4t4JcLxX42 vyrELu+Uz7nZbhvRCSL+yDcm69xqonhd9+xC3BhtCtUme20imHldxsFoNg2h9zh9PN0h 6wEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=QmNrLV2ouq37rJeTa4aJrb/A4HzlLl64fsXLaFH/79U=; b=Oz634Y7hKfSUebwAlv9nJQX3+5hJA9P72HzXJVnvDzvrVzPAMDN/FbyZCQLb2CqXbl fRAaTlN3dCc48Q/ZtQQHDqCo9ZmE2LWATjliLTJ0igg7wHFEFnYQ7dSLRguwiG54IqqY 1wd9ZnSN8Tn8yReSeEivr8CfsHSI7ePqnAvmAcnvL9mzeNiXcPIGC5QhalqveuN03Zm4 4s23nGqFxXxTZG/qzdAD/cDuj8ez7GqomXQIwWG7f0RjvLpnDK6MYYnj8O6/DiC4zO2Z 7UznmnfP+bF4PPAOvI+EtfZ+KH8GV3Q7Vfny1cdoUYfBtT6DxMZAC1VzS7ll76cZlvKR qCYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qcgIx79D; spf=pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=andreyknvl@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id o66-v6sor12129412wrb.30.2018.05.08.10.21.23 for (Google Transport Security); Tue, 08 May 2018 10:21:23 -0700 (PDT) Received-SPF: pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qcgIx79D; spf=pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=andreyknvl@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 :in-reply-to:references; bh=QmNrLV2ouq37rJeTa4aJrb/A4HzlLl64fsXLaFH/79U=; b=qcgIx79Dqsm5W/4pF2jVzunC8anbYsrTSswHKkoap9SoyraY8bFdrjTIPh7P5iJrwG CA+rziEZPaWJjgmWQGNE/jkhqJYlhxS/djf9pv+17hf3VvLGbviNvsI//1V/+f9Ql37/ ZQWGdHj8MWuRArZh0LANOE91Rz8B7gjV0piQNPD3i1PzWqlJHnx751cg0vsxRTOzeyc8 VwH/sXLr7lapQsCRIlsy4p62lAi99czL/XC9AqqY3FlT7wrCChQmYaszz4Jyed2Gkihe OjnTKKgtAnw6XgHE18yZeSuUAlS+IWcLkUtYU/355fP0Floh54DEqp/fafhiRSAKhq2i 3P7w== X-Google-Smtp-Source: AB8JxZrE0Zvje53ekCiQ5091B1wopM1Hl9R4HO51zbca6GFvC0pbfWGM3M9JPHV9QhEjxLxu4c/plA== X-Received: by 2002:adf:8e44:: with SMTP id n62-v6mr33809816wrb.159.1525800082211; Tue, 08 May 2018 10:21:22 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id m134sm14178311wmg.4.2018.05.08.10.21.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 10:21:21 -0700 (PDT) From: Andrey Konovalov To: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Jonathan Corbet , Catalin Marinas , Will Deacon , Christopher Li , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Masahiro Yamada , Michal Marek , Andrey Konovalov , Mark Rutland , Nick Desaulniers , Yury Norov , Marc Zyngier , Kristina Martsenko , Suzuki K Poulose , Punit Agrawal , Dave Martin , Ard Biesheuvel , James Morse , Michael Weiser , Julien Thierry , Tyler Baicar , "Eric W . Biederman" , Thomas Gleixner , Ingo Molnar , Kees Cook , Sandipan Das , David Woodhouse , Paul Lawrence , Herbert Xu , Josh Poimboeuf , Geert Uytterhoeven , Tom Lendacky , Arnd Bergmann , Dan Williams , Michal Hocko , Jan Kara , Ross Zwisler , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Matthew Wilcox , "Kirill A . Shutemov" , Souptick Joarder , Hugh Dickins , Davidlohr Bueso , Greg Kroah-Hartman , Philippe Ombredanne , Kate Stewart , Laura Abbott , Boris Brezillon , Vlastimil Babka , Pintu Agarwal , Doug Berger , Anshuman Khandual , Mike Rapoport , Mel Gorman , Pavel Tatashin , Tetsuo Handa , 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 , Kees Cook , Jann Horn , Mark Brand , Chintan Pandya Subject: [PATCH v1 06/16] khwasan, arm64: untag virt address in __kimg_to_phys Date: Tue, 8 May 2018 19:20:52 +0200 Message-Id: <82d6efa1879a9ab0f0c35d7251284f403c3ac82a.1525798754.git.andreyknvl@google.com> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog In-Reply-To: References: In-Reply-To: References: X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP __kimg_to_phys (which is used by virt_to_phys) assumes 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 __kimg_to_phys. __lm_to_phys doesn't require any fixups, as it zeroes out the top byte with the current implementation. Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/memory.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index 6d084431b7f7..f206273469b5 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -92,6 +92,12 @@ #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)) +#endif + #define MIN_THREAD_SHIFT (14 + KASAN_THREAD_SHIFT) /* @@ -225,7 +231,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_SET_TAG((addr), 0xff) - 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); \