Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp787729imm; Fri, 21 Sep 2018 08:17:48 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYeUaXJJK9sVV00hLt5QxKytY1cJVknN1NZpgzCKGNh87mYJTnJp+NJdff4m5hJirkJ8PFz X-Received: by 2002:a62:4808:: with SMTP id v8-v6mr47355376pfa.89.1537543068362; Fri, 21 Sep 2018 08:17:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537543068; cv=none; d=google.com; s=arc-20160816; b=O9kmDvFm47RLl/jq6jhQgBOhQojlKtc7NridCMMMvfD1ZMoQqRtw5lg++sUQeCcj0V 8MsjlWSQWsV3NeTkLGtFKEzEvul8BjyLOQ2q45fIaC0FzbK8H+syADYVmFRzX6igw/jq Vr2RZA7Pojwyt4OviLQArrYF9QAjU7ff+oVARhin8UZgLYiYCUYK3gj3+SRYYnJsAmlf IyWkuoXWuPVvorvdA/zl6Wuq3zBjCFIHNU+J62aujRJ4MS8Elch55RyZcKA424C7z2SP ro/upVkA+7TK0r2uuTuEcVKQCASqwlvMMP4oNW/kMKR/qggFMwFVSxaqm0AfqV5sewpu WgQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=m233AnC4qvrdV4eo3QzdNfMFrtQI7a9l1G83xPQzcRQ=; b=lvRIaN2ZUKxqmFDeoduE6c07w/xqSUvvYmkp39GjeL0CqMVDPwiOCWpf+8QIoXPXEx Ezdm9OFTaGY/LsTxCf/P8AYoHV0xJNV+4etKybU9+eJlpIDWU3WeFisovyU4IyXg2tGO Igc6N91PL8qbKei701y3s+aNH738uKrpSifglDW6ZbGsU5kA7pkIUu0zp+RhEoef3hCo 7psSh1zqciufxNZwE+VIt0jex8C9t6oDXIN05W0GJmrU/5zWPncqyz7opE+0IdY+uEfj RiOTKnuWkDpI/eBeEFM9UQ5sIsWJVsO/kaf/hBBq4RWKVh9N/5HaN5Yz80+aUJ2tzfkj bMYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eXnNKEPH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x16-v6si26112123pgf.311.2018.09.21.08.17.23; Fri, 21 Sep 2018 08:17:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eXnNKEPH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390529AbeIUVEr (ORCPT + 99 others); Fri, 21 Sep 2018 17:04:47 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:46147 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390964AbeIUVDT (ORCPT ); Fri, 21 Sep 2018 17:03:19 -0400 Received: by mail-wr1-f68.google.com with SMTP id z3-v6so1388485wrr.13 for ; Fri, 21 Sep 2018 08:13:59 -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=m233AnC4qvrdV4eo3QzdNfMFrtQI7a9l1G83xPQzcRQ=; b=eXnNKEPHitQJezi0vHtHIhgtf1+Nu76xnakGrrSIlmxQYrEomHDWnSPKQZv2RBaMyg DfOVVg7EW8nVvRheW/vPQsiupWVv3evsdHoJRSqZc5ljRyWpJPE9tFdyKd5RY7/gEjsf Bo9WOBw2fmhd1oljcXXeQgEpPVkER26e6mZUo021V6Dlc4TrtV542wIpdX1hwq2n1yWg A1wHs5iM0blg0U9U5JZfWUVL3DgRODcMiXnIJK/FzsWXwjYpVDteD/5/1twuScg+5ilL qdeYlxvgCjApJidVANb5pXkm6j00YzJAnSB/ACTkn+5l0LVYlZeh0KIpEQ5r1osMg3rK 6eFQ== 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=m233AnC4qvrdV4eo3QzdNfMFrtQI7a9l1G83xPQzcRQ=; b=q5moj15yvc+rYFx5K2/NPD6CG7bsYLgna0tHDGbDYQ6tUDGUJDKod4vhWquEmiMTf2 JZJXmow4o1sVVCxnDuxalhLricFegU7lENehcGemVY1R+aevIhwpTL8x3lZQj1ObL7wG eDDj1Uy/Vzlbo0VLnfAGfXeP8C97gE1662qfP5tXyUJp48SeTJWa/k7i8m6hjt6M7gTT fX1PzHA3+jozY1j516uCZ0yG3OJydDSoDEZUs5prHU9m2qse5ekFAtzNNEPVXX2GMSPM OHeFI7M2zTKZha/4ClZxjYq/l15cv+VxSUxinrcx+QboDW9XVtwOCDfNhAkHzQ2CdgOv 1saQ== X-Gm-Message-State: APzg51AUbIscSWdZn/OS5QBi+AeezefpaYX8BBc5yCNqPTZJ0hg2rnAE 7Dael1QCAUkX3XLymxuRwKRLhQ== X-Received: by 2002:adf:9244:: with SMTP id 62-v6mr35901684wrj.62.1537542838400; Fri, 21 Sep 2018 08:13:58 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id e7-v6sm27990271wru.46.2018.09.21.08.13.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 08:13:57 -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 v9 07/20] kasan, arm64: untag address in __kimg_to_phys and _virt_addr_is_linear Date: Fri, 21 Sep 2018 17:13:29 +0200 Message-Id: <1324a622035ee2a6fecd1e729a62af22542d9f3e.1537542735.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.0.444.g18242da7ef-goog In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org __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 tag-based KASAN. This patch resets the tag in those macros. Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/memory.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index 0f1e024a951f..3226a0218b0b 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -92,6 +92,15 @@ #define KASAN_THREAD_SHIFT 0 #endif +#ifdef CONFIG_KASAN_SW_TAGS +#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) +#else +#define KASAN_RESET_TAG(addr) addr +#endif + #define MIN_THREAD_SHIFT (14 + KASAN_THREAD_SHIFT) /* @@ -232,7 +241,7 @@ 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) -#define __kimg_to_phys(addr) ((addr) - kimage_voffset) +#define __kimg_to_phys(addr) (KASAN_RESET_TAG(addr) - kimage_voffset) #define __virt_to_phys_nodebug(x) ({ \ phys_addr_t __x = (phys_addr_t)(x); \ @@ -308,7 +317,8 @@ static inline void *phys_to_virt(phys_addr_t x) #endif #endif -#define _virt_addr_is_linear(kaddr) (((u64)(kaddr)) >= PAGE_OFFSET) +#define _virt_addr_is_linear(kaddr) (KASAN_RESET_TAG((u64)(kaddr)) >= \ + PAGE_OFFSET) #define virt_addr_valid(kaddr) (_virt_addr_is_linear(kaddr) && \ _virt_addr_valid(kaddr)) -- 2.19.0.444.g18242da7ef-goog