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: 10670931 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 992AA13BF for ; Tue, 6 Nov 2018 17:31:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81CCF2ABB7 for ; Tue, 6 Nov 2018 17:31:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7591F2AB8C; Tue, 6 Nov 2018 17:31:14 +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 07DCB2ABC9 for ; Tue, 6 Nov 2018 17:31:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 312CA6B035A; Tue, 6 Nov 2018 12:30:57 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2DAAB6B035B; Tue, 6 Nov 2018 12:30:56 -0500 (EST) 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 861C76B035C; Tue, 6 Nov 2018 12:30:56 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by kanga.kvack.org (Postfix) with ESMTP id 3213A6B035A for ; Tue, 6 Nov 2018 12:30:56 -0500 (EST) Received: by mail-wr1-f72.google.com with SMTP id q1-v6so12316125wrr.9 for ; Tue, 06 Nov 2018 09:30:56 -0800 (PST) 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=iAdA2FIVXKrjFBT52+TbmLiPLvAT0qhuSkNJfNCOc2A=; b=X/16Q0/HLh3kWu41ZgJ012EE+fNaCSlZXvte/3viMIOejAqfcHHQHmfjrTsGVQOn/n 3CY/JO+ON1cQJHTGaJbFAE20GvMFMosZu4muYcGrXOh4yEVcaspPBmkulWXPoVD1D+nD coQ95erpGtsu5U95vIVSiazFqBqAXoYkkwPKIITKGvv2xeFdQDCZs9rozVROBYBqXl7r /KCjajtSgTUM8ODjlBHLQnXOtf7RB1PzA1jcNyQZjQ/694uV67alPlLRf3godlCUG0b3 PrY3wJ0myZlyeUlMw9z3iVGVRWICAKEwCbvkOlAZRv46b7Nrbi1c7j/Xj+7/L1CG37k8 UL9A== X-Gm-Message-State: AGRZ1gIcsW2zncx+CQGIFxrKmNlJYcxbaFUib/jdgh8VJJwaCJi6kjk/ Gdjea4BM9mNLAxk862ht77HMb+Y2DMHkR932RH/shBaEReqTWLy3t6drC77znyrk5bdiu4pHpOy 5Z6cPKU8qeW7XWpDjOlpvHz6BhfZo36K21rgfqKzCkTAbkA8g4kxgzIp/wyIWjqWv3qCFKZJt5p 9LZWamlGoKh3ZQ5aYKRKFXgUMKzFES7Pb53OUkgXbupx51HPml7kvGkFxc3RZD4dRPbkRilKXl1 6kmACyJA7paJXrxZOslU7F7mdJA0a5Kd2hLossnEnmD4a6v+vDanwDMpq8akadXe3uVUaO4t22M CFBE5AyeecaXTULL43xbP/fJIdCsPI0tdxtPzuVt+phP1QhZ3MfPU83xmth5YeNTr5HX8di1DEO c X-Received: by 2002:adf:bf10:: with SMTP id p16-v6mr23388263wrh.235.1541525455748; Tue, 06 Nov 2018 09:30:55 -0800 (PST) X-Received: by 2002:adf:bf10:: with SMTP id p16-v6mr23388219wrh.235.1541525455033; Tue, 06 Nov 2018 09:30:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541525455; cv=none; d=google.com; s=arc-20160816; b=QPHMA/TibpRs9aJVgx6jaNWEgtMy8pVqJ+V59lvaFdKcaWJjVfHVKUnirjJ3IUKzg0 Rzoc6d5jzmP1gyh++ruUmbLXhNZMMDmPTB5iK3h3RV4VPpvZLgT4O+niDq201UT6bJ0g wbAJeFLah5s7klweShHNMMYwCQeE6kWaTU920SYQkpeVGfknFGm0f2IP1HKCvHYkLEjZ goA6mSrlw5ba3cTGkwRW+M8R0KLhC6UD2iLI5p2CtyWYpWoX7c+VNKjPkgyaB+jpA3iD W1qr0BAxC9a7p+vwAB3idVW+ksXLPXyRhmrbjge+n+P6XTNKVloLR1MggS03LFgMg/jS 7f7Q== 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; bh=iAdA2FIVXKrjFBT52+TbmLiPLvAT0qhuSkNJfNCOc2A=; b=UYqLRaSkJJ1p/8Li+VCjnSZF91bp6i9/cGf7yVKslrDrPOFBAMOumJj9+H/JgOu/dh uQrD/+7hyuhx7d3U9VDrfSkg2610MPpTG1o0MPbE4SD7hO6Kp+tHz/+gHLFfSbWZo+JM VjHQh4T0PXQ4k9xo3aU66O2hU0yqorNMHJUDOw6abG1VZCRNUNN8iV5AxrjdT2U6WRFl +bK4fjpZnPb3FwR3qz8fLU6BRC2IRKdCPYNONzxKj14aKIwR0EMCpHh5rnSNQNcD62gC m0+/nM+NqH2hIM44ilgHBnT+KdNFbER/OfiGXucL1/mvr2Bp8ZNU1HSq6xccj/QiK+fK odxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=PGq5Em+h; 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 m18-v6sor8352239wrn.12.2018.11.06.09.30.54 for (Google Transport Security); Tue, 06 Nov 2018 09:30:55 -0800 (PST) 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=PGq5Em+h; 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=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-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 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 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))