From patchwork Tue Nov 6 17:30:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10671021 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 B101115E9 for ; Tue, 6 Nov 2018 17:32:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C6912AC0C for ; Tue, 6 Nov 2018 17:32:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 908152AC01; Tue, 6 Nov 2018 17:32:35 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 2EF582ABE2 for ; Tue, 6 Nov 2018 17:32:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389764AbeKGC5M (ORCPT ); Tue, 6 Nov 2018 21:57:12 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:40523 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389743AbeKGC5L (ORCPT ); Tue, 6 Nov 2018 21:57:11 -0500 Received: by mail-wr1-f67.google.com with SMTP id i17-v6so14467507wre.7 for ; Tue, 06 Nov 2018 09:30:55 -0800 (PST) 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=iAdA2FIVXKrjFBT52+TbmLiPLvAT0qhuSkNJfNCOc2A=; b=PGq5Em+hIMGRrbgQhOj9WL7gicpV1a3cL1rwh4lemyPxMvFq4cG0mLriMBcSZkZUkh y+3GtrAF+dUXGDq1ZluSY4Ae+lNWq96tu7xFx8+3iUW74K5mMz0bNUjL+NF6zctA+4QS qnxDtpPcAEaC7j/9Pr+9+iCcTjIRBCQDBlqgv7jG812R/tkMjbJxP0Ho79hqKU+e0BK/ 1V3aOBfi8vX1vQdtwGNFcAWiS0iJHMNQQEwB2emM9/9GBvWQmJ/6N9TDkBQji3hVOuxH OvBCjaHDQv/WAwDgrbXwVByowANBHjdFk09bux4a/YZWYWedpIt49wvjAZbdfS4GERDS Djtg== 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=iAdA2FIVXKrjFBT52+TbmLiPLvAT0qhuSkNJfNCOc2A=; b=ScUdX64aSp9OxbSd1RTFOE52x+0MaCIhbb0KVVMQWZm2pidPpBXNgCyJjHch1Jtz68 RHMvLZ/2e/iccV5DaGDD/Di2LaDW4votKnbo23yJo9KteTm4zIrXvmssBIiKuRzZkEqU Sctxdsf5nLMOUgCEsb1r+Itd3aLJ8vmjGJAya7An02TKW6nHH+x2wKc0yAHLgslAkGOF OJ8yBeadvpTGS2XmWRUkkHf3yGlkE9T1zcL3Om+E4h2mOXfuTxyJyoDugSQszvYaFIKK qMwbN22lNE4kVvCKWpeKrm+rePFcG+oTRAFrVovy2duVCLbAhjhhz7PK4e91BmWIKYUw TPvQ== X-Gm-Message-State: AGRZ1gL+j25jWNd9BJFgk0nefYJBCZ8aZfPWj8Ldo/6vdi4/gbnk9iAu d26NWT9eh3yL7UWaamjBOv7Ogw== X-Google-Smtp-Source: AJdET5f8uBubLHMHT+u4DepXXo41R1BmOHzAcM6VRyMsXW0CF05mu1xpsp3a9dayz1rV+f4WhA8xlg== X-Received: by 2002:adf:8989:: with SMTP id x9-v6mr22834650wrx.184.1541525454442; Tue, 06 Nov 2018 09:30:54 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id z17-v6sm16328416wrm.65.2018.11.06.09.30.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 09:30:53 -0800 (PST) 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 v10 08/22] kasan, arm64: untag address in __kimg_to_phys and _virt_addr_is_linear Date: Tue, 6 Nov 2018 18:30:23 +0100 Message-Id: X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: References: MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@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 tag-based KASAN. This patch resets the tag in those macros. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov 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))