From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C05E6C4707F for ; Fri, 21 May 2021 22:16:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA851613F4 for ; Fri, 21 May 2021 22:16:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230372AbhEUWRv (ORCPT ); Fri, 21 May 2021 18:17:51 -0400 Received: from mga09.intel.com ([134.134.136.24]:55678 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230290AbhEUWRG (ORCPT ); Fri, 21 May 2021 18:17:06 -0400 IronPort-SDR: Dx/o/CnRK5rc1SEmtVIJlgzxUqXw96lSJv2xUkEciKV8VT6y5YgCx9PLjyFlB/3fD/kZSecBo4 ppTVqged3qUg== X-IronPort-AV: E=McAfee;i="6200,9189,9991"; a="201618788" X-IronPort-AV: E=Sophos;i="5.82,319,1613462400"; d="scan'208";a="201618788" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2021 15:13:24 -0700 IronPort-SDR: jHailS4/bu9yvJG++qzIFR5Tg2qmjauFpxmU4QgJ6htzzaEADtc/8j9GNGMRW2XQ0bFHyxzHyz ATilK+c1T/sw== X-IronPort-AV: E=Sophos;i="5.82,319,1613462400"; d="scan'208";a="441116255" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2021 15:13:24 -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 , "Kirill A . Shutemov" , Catalin Marinas , Vincenzo Frascino , Will Deacon Subject: [PATCH v27 30/31] mm: Update arch_validate_flags() to test vma anonymous Date: Fri, 21 May 2021 15:12:10 -0700 Message-Id: <20210521221211.29077-31-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210521221211.29077-1-yu-cheng.yu@intel.com> References: <20210521221211.29077-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 Reviewed-by: Kirill A. Shutemov Cc: Catalin Marinas Cc: Kees Cook Cc: Vincenzo Frascino Cc: Will Deacon --- 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 a99b01877c45..352ad2762a6b 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1856,7 +1856,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 40428e8536bb..c28f9b1c9069 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