From patchwork Tue Nov 17 13:05:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 325448 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp4180513ils; Tue, 17 Nov 2020 05:46:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJzTphMHTJcksROQRjn7x9Cz7vkdX0r/1yq+tG4+szW6Vk8sVp7kGOlKHv0HrhL8Zz0c5EBp X-Received: by 2002:a05:6402:b3b:: with SMTP id bo27mr20544696edb.376.1605620795957; Tue, 17 Nov 2020 05:46:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605620795; cv=none; d=google.com; s=arc-20160816; b=uT4/KKUgI/MDrp91PS76pBC4y2hEGtO9EVlyFxppG6UDR04xhoiGYke1CxXsjKiKpj VeWMQgbOKGcAU6qMDJsfohK9fWBdAVRvjWtNhIbqpTIWEiKDu7c917FP5lfoWEQLbfT0 apesLEaVPD7mNqjl1ZRKyzeLX5yZqzmMa9rzjCNETNbr4ZGcvWZsdM6OYSIPJ7QokdNn e7UlPFDydOygqiY+ovS5lKkciNEYmUT06XPKw15YlwFTysRchB5BzUTApwWfDEe33tbo IX4WUfPuraYpqKKathttmHJSpSC8Sbwn7XR8xIv5bBMbWudeETcYO7g8yDzEnHOXGjya UW1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QbP4vopc8iHvZgIg/65gNHLaN5bjJPklYqnRcsgGeCg=; b=XM9isukN2OuNoZN4fDfPhnnPqkCBUQXqleW6NWdKe/QQatQZtii88PXGWBsLPbq8h/ g3PyxY9VQT0VFmuCJ0r3Gj5wYKDQwHFRd0Zvk2zfj6pSOKvSMX0Sn0OvS70sUE7DbpUH ATqfIJIRU4Ulty5+wIh3ljOFWc7Aul+HeyKqjkeHaWti0eF/6fCV/5jtk7/wAc2fbaA8 BkmHX84qzCBjMxmzw0mx300CrU1KLpRLEC0RNCUZi+SF/ugj1PPf/g9oBdAtZJ5v2Rxj 5gKC6b1UjU75EL0oUsih/aK5HEg5g7KHilLutds0bi+uZoJAssVTvlo8f+mihuXedHiy hjMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1jNLsVse; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cd24si12999456ejb.213.2020.11.17.05.46.35; Tue, 17 Nov 2020 05:46:35 -0800 (PST) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1jNLsVse; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733051AbgKQNiS (ORCPT + 14 others); Tue, 17 Nov 2020 08:38:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:49638 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733045AbgKQNiR (ORCPT ); Tue, 17 Nov 2020 08:38:17 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 23484246AB; Tue, 17 Nov 2020 13:38:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605620296; bh=050kAai3rGkvt0932R2moPRhv1QradTBEV+TlPQtElA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1jNLsVseTVv2Bvv/WmJBtp4rgE354jndcxtvGSl9pzpvN8cuVzYMdBgEJvd7E7VhO 3WkZ3jnSH64aoIJ4keS04T/rzRNp2wab+QmWWiu47XgPxJVfVVkhcklCwY730Tvdzq vZsJPRh1nZx/85EryWC+FDWemH0JIQBmNbl/vob4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anshuman Khandual , Ard Biesheuvel , Catalin Marinas , Will Deacon , Mark Rutland , Steven Price , Robin Murphy , David Hildenbrand , Andrew Morton , linux-arm-kernel@lists.infradead.org, Sasha Levin Subject: [PATCH 5.9 172/255] arm64/mm: Validate hotplug range before creating linear mapping Date: Tue, 17 Nov 2020 14:05:12 +0100 Message-Id: <20201117122147.296989748@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122138.925150709@linuxfoundation.org> References: <20201117122138.925150709@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Anshuman Khandual [ Upstream commit 58284a901b426e6130672e9f14c30dfd5a9dbde0 ] During memory hotplug process, the linear mapping should not be created for a given memory range if that would fall outside the maximum allowed linear range. Else it might cause memory corruption in the kernel virtual space. Maximum linear mapping region is [PAGE_OFFSET..(PAGE_END -1)] accommodating both its ends but excluding PAGE_END. Max physical range that can be mapped inside this linear mapping range, must also be derived from its end points. This ensures that arch_add_memory() validates memory hot add range for its potential linear mapping requirements, before creating it with __create_pgd_mapping(). Fixes: 4ab215061554 ("arm64: Add memory hotplug support") Signed-off-by: Anshuman Khandual Reviewed-by: Ard Biesheuvel Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: Ard Biesheuvel Cc: Steven Price Cc: Robin Murphy Cc: David Hildenbrand Cc: Andrew Morton Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Link: https://lore.kernel.org/r/1605252614-761-1-git-send-email-anshuman.khandual@arm.com Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/mm/mmu.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) -- 2.27.0 diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 75df62fea1b68..a834e7fb0e250 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1433,11 +1433,28 @@ static void __remove_pgd_mapping(pgd_t *pgdir, unsigned long start, u64 size) free_empty_tables(start, end, PAGE_OFFSET, PAGE_END); } +static bool inside_linear_region(u64 start, u64 size) +{ + /* + * Linear mapping region is the range [PAGE_OFFSET..(PAGE_END - 1)] + * accommodating both its ends but excluding PAGE_END. Max physical + * range which can be mapped inside this linear mapping range, must + * also be derived from its end points. + */ + return start >= __pa(_PAGE_OFFSET(vabits_actual)) && + (start + size - 1) <= __pa(PAGE_END - 1); +} + int arch_add_memory(int nid, u64 start, u64 size, struct mhp_params *params) { int ret, flags = 0; + if (!inside_linear_region(start, size)) { + pr_err("[%llx %llx] is outside linear mapping region\n", start, start + size); + return -EINVAL; + } + if (rodata_full || debug_pagealloc_enabled()) flags = NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS;