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: 10579947 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 1B92E1805 for ; Wed, 29 Aug 2018 11:35:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D2A62AA9C for ; Wed, 29 Aug 2018 11:35:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00E4F2ABDA; Wed, 29 Aug 2018 11:35:50 +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=unavailable 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 952122AB91 for ; Wed, 29 Aug 2018 11:35:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 803966B4B7E; Wed, 29 Aug 2018 07:35:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7DCC36B4B7F; Wed, 29 Aug 2018 07:35:39 -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 592366B4B80; Wed, 29 Aug 2018 07:35:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm0-f72.google.com (mail-wm0-f72.google.com [74.125.82.72]) by kanga.kvack.org (Postfix) with ESMTP id EF83D6B4B7E for ; Wed, 29 Aug 2018 07:35:38 -0400 (EDT) Received: by mail-wm0-f72.google.com with SMTP id z23-v6so2816865wma.2 for ; Wed, 29 Aug 2018 04:35:38 -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:mime-version :content-transfer-encoding; bh=ScyVG8/8R+wHPT40gRo57Kpvm4BCgl84gWeZYScmJuw=; b=JAoKGCcWwvUk6RgKm/AEAu4M+ce41CBBImCo5qmTZCJFYoTN4W7vAt3v83WPZ6arTF 3btTC/50M/x4oikuTFRqLrKWBj/CSrT3Z+HkB/fSHapwFjvCbdX0DG+uZ0Q5qLHEhpxI yJFNBSr2hjcLdUtiDh8WUBkh/qHIlQM2ouzDr3ZGjnlXajlc+my+pgbMrELMdmciVnVt 3w4maMLrdq5bUIFcVZUeqH/+N6MH7/4u0Xbyr2LgniwD0e81qq8Wk/VxlbkM+YJTzk39 XXwOEFfofhRrJHK+YlXtv1sY7l7SLx0DQi7qsbQsfggqkvlBS8gN5xaD3K+eWseVwbHJ 8KZw== X-Gm-Message-State: APzg51AZh7hSIubdr370j6a6U4wftMpV1Kb/8c3sVqUK0R9172mQLWj4 A6njJiBsEMF92KHlw04i0H8usUSRoL/UPEHop/8x4iTjN0J8DEAuBt1hXpYECWY9wVnOuDmNW5J jk7MvRr39TT7hZmhddyFpN85DOPODh47fAUwfa5RM3/RQteRvL7G7ogxG1jkVFrG/hXEme8hU3U DsbEbOHZd/VHuwMYRpC3JKY3PbZVd/vIX8Qih7T4p9CKU+CKoe6zGRl7HLhOIkKKcsSfAk1P4I1 4ZRfqxEYBxG8Bi7tFQfBKsEHcWjFRYpY9j9U85zdfsuTHSq9u3ytmAo6d8rqH0Pmm8o12xda3uq EqdCL9Hc49xi3VLbHMntaXMUNI55xNg87FButYpIcQm8UNOG4NLOK3rnx1CTMtMvpc4AybMK4Qr b X-Received: by 2002:adf:c454:: with SMTP id a20-v6mr4009512wrg.20.1535542538514; Wed, 29 Aug 2018 04:35:38 -0700 (PDT) X-Received: by 2002:adf:c454:: with SMTP id a20-v6mr4009485wrg.20.1535542537862; Wed, 29 Aug 2018 04:35:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535542537; cv=none; d=google.com; s=arc-20160816; b=yxOmP9yLRYarQvlnUs/4BVo4uvpGDq44Nu1n2IxEU2USC9Kka/YkTJhx8t20NurRIe LPHXbdZPxgTckH8cUUl6uuUMV7tZ6SDkSY0MYQtJSp7U8WOA5dZTA+yiWj7QN5DPm1xz S7lH/M5n6sd5CeR2b4paX/skG3MKPBqmljsldTiYQdgTVir5wOONuDjNqSfD/15GHf7t HhWtCbKYYA2g3jVpRMuEXypeE1Yn5eYM+WTvoZICIOwShxpr8/jk3uNLeAd9FT+aeC8Y KWhkk+1i/9BZ8E2ZrXfMzLWirxNMlUI+F4HrVfJgHEkfM/y8YXQ/uccf6eWY5A/kcxPB gzaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=ScyVG8/8R+wHPT40gRo57Kpvm4BCgl84gWeZYScmJuw=; b=CGP4dGHoNFpFzurtHjXrJpjlZBK64GQkDE+EVNGIomf44UJObjeTKS5leMQeybGNtN 7GaARM+fkpCCHqRPJaonC6ZE0GnfUogSN6ejEXaPdku5zegMLlCc5ARjS2TH1USEWLgo CT6Ihb8MOdB4bcI1U7z0noa50Fmt1isDcM2GtqCHYFzXj3IzsWh1SGfLzz9+KTD7a7Wc FeuvU1UHDQpURdfp9LXXOiT5T3M0qXMBq9e2Pu15gonOIysDQrk43rVuF77xGnBULwRS o3qhe2Ofdh/jbPrMzznzP2YfzSgu8OWiFJJHf7hPLbbuADKUj/XXMohEQ3cXMyJoagI8 RDjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=wTs5ODdO; 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 s202-v6sor250704wmd.91.2018.08.29.04.35.37 for (Google Transport Security); Wed, 29 Aug 2018 04:35:37 -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=wTs5ODdO; 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 :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-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 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) 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))