Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2094518ybp; Thu, 10 Oct 2019 02:05:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqx6AvfuzGgMJICYR28O2CJ8XocyU+MBRJDE42d/VcvwlSAgu7sGryqHjpBYS6HX0AfsLjI9 X-Received: by 2002:a17:906:f110:: with SMTP id gv16mr7177811ejb.331.1570698331215; Thu, 10 Oct 2019 02:05:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570698331; cv=none; d=google.com; s=arc-20160816; b=jU9rg2hVyTunQxDYWWyPKB4ZVuVA2NYph65aBGHm/ihWng9UiBsc8h5/ATBcx1xL/r 7OTWX5RXrX2aE31D66jPu49/AzRzXkBKhJJvG1hXOIAAM4bo+s5ZjFUYzvZ92pLHS9sQ dmq86smzNojObG1pWp806ifdLSjIllR9APr31KyNaH/Pn/hbUd930PSJb7lYzy03v6Ll dHuWx+gPcrkd0cWWCNB8dk/v4unswVVP5urFi4WUM1iACDWJs5DYySsd2ygJhriPHttR h/zNpyUblP0J0VtAF3FeE1NyKTVP/3ppK2RQf7JkQr2uXhNGqf0wYyjrU2oCfemSz0s7 xOsQ== 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=kCz+Ch9Ew8iqccuwPIKozP1NWyGN9aVQKGyMYq4+N2k=; b=mCaGG9odVhAXs0w5JnLMkPvpRf6dIPK6pXLfKcj8nWCQkqGVYjq5b+Tc8vHNl4NJFh TuI1OQkmbgylpPGCsvQETVgeE661mJTfpPcIJgiC3GLUOExlhfWt4SdBXZnVjzw+YWx4 fI/N9bI3cdkl2vqUVuqNiAb0Qg+kRcnte3qFfeCTtFO3o7sYW3Qf4ln0BxxlzJAAOqF2 1cBxLStFYSib35bBSVpp5rkMgrAbatrbT2+QYcGDiU1veBSXuhPJkb+0JCilJPV8zd03 5iJggLdphJRtyvPzSun3h1+e1nUeP1dg5uvQN3cou5/nX7XyphwSFfTabvdYdeWBArZ2 aypg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XAMDi4lF; 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 e21si3543036edb.164.2019.10.10.02.05.07; Thu, 10 Oct 2019 02:05:31 -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=XAMDi4lF; 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 S2387713AbfJJIiw (ORCPT + 99 others); Thu, 10 Oct 2019 04:38:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:41862 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387635AbfJJIiu (ORCPT ); Thu, 10 Oct 2019 04:38:50 -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 DA6E620B7C; Thu, 10 Oct 2019 08:38:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570696729; bh=7ICmKWHcVsxa7fjU9//oUnyZkEX5xHC61tndE/5jLus=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XAMDi4lFgVBRQs4zophgeUB1/Uoztx86N0RZDTuJ0BT0GygFwzx50G+NPtN6J51kn dJ+sm9Rmb/2bnVwxgPdcqT6Jo8ZAxdtJJyscuE4jsP41EHg0w+MtWvg9chVEeusz7I XFWbSvm2BAsx45KAXrFyvGuVovh9yX5R9afwci7s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe Leroy , Michael Ellerman Subject: [PATCH 5.3 030/148] powerpc/kasan: Fix parallel loading of modules. Date: Thu, 10 Oct 2019 10:34:51 +0200 Message-Id: <20191010083612.957788488@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083609.660878383@linuxfoundation.org> References: <20191010083609.660878383@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: Christophe Leroy commit 45ff3c55958542c3b76075d59741297b8cb31cbb upstream. Parallel loading of modules may lead to bad setup of shadow page table entries. First, lets align modules so that two modules never share the same shadow page. Second, ensure that two modules cannot allocate two page tables for the same PMD entry at the same time. This is done by using init_mm.page_table_lock in the same way as __pte_alloc_kernel() Fixes: 2edb16efc899 ("powerpc/32: Add KASAN support") Cc: stable@vger.kernel.org # v5.2+ Signed-off-by: Christophe Leroy Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/c97284f912128cbc3f2fe09d68e90e65fb3e6026.1565361876.git.christophe.leroy@c-s.fr Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/mm/kasan/kasan_init_32.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) --- a/arch/powerpc/mm/kasan/kasan_init_32.c +++ b/arch/powerpc/mm/kasan/kasan_init_32.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,19 @@ static int __ref kasan_init_shadow_page_ kasan_populate_pte(new, PAGE_READONLY); else kasan_populate_pte(new, PAGE_KERNEL_RO); - pmd_populate_kernel(&init_mm, pmd, new); + + smp_wmb(); /* See comment in __pte_alloc */ + + spin_lock(&init_mm.page_table_lock); + /* Has another populated it ? */ + if (likely((void *)pmd_page_vaddr(*pmd) == kasan_early_shadow_pte)) { + pmd_populate_kernel(&init_mm, pmd, new); + new = NULL; + } + spin_unlock(&init_mm.page_table_lock); + + if (new && slab_is_available()) + pte_free_kernel(&init_mm, new); } return 0; } @@ -137,7 +150,11 @@ void __init kasan_init(void) #ifdef CONFIG_MODULES void *module_alloc(unsigned long size) { - void *base = vmalloc_exec(size); + void *base; + + base = __vmalloc_node_range(size, MODULE_ALIGN, VMALLOC_START, VMALLOC_END, + GFP_KERNEL, PAGE_KERNEL_EXEC, VM_FLUSH_RESET_PERMS, + NUMA_NO_NODE, __builtin_return_address(0)); if (!base) return NULL;