Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1689536pxb; Fri, 20 Aug 2021 11:23:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzs2J5yPdYegPKRZBUzsNxzQ9BBm8IsW5k9sZJgpidNVOvvEnXzMsuguaVPjzCqD7GQrLBE X-Received: by 2002:a6b:b2d4:: with SMTP id b203mr17376434iof.179.1629483825430; Fri, 20 Aug 2021 11:23:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629483825; cv=none; d=google.com; s=arc-20160816; b=YDG7Oc+42j190b/Y/fxCI3TX5C8GIuUsXzUecZmJs9Vxt6X4UJDHoA+QS80wFWS3FQ CcsKoFFrvriiq2cd6WAadavT9bG1jyppF7GALSh7AnLVzItroIyRP006CQPMVtIf9i3j 7dxednataaYoi4WlDFzlReYVjaTjwsVjzcHV/JIU3PSglawb2BzL/xGG2qcdy88yL5FX aDKGGM/HpdjvI3MkL/b1Yr2F1RnzSNg+pzLuNNpPRe2Ax2EqISWMn9Ogp50JJV5t87Tz ZMdClkI8Wi/TumCv1H/yN7l7PPwCFRVA6fwlUSLL4UtFAJ/kd6GM74QNfIy1SCSjaodd BvIg== 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; bh=dn4kRAOUO+oz8rOgo+Zb4HhKB/lga2ZgtpuoVrOwdb0=; b=aTsqydwlBzkkWG8mvikitzeym6WA2GgIMlfQ9wnTSF+eshes/FI8MtBIyAhHtLyomG eO76P9yagaZkFSz19qqDZ481JsQ5vqnTPbuM5ClTMqIuUkkuPxKMUyAVvb2qzHB9NPE6 CcaHz7grjb87lBJMrBoFkzP/XLex5fV0OoniaXbV6fQh7N/+BeF5Gm/UcymTEBm2aYjy cH4ErxDRXF9s6wx9IBXPtOEPsnGwchQgux72SzKbhxjdlvtJeT+kV5JW80Ko7GfoLXb1 Jb8zocsQUoTJIPq4zmNv9mriH0JCmH8dlA46RNgtQ+5Z48BCPiPFYnFDq2UrvsC1+959 xP3Q== 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 d131si9145955iog.11.2021.08.20.11.23.33; Fri, 20 Aug 2021 11:23:45 -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 S238427AbhHTSXV (ORCPT + 99 others); Fri, 20 Aug 2021 14:23:21 -0400 Received: from mga05.intel.com ([192.55.52.43]:22456 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238369AbhHTSWX (ORCPT ); Fri, 20 Aug 2021 14:22:23 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10082"; a="302407845" X-IronPort-AV: E=Sophos;i="5.84,338,1620716400"; d="scan'208";a="302407845" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Aug 2021 11:18:53 -0700 X-IronPort-AV: E=Sophos;i="5.84,338,1620716400"; d="scan'208";a="533074803" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Aug 2021 11:18:52 -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" , Dave Martin , Weijiang Yang , Pengfei Xu , Haitao Huang , Rick P Edgecombe Cc: Yu-cheng Yu , "Kirill A . Shutemov" , Catalin Marinas , Vincenzo Frascino , Will Deacon Subject: [PATCH v29 31/32] mm: Update arch_validate_flags() to test vma anonymous Date: Fri, 20 Aug 2021 11:12:00 -0700 Message-Id: <20210820181201.31490-32-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210820181201.31490-1-yu-cheng.yu@intel.com> References: <20210820181201.31490-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 Acked-by: 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 ebb09a964272..b6a9414e806c 100644 --- a/include/linux/mman.h +++ b/include/linux/mman.h @@ -116,7 +116,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 100db6e46831..fe7afd968087 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1853,7 +1853,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 94cb799216ec..e826ecb68e3a 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -621,7 +621,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