From patchwork Mon Jul 8 15:13:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 168666 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp7308873ilk; Mon, 8 Jul 2019 08:28:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzsx35FOmeJ7n2CkvsgGhKnyxFcm1s3UHjfLUfO/6QB2LdEPYfbb+keHc4dJe+FoZ25I+H3 X-Received: by 2002:a65:538d:: with SMTP id x13mr24534285pgq.190.1562599720057; Mon, 08 Jul 2019 08:28:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562599720; cv=none; d=google.com; s=arc-20160816; b=JgaTCJlo6FTVo2NgAPM+ZNi4xl3q4o5pw3ey3SXMOfG5yKbbu48LIEMCe+ZoRZJLen ntKOftL3v9A7ffZrFwMJY678L3xDD+MBb3/+ZqVCCAkfAv6nHZxoqw6ClrlrBdpvGaQH 3dCjhMKEqT5u/H4Vqf/73SBqUa7T+4BFEoOnFkm7rnpyzVIe1Elrxnk/Bsj+5xhMrekR urWq+1louqLRYoybfFe1O6Y63DJntw5QVMoxHRhtNKJbwBXfI/WErivOzrklcFGs15ng yCPSCYTT5REtS7ejHIKH1xo2ZNpbyzneZfV77j0gkwLiZvJS3HFYMnJSuDTXPeyPJw3w NLRg== 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=Q0Bn/kCsAAEIsl7/JRuTgs73rspEWlcATaIwKGAvCAc=; b=hoX39OEtiaYh1pig7Ct1FJHc1jpZRIUIPm6hm6nefD5/g3Kr03ojfHnVVUrPCUa/yL PBWyRiYlc3Ce4BSLkLa7go7uvb/VYo6/lhIx3tq5cGUdEVfuC3wMoIOfh85CIrXI9met Lw6EVE+n6qoDcWYJCt3S7GaZ0H6GSw4os6pq9TxchGhv7Zv0w9Km1i/Rri95YSChA1X3 rKIKkP55HswF2RyBBU0O9nAP1RzFBJH2js/1c7eih6w59JebXfbR/nkIYzzCHWHPlrTT l0FRBAkLRwb7hh79rLwFK/Lgc9DjOiqzGtBAjTqLxnJ4K89MvAfk2HEELv2pD/ygFFU/ ZUBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jhLYGoNt; 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 f32si17773597pje.70.2019.07.08.08.28.39; Mon, 08 Jul 2019 08:28:40 -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=jhLYGoNt; 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 S2389333AbfGHP2i (ORCPT + 30 others); Mon, 8 Jul 2019 11:28:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:57168 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731889AbfGHP2g (ORCPT ); Mon, 8 Jul 2019 11:28:36 -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 288CE21738; Mon, 8 Jul 2019 15:28:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562599715; bh=+LiCpwHsjJSrbJyVIAOZQxJz3K+eHJCNVBkQ9T3ckGk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jhLYGoNthqwYdqyQtKKyE2GLkaPJKSLgj4Jz3rON8qeKHXgVFS1cbFpfrMYcaiDi/ ET/HSOM3s8ho2iCZu4PvaEa6FLloiNvOZIC/uI8BOb66Q8n1Oo7XGjSE48MgnSPY+V PQI5FdUo1nyFK8qFOPNu5tTF0qkCBMttASLUCM1I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Catalin Marinas , Ard Biesheuvel , Will Deacon Subject: [PATCH 4.19 54/90] arm64: kaslr: keep modules inside module region when KASAN is enabled Date: Mon, 8 Jul 2019 17:13:21 +0200 Message-Id: <20190708150525.232113672@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150521.829733162@linuxfoundation.org> References: <20190708150521.829733162@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel commit 6f496a555d93db7a11d4860b9220d904822f586a upstream. When KASLR and KASAN are both enabled, we keep the modules where they are, and randomize the placement of the kernel so it is within 2 GB of the module region. The reason for this is that putting modules in the vmalloc region (like we normally do when KASLR is enabled) is not possible in this case, given that the entire vmalloc region is already backed by KASAN zero shadow pages, and so allocating dedicated KASAN shadow space as required by loaded modules is not possible. The default module allocation window is set to [_etext - 128MB, _etext] in kaslr.c, which is appropriate for KASLR kernels booted without a seed or with 'nokaslr' on the command line. However, as it turns out, it is not quite correct for the KASAN case, since it still intersects the vmalloc region at the top, where attempts to allocate shadow pages will collide with the KASAN zero shadow pages, causing a WARN() and all kinds of other trouble. So cap the top end to MODULES_END explicitly when running with KASAN. Cc: # 4.9+ Acked-by: Catalin Marinas Tested-by: Catalin Marinas Signed-off-by: Ard Biesheuvel Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- arch/arm64/kernel/module.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/arch/arm64/kernel/module.c +++ b/arch/arm64/kernel/module.c @@ -32,6 +32,7 @@ void *module_alloc(unsigned long size) { + u64 module_alloc_end = module_alloc_base + MODULES_VSIZE; gfp_t gfp_mask = GFP_KERNEL; void *p; @@ -39,9 +40,12 @@ void *module_alloc(unsigned long size) if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS)) gfp_mask |= __GFP_NOWARN; + if (IS_ENABLED(CONFIG_KASAN)) + /* don't exceed the static module region - see below */ + module_alloc_end = MODULES_END; + p = __vmalloc_node_range(size, MODULE_ALIGN, module_alloc_base, - module_alloc_base + MODULES_VSIZE, - gfp_mask, PAGE_KERNEL_EXEC, 0, + module_alloc_end, gfp_mask, PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE, __builtin_return_address(0)); if (!p && IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) &&