Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4832877pxy; Tue, 27 Apr 2021 13:48:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5y0tCWT9165qQtWchW6HnCHt5eN8yGQ5QsISVnkuUCDbZHJYf/bsntnM9nSVDSpGvGjro X-Received: by 2002:aa7:8a11:0:b029:263:6c93:726d with SMTP id m17-20020aa78a110000b02902636c93726dmr2024073pfa.66.1619556504565; Tue, 27 Apr 2021 13:48:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619556504; cv=none; d=google.com; s=arc-20160816; b=uSMja2tTakxoMducbiznvlR1rrQWO9Sf1tsqVt2adjDqu1coK6QN8EM/ccOoT9YJD0 TpRdUAjBHjoL7PfbQtdNJoHRz4Hl08BeaRbSxwjCJmzIs3H7ASZkhqUy0tHXNLQ5TX22 OqgpuLkwaEIg5n5bFXrwOouAbyu9r53wqM0Q4aDIIbD+UIy/G1KTIE94q1lDF/qPuvWf y3ph+fqtvI3IdtLFcGD7fMroPFI9k1UokDEd6nx7ud6pLhIFhOVKTWY6FgLDp5Rz86Hj MFCH6cEBVdO0DXF7FFl8ABsaEsZ5sB79hqG5yeLEHuBUpKzKbpwZovk0Y7J7l4eDqjle kJnw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=Rw//2LU8to3WCaDo3ZHxxo2gktUIAXCPtebdsZHtHkQ=; b=szPkejio2D/Oayzq+hF9MOgzn507C/73ls7stfqoK6Z8xsMyB1FIvGNAcd+CrJqbuM QqgoAEuAYJnQ9X0ytPjJSumR3hvHbdPkhRx+sssoJDrKLMZXgVbf0EGHu9Zq7T1TYuxj SApYq9oF6w+ckRiOZotW2QA3a6cNn1kd5LOhP0KrXwioDBvTBsR6oJ5VXYBqh+1NZK1K nieiVJoJVlaSV3209pBtoQHbSFuvKvOzkfkIHhtQh0oCJz1NijyvHoOW6OpmuL5GP7Kx iJ9JgWzCrbvrfZkPF5lh1AR1wdBe/Y7CDgBSNbjEld5VwhSC9VHiqbMHJWF3lyx8IYP6 ZmUQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ot9si4667044pjb.104.2021.04.27.13.48.11; Tue, 27 Apr 2021 13:48:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239107AbhD0UrK (ORCPT + 99 others); Tue, 27 Apr 2021 16:47:10 -0400 Received: from mga05.intel.com ([192.55.52.43]:31798 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239044AbhD0Uqc (ORCPT ); Tue, 27 Apr 2021 16:46:32 -0400 IronPort-SDR: ZL2eABa1zh3dlqU/92qMT0yVznQh+2+5h9GZ1LPD8kLcwiWQenzWPJY/KAERdrhD5mWIMV1Wpg 8IQUiRMvSFdA== X-IronPort-AV: E=McAfee;i="6200,9189,9967"; a="281922505" X-IronPort-AV: E=Sophos;i="5.82,255,1613462400"; d="scan'208";a="281922505" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2021 13:44:25 -0700 IronPort-SDR: xtJHpIS9Akgk3yrr6I4AH9oYnMCacZLvBt3pMls0JqIaGOZgvywvKXp62L6pyHD+s4IAixmFBu 6gDaLjPlgRdQ== X-IronPort-AV: E=Sophos;i="5.82,255,1613462400"; d="scan'208";a="465623573" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2021 13:44:25 -0700 From: Yu-cheng Yu To: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin , Weijiang Yang , Pengfei Xu , Haitao Huang Cc: Yu-cheng Yu , Catalin Marinas , "Kirill A . Shutemov" , Vincenzo Frascino , Will Deacon Subject: [PATCH v26 29/30] mm: Update arch_validate_flags() to test vma anonymous Date: Tue, 27 Apr 2021 13:43:14 -0700 Message-Id: <20210427204315.24153-30-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210427204315.24153-1-yu-cheng.yu@intel.com> References: <20210427204315.24153-1-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When newer VM flags are being created, such as VM_MTE, it becomes necessary for mmap/mprotect to verify if certain flags are being applied to an anonymous VMA. To solve this, one approach is adding a VM flag to track that MAP_ANONYMOUS is specified [1], and then using the flag in arch_validate_flags(). Another approach is passing the VMA to arch_validate_flags(), and check vma_is_anonymous(). To prepare the introduction of PROT_SHADOW_STACK, which creates a shadow stack mapping and can be applied only to an anonymous VMA, update arch_validate_flags() to pass in the VMA. [1] commit 9f3419315f3c ("arm64: mte: Add PROT_MTE support to mmap() and mprotect()"), Signed-off-by: Yu-cheng Yu Cc: Catalin Marinas Cc: Kees Cook Cc: Kirill A. Shutemov Cc: Vincenzo Frascino Cc: Will Deacon --- v26: - Instead of passing vma is anonymous, pass the VMA to arch_validate_flags(). arch/arm64/include/asm/mman.h | 4 ++-- arch/sparc/include/asm/mman.h | 4 ++-- include/linux/mman.h | 2 +- mm/mmap.c | 2 +- mm/mprotect.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/mman.h b/arch/arm64/include/asm/mman.h index e3e28f7daf62..7c45e7578f78 100644 --- a/arch/arm64/include/asm/mman.h +++ b/arch/arm64/include/asm/mman.h @@ -74,7 +74,7 @@ static inline bool arch_validate_prot(unsigned long prot, } #define arch_validate_prot(prot, addr) arch_validate_prot(prot, addr) -static inline bool arch_validate_flags(unsigned long vm_flags) +static inline bool arch_validate_flags(struct vm_area_struct *vma, unsigned long vm_flags) { if (!system_supports_mte()) return true; @@ -82,6 +82,6 @@ static inline bool arch_validate_flags(unsigned long vm_flags) /* only allow VM_MTE if VM_MTE_ALLOWED has been set previously */ return !(vm_flags & VM_MTE) || (vm_flags & VM_MTE_ALLOWED); } -#define arch_validate_flags(vm_flags) arch_validate_flags(vm_flags) +#define arch_validate_flags(vma, vm_flags) arch_validate_flags(vma, vm_flags) #endif /* ! __ASM_MMAN_H__ */ diff --git a/arch/sparc/include/asm/mman.h b/arch/sparc/include/asm/mman.h index 274217e7ed70..0ec4975f167d 100644 --- a/arch/sparc/include/asm/mman.h +++ b/arch/sparc/include/asm/mman.h @@ -60,11 +60,11 @@ static inline int sparc_validate_prot(unsigned long prot, unsigned long addr) return 1; } -#define arch_validate_flags(vm_flags) arch_validate_flags(vm_flags) +#define arch_validate_flags(vma, vm_flags) arch_validate_flags(vma, vm_flags) /* arch_validate_flags() - Ensure combination of flags is valid for a * VMA. */ -static inline bool arch_validate_flags(unsigned long vm_flags) +static inline bool arch_validate_flags(struct vm_area_struct *vma, unsigned long vm_flags) { /* If ADI is being enabled on this VMA, check for ADI * capability on the platform and ensure VMA is suitable diff --git a/include/linux/mman.h b/include/linux/mman.h index 629cefc4ecba..41d6fbf4e7d9 100644 --- a/include/linux/mman.h +++ b/include/linux/mman.h @@ -114,7 +114,7 @@ static inline bool arch_validate_prot(unsigned long prot, unsigned long addr) * * Returns true if the VM_* flags are valid. */ -static inline bool arch_validate_flags(unsigned long flags) +static inline bool arch_validate_flags(struct vm_area_struct *vma, unsigned long flags) { return true; } diff --git a/mm/mmap.c b/mm/mmap.c index 7b2992ef8ee0..b6a2b44b75dc 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1850,7 +1850,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, } /* Allow architectures to sanity-check the vm_flags */ - if (!arch_validate_flags(vma->vm_flags)) { + if (!arch_validate_flags(vma, vma->vm_flags)) { error = -EINVAL; if (file) goto unmap_and_free_vma; diff --git a/mm/mprotect.c b/mm/mprotect.c index 3b2f0d75519f..7aef1e1af11a 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -611,7 +611,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len, } /* Allow architectures to sanity-check the new flags */ - if (!arch_validate_flags(newflags)) { + if (!arch_validate_flags(vma, newflags)) { error = -EINVAL; goto out; } -- 2.21.0