Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp620494pxb; Tue, 1 Feb 2022 07:08:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwKMn9dPAEykpAMVfe46XZTuWwqrKWoQQ0nA3pOEgkjLaYPpnPbPl/K7/tUGdq3leELS9ou X-Received: by 2002:a05:6402:19a9:: with SMTP id o9mr25737069edz.295.1643728133279; Tue, 01 Feb 2022 07:08:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643728133; cv=none; d=google.com; s=arc-20160816; b=xx3ToAFByHDneAUY3h7Rzlgv+taR4yABQEr1xmtBedx1myJUf6Gigooq1ZUcfszIGE JBtvZIV3dGD10bmZqTTECpIZ63YnWIesoiMqHi8umtu6ZaI2LsoGqEU579nngzNS0KvR dDsg5Yx0vqs4XHwU1Y5gVWx/yEQxV2U5tw663K5dGQ/qc64OUXwVEmPi+R4om+KLDpQU PYvNE8r1uvZm0JYbpOvRx46ID6CvcOe3mTBTvy71lQfockW/DJHQCpRIxIB3Am7Bl8vN FGDADaYJ4Kl0oJdjjx3iQNi3rb2mKV6LcEkftOgjqQui+ubnEz0mKPAeUBnyHZZ5h1BZ B9cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=pdXYUGWKqXATUA4zcVvXgw9BiltBXpUsP509an9i05Y=; b=hRtPvri5wchFYHS9lAqNan3fGq+qRQ4DeTTQO9IhK/P5fT6ho0ANY0A2GqZNZ3v/fo tRIUVt7r0rSmr+fGN6F30j1SVqzoYSjOGjIkZ1GK6WB7cgi5T4Mqf4uTnWt0xkMyzpPA Cacczo5iKxCSXRdNP3XQLpM2Wl/aDpdYFXtdul9a2uF8wbAO76P9TbBU4gdiB8WA4WM8 L/WK7Di9Ym8EnNxXNm2K/e+YyCquSHhs1pD2UERsiK/mHL2h2bk/RSROTj26CDHZlb/2 fVde5zsgHQy36IMEuEaOdxToAeHaAhfjQ6GfcSmuvAqirzYOHC0BE6LUYK9J0T5gonL4 bAVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=oEesWLWT; 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=pass (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 e7si11452720edz.397.2022.02.01.07.08.26; Tue, 01 Feb 2022 07:08:53 -0800 (PST) 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; dkim=pass header.i=@intel.com header.s=Intel header.b=oEesWLWT; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356895AbiA3V0S (ORCPT + 99 others); Sun, 30 Jan 2022 16:26:18 -0500 Received: from mga06.intel.com ([134.134.136.31]:52048 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356933AbiA3VYV (ORCPT ); Sun, 30 Jan 2022 16:24:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643577861; x=1675113861; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=IJv3bcwNym+ue5ES2C0XMwMTBK04UF1ldHp0VsVFE1E=; b=oEesWLWTvf1NRortqptmF869smrGW3s7xRGRs/R3/6goKAl4lEvk7tE0 B4z9qeXr3okAs2CasejlCWl00c0YrO2CTK3L7u90sfZQ4S7tTZfEwBG0f jJRjhyLkUpVBuUhIiQRi+6RH/BozGgiQltL3IFvSf+oi1h6whmw9HU4hJ WSnUUKU6xlA8SO+1qs4bCgnaJUrkd0+vXBryYKVZhGCBpsb9YO35iOY4j s32Go/Lu/PYFdcszKp9AqPdRKPoD/z/cuhH2XQZirRcVH9o44vkg5En7u A+UJ+Ix3KvIeLllFsZxV0KcshVCTaInSz6Kk8fN9N2dIwmSbmg4supjvL g==; X-IronPort-AV: E=McAfee;i="6200,9189,10243"; a="308104965" X-IronPort-AV: E=Sophos;i="5.88,329,1635231600"; d="scan'208";a="308104965" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2022 13:22:05 -0800 X-IronPort-AV: E=Sophos;i="5.88,329,1635231600"; d="scan'208";a="536856881" Received: from avmallar-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.123.171]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2022 13:22:04 -0800 From: Rick Edgecombe 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 , "Kirill A . Shutemov" , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu , Andrew Morton Subject: [PATCH 24/35] mm: Re-introduce vm_flags to do_mmap() Date: Sun, 30 Jan 2022 13:18:27 -0800 Message-Id: <20220130211838.8382-25-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220130211838.8382-1-rick.p.edgecombe@intel.com> References: <20220130211838.8382-1-rick.p.edgecombe@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yu-cheng Yu There was no more caller passing vm_flags to do_mmap(), and vm_flags was removed from the function's input by: commit 45e55300f114 ("mm: remove unnecessary wrapper function do_mmap_pgoff()"). There is a new user now. Shadow stack allocation passes VM_SHADOW_STACK to do_mmap(). Thus, re-introduce vm_flags to do_mmap(). Signed-off-by: Yu-cheng Yu Reviewed-by: Peter Collingbourne Reviewed-by: Kees Cook Reviewed-by: Kirill A. Shutemov Signed-off-by: Rick Edgecombe Cc: Andrew Morton Cc: Oleg Nesterov Cc: linux-mm@kvack.org --- fs/aio.c | 2 +- include/linux/mm.h | 3 ++- ipc/shm.c | 2 +- mm/mmap.c | 10 +++++----- mm/nommu.c | 4 ++-- mm/util.c | 2 +- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 4ceba13a7db0..a24618e0e3fc 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -554,7 +554,7 @@ static int aio_setup_ring(struct kioctx *ctx, unsigned int nr_events) ctx->mmap_base = do_mmap(ctx->aio_ring_file, 0, ctx->mmap_size, PROT_READ | PROT_WRITE, - MAP_SHARED, 0, &unused, NULL); + MAP_SHARED, 0, 0, &unused, NULL); mmap_write_unlock(mm); if (IS_ERR((void *)ctx->mmap_base)) { ctx->mmap_size = 0; diff --git a/include/linux/mm.h b/include/linux/mm.h index e125358d7f75..481e1271409f 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2689,7 +2689,8 @@ extern unsigned long mmap_region(struct file *file, unsigned long addr, struct list_head *uf); extern unsigned long do_mmap(struct file *file, unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags, - unsigned long pgoff, unsigned long *populate, struct list_head *uf); + vm_flags_t vm_flags, unsigned long pgoff, unsigned long *populate, + struct list_head *uf); extern int __do_munmap(struct mm_struct *, unsigned long, size_t, struct list_head *uf, bool downgrade); extern int do_munmap(struct mm_struct *, unsigned long, size_t, diff --git a/ipc/shm.c b/ipc/shm.c index b3048ebd5c31..f236b3e14ec4 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -1646,7 +1646,7 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, goto invalid; } - addr = do_mmap(file, addr, size, prot, flags, 0, &populate, NULL); + addr = do_mmap(file, addr, size, prot, flags, 0, 0, &populate, NULL); *raddr = addr; err = 0; if (IS_ERR_VALUE(addr)) diff --git a/mm/mmap.c b/mm/mmap.c index 9bab326332af..9c82a1b02cfc 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1410,11 +1410,11 @@ static inline bool file_mmap_ok(struct file *file, struct inode *inode, */ unsigned long do_mmap(struct file *file, unsigned long addr, unsigned long len, unsigned long prot, - unsigned long flags, unsigned long pgoff, - unsigned long *populate, struct list_head *uf) + unsigned long flags, vm_flags_t vm_flags, + unsigned long pgoff, unsigned long *populate, + struct list_head *uf) { struct mm_struct *mm = current->mm; - vm_flags_t vm_flags; int pkey = 0; *populate = 0; @@ -1474,7 +1474,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr, * to. we assume access permissions have been handled by the open * of the memory object, so we don't do any here. */ - vm_flags = calc_vm_prot_bits(prot, pkey) | calc_vm_flag_bits(flags) | + vm_flags |= calc_vm_prot_bits(prot, pkey) | calc_vm_flag_bits(flags) | mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC; if (flags & MAP_LOCKED) @@ -3011,7 +3011,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, file = get_file(vma->vm_file); ret = do_mmap(vma->vm_file, start, size, - prot, flags, pgoff, &populate, NULL); + prot, flags, 0, pgoff, &populate, NULL); fput(file); out: mmap_write_unlock(mm); diff --git a/mm/nommu.c b/mm/nommu.c index 55a9e48a7a02..a6e0243cd69b 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -1057,6 +1057,7 @@ unsigned long do_mmap(struct file *file, unsigned long len, unsigned long prot, unsigned long flags, + vm_flags_t vm_flags, unsigned long pgoff, unsigned long *populate, struct list_head *uf) @@ -1064,7 +1065,6 @@ unsigned long do_mmap(struct file *file, struct vm_area_struct *vma; struct vm_region *region; struct rb_node *rb; - vm_flags_t vm_flags; unsigned long capabilities, result; int ret; @@ -1083,7 +1083,7 @@ unsigned long do_mmap(struct file *file, /* we've determined that we can make the mapping, now translate what we * now know into VMA flags */ - vm_flags = determine_vm_flags(file, prot, flags, capabilities); + vm_flags |= determine_vm_flags(file, prot, flags, capabilities); /* we're going to need to record the mapping */ region = kmem_cache_zalloc(vm_region_jar, GFP_KERNEL); diff --git a/mm/util.c b/mm/util.c index 7e43369064c8..d419821364cc 100644 --- a/mm/util.c +++ b/mm/util.c @@ -516,7 +516,7 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr, if (!ret) { if (mmap_write_lock_killable(mm)) return -EINTR; - ret = do_mmap(file, addr, len, prot, flag, pgoff, &populate, + ret = do_mmap(file, addr, len, prot, flag, 0, pgoff, &populate, &uf); mmap_write_unlock(mm); userfaultfd_unmap_complete(mm, &uf); -- 2.17.1