Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3009207ybi; Mon, 17 Jun 2019 14:35:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqy5uSaEiL3M+pzsJ3cbQJWeERupW0dS8pudvmxXzaTVenItjxGARM9oimL355gOoPcilwm4 X-Received: by 2002:a62:2582:: with SMTP id l124mr92693728pfl.43.1560807332139; Mon, 17 Jun 2019 14:35:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560807332; cv=none; d=google.com; s=arc-20160816; b=I15GtmP1/SuJMsDygWTZGQY78wkGRvZkvisKIw4wfkktoIklDS2fOf6c2ikUF8YObe fIqx8E6BJWM+5CDLZNEmlOE3td6eGryYSG+QGIxkCYko8HBlh+wacNRki4LVpLJJ6Q18 wtuMlisnITAMIMTQUVgIRsQ1CTepxJl2uFYbd57gnnQfv1atNvpnOPgkCre2LO8sbbEC h2ZaksqubqZE8KS7GvmIBagMUPOvGROHInt6H/BHtVBuEWODKOn8xtXYf2acjGvQpUTb fOIWurDcAmPsS2iy086nRz00crq7uP4oJMLeRaG0VMRGkUY68NQLvvKWg0wSMfRZ2MYP VeSQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2oANRJLDUUs2TOBdqP5hJFxzvExhz+2VjqCZlzAtFw0=; b=ISQAwi4r8zwmNHp7/oIQOF4K6cbzDL2oBgb2dHMlEkM4m9tEJkDyOVKIA8WjIi0OMY wYh3GoheqdEkzsUzkVHPNIR8zAXh//xWAvozkZVwOsbSIkwC4B+4tMcMLWTKmy17dWYh HWQxY6P08b561CuThWFZrxOG5Wg/fV1C0pA/uPXa7Acl8xTJVlKJUsXG3v6gejqPX51k pLT8L5W0VN0+Ud5wNOhmzdxz5gEXM8BX798ezAHUJB6PiyUxQWvb7jxHaonMNyvHBdX0 IgYSxXVlebscppMA+8NwCI2NWZfpWR4tvVrqI0OumF6nZq83udRR3w+sm0bv6A15u783 mw5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SjsiOC0C; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v126si12368283pgb.484.2019.06.17.14.35.17; Mon, 17 Jun 2019 14:35:32 -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=@kernel.org header.s=default header.b=SjsiOC0C; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729719AbfFQVX2 (ORCPT + 99 others); Mon, 17 Jun 2019 17:23:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:48488 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729711AbfFQVXY (ORCPT ); Mon, 17 Jun 2019 17:23:24 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DD657206B7; Mon, 17 Jun 2019 21:23:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560806603; bh=mYhpHegnKzOHNL0fBQhB1WI/jHJUIg7YJUKcI2AzpYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SjsiOC0COmK45NXueurZ9eVgtIZMGw9TwCQl7QwS8CmeFwYsnWNnwzfdgjAlHAZ7Z zQIHwp+WSr7jeSGT1HYD5TUD2C0Zfqwob/g+wZZ2GqWTiHvCde9EQSLN1aRMASj/O8 h2Mi70Sq0LgjOt4q/RaigV/IPSno9I4Enm+RruOU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Kirill A. Shutemov" , Andrey Ryabinin , Thomas Gleixner , Borislav Petkov , "H. Peter Anvin" , Alexander Potapenko , Dmitry Vyukov , kasan-dev@googlegroups.com Subject: [PATCH 5.1 109/115] x86/kasan: Fix boot with 5-level paging and KASAN Date: Mon, 17 Jun 2019 23:10:09 +0200 Message-Id: <20190617210805.492186083@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617210759.929316339@linuxfoundation.org> References: <20190617210759.929316339@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Ryabinin commit f3176ec9420de0c385023afa3e4970129444ac2f upstream. Since commit d52888aa2753 ("x86/mm: Move LDT remap out of KASLR region on 5-level paging") kernel doesn't boot with KASAN on 5-level paging machines. The bug is actually in early_p4d_offset() and introduced by commit 12a8cc7fcf54 ("x86/kasan: Use the same shadow offset for 4- and 5-level paging") early_p4d_offset() tries to convert pgd_val(*pgd) value to a physical address. This doesn't make sense because pgd_val() already contains the physical address. It did work prior to commit d52888aa2753 because the result of "__pa_nodebug(pgd_val(*pgd)) & PTE_PFN_MASK" was the same as "pgd_val(*pgd) & PTE_PFN_MASK". __pa_nodebug() just set some high bits which were masked out by applying PTE_PFN_MASK. After the change of the PAGE_OFFSET offset in commit d52888aa2753 __pa_nodebug(pgd_val(*pgd)) started to return a value with more high bits set and PTE_PFN_MASK wasn't enough to mask out all of them. So it returns a wrong not even canonical address and crashes on the attempt to dereference it. Switch back to pgd_val() & PTE_PFN_MASK to cure the issue. Fixes: 12a8cc7fcf54 ("x86/kasan: Use the same shadow offset for 4- and 5-level paging") Reported-by: Kirill A. Shutemov Signed-off-by: Andrey Ryabinin Signed-off-by: Thomas Gleixner Cc: Borislav Petkov Cc: "H. Peter Anvin" Cc: Alexander Potapenko Cc: Dmitry Vyukov Cc: kasan-dev@googlegroups.com Cc: stable@vger.kernel.org Cc: Link: https://lkml.kernel.org/r/20190614143149.2227-1-aryabinin@virtuozzo.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/mm/kasan_init_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/x86/mm/kasan_init_64.c +++ b/arch/x86/mm/kasan_init_64.c @@ -199,7 +199,7 @@ static inline p4d_t *early_p4d_offset(pg if (!pgtable_l5_enabled()) return (p4d_t *)pgd; - p4d = __pa_nodebug(pgd_val(*pgd)) & PTE_PFN_MASK; + p4d = pgd_val(*pgd) & PTE_PFN_MASK; p4d += __START_KERNEL_map - phys_base; return (p4d_t *)p4d + p4d_index(addr); }