From patchwork Mon Feb 27 22:29:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 13154255 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F36E5C7EE3A for ; Mon, 27 Feb 2023 22:32:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C41E16B009A; Mon, 27 Feb 2023 17:31:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B2A616B009C; Mon, 27 Feb 2023 17:31:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A3A06B009D; Mon, 27 Feb 2023 17:31:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 87B3F6B009A for ; Mon, 27 Feb 2023 17:31:52 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5DA0D40A1C for ; Mon, 27 Feb 2023 22:31:52 +0000 (UTC) X-FDA: 80514520464.25.441FF0C Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by imf28.hostedemail.com (Postfix) with ESMTP id 5E60DC000F for ; Mon, 27 Feb 2023 22:31:49 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=lheS49sH; spf=pass (imf28.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677537109; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=qAyyzHuhpB1+Uby4j0qT9fRmrng7fTbHGa4BAOyou28=; b=Tvpya5zHVN4FDSs4ew+zIYJC6eEjz8ufT33O0sMrHI/476prI1/SFllbZ0nnGCCk62usD9 92leXaLPi20QkmAF9U4Ge4g5pertzG6zb12uxXTnV77lHF2J8Nyktp7XFjsM/gVwpH3otR xJdLdv9K1H+pC5iDRz/yQji8bjeNHKs= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=lheS49sH; spf=pass (imf28.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677537109; a=rsa-sha256; cv=none; b=uf000lPmDjjhX1hdrilfP21Q52XHSOgEtK3yQzQQFMBuOCUAW1gB2BA1cLIAGGJWW0xdr6 cyHsA6VLA/Mhaf7f+qX0Z672JF8z+Liie3yCQYkSU7MAFcNE6dSQlBpNYQ1sjtfF7ecTQG a4wiyZ5JW6O75jzIBnCz44oqwpTPcHA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677537109; x=1709073109; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Wm5/KWrYYFgliIdaotUWNuGKUFxakUNYXMA7lYNP4nA=; b=lheS49sH3AyRf9AuP3pfgUdYLqTbaz4sXIROrYKAae282h3/AeXEEkry 7gz3FI/9ovSQQ3+aVKLDPs3y9UtEb1GsDU2zBMtUe1sqRo9tHBskzRb2F xW5C0to/dWAmaB3eAH+84L9Z5xYxkYtvIP6V8IYoP4/ZeLGFvMOMBmJBC WO4kSekasHl8IpRLkylNH8t3CmqpFBLWXKRXA/sJFtm9mTI1PXiIns871 H4QE1NpsgYDWYry637M7sCXI+UzxOXt9JMhyCI2Y0YP6LM1O0bIEDZYR2 SlnIuHen0Su1ELI9tdpvQ38RPz4wFzJHO0FYZBX2VVdaa5B1QjcZl7WD2 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="313657531" X-IronPort-AV: E=Sophos;i="5.98,220,1673942400"; d="scan'208";a="313657531" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 14:31:25 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="848024644" X-IronPort-AV: E=Sophos;i="5.98,220,1673942400"; d="scan'208";a="848024644" Received: from leonqu-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.72.19]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 14:31:24 -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 , Weijiang Yang , "Kirill A . Shutemov" , John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com, david@redhat.com, debug@rivosinc.com Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu Subject: [PATCH v7 23/41] mm: Re-introduce vm_flags to do_mmap() Date: Mon, 27 Feb 2023 14:29:39 -0800 Message-Id: <20230227222957.24501-24-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230227222957.24501-1-rick.p.edgecombe@intel.com> References: <20230227222957.24501-1-rick.p.edgecombe@intel.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 5E60DC000F X-Stat-Signature: 9ibs59eydxajmmk57qpxqpcanbkep1tw X-Rspam-User: X-HE-Tag: 1677537109-820704 X-HE-Meta: U2FsdGVkX1+Aovv8Hf6tu6iVBJUFSlSYWxWDes4wZJrqdkGkqtIo9dNntfQGpONEIyE5TOCqVblaeknmD5cUDTelyHrTk58l4HN0Nt3JO0LFIsE7XLTFicPyA5w4yXTmD9uV7bn5pn0xFrE47OspHa4xHWijvwJSX/MxE/C8BmUK0oh4S/BsdLTSmq7j4CnE3nl5yRbNv2tNFCqGnFGma4E9G7xyJZ1fflRzohcWwB10e17gdnD2WyGL1RNuTgLdiUChLfSUkHtXRWFMxM0RN4CP37z30/hrghzmF09djKAojrfcjYSkDO3meWcJWDzPztjyOqBV01SxuOgeFmJgxkfpSNxQenDDDUJfzcdHEUXYQpWew6WvGcMdnKczaogJlOfVEPyuOc2QhWjO0VhrQhDhWhwZbd0piH0nA6KA0RmBvsgvRNUixOoxMYFEgyAoUY/IM5a3YM7yps5Y0pMSDU2iZGbT0pJY49y4sZS4JW6YGlXX1D8WR+My+hEVUpYgmKKgkcmSUoMes453BbxuvfwRM/IV8QbqJMICexGqbN8atiNy4699IuB4t+GkYoR9aDvVLU+5sS07sL1FuSekNuTCcpbpYvMAXOHzFwwRI127TWy7W2qbsLIN0woccrRsWPKIK21TAlXJjIlWNUMCAijGSbB1jbU7qAuHgZXJcW6ED/zIs9ghvjno+VOiNhKM7tgQbay7qH27o4LAlDFoKlUDpD442TyKPSfxygyEYNyMI6ARG3oFO8y0pnGlaCq57N71H5icu14qJnStizI+4VR36n5F7Jcyr/oQEIPKI0GFLru1Ncc0+w1EDZPYRXm24g5452SytLeYgfosuFRxgUDUG4D9i5on5644qgWC8GjmiZcE1Kw0E30HwmkzVqGHiCsJ71OKalPQvcnxCZX7kTX8EtmmRUPUNM6C6VN9pqGEVHZz+SiRrwETLtckaHO2Lzsqc9vizIL6+IBecRY 3M1CnxyK TZ1oUqdI42c2GxG1OW2sHFZ7n16z22Evw7je1YnDfWWJVyAAlIFrmxqOCO2JDtbxDr+qHXsuSLu7irkPVnDtLvKmZAco1e+RsUDWYPXQd5ZF1RzyrzV2rinVPOSpMZt15/bWomOFVDtRIrBBd1e+kMtaraCOrmq2MwN/De1PktNOWg0Q9oP006hY4d4pF3XS7cuXR8JG1+u2YdmSnEWElR3hl8vS1XZ3D9/GqRXiDrzhs5l3s56jgEHyHdrcao/utkMpi0zD4ADfywsEpSOFIjOUd7cbfe4fXuqwo9ebhPBsvXrv472LP+rJ6uMuDOgCB4WmWsGxEHs2EeqJGGMfzIdw/ld1VguOrOr7h5u9tjnfFb+2harESXT9x3w6qh3Dk9Hgrgqbap8EukKCaMEXzyUta8AID4rYD2ecp9vQQPKgTJElKDjOCArxbp9xqDmDWm2bKOPgMpnwJSHopvRQtZLy5lMoQi6Dtm7LgkIPxa4p16BReP9hQTgMjytmz1iClu8DldS7AbDT+XTnoy3mRUwmH+sOXfUF/ERg50JkSc7Sjlqx06GN2LXJ9cw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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(). Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook Acked-by: Mike Rapoport (IBM) Reviewed-by: Peter Collingbourne Reviewed-by: Kees Cook Reviewed-by: Kirill A. Shutemov Signed-off-by: Yu-cheng Yu 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 b0b17bd098bb..4a7576989719 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -558,7 +558,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 6a093daced88..87e46a9e0e93 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3014,7 +3014,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_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm, unsigned long start, size_t len, struct list_head *uf, bool downgrade); diff --git a/ipc/shm.c b/ipc/shm.c index 60e45e7045d4..576a543b7cff 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -1662,7 +1662,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 20f21f0949dd..eedae44dfc78 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1191,11 +1191,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; validate_mm(mm); @@ -1256,7 +1256,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) @@ -2829,7 +2829,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 57ba243c6a37..f6ddd084671f 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -1002,6 +1002,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) @@ -1009,7 +1010,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; VMA_ITERATOR(vmi, current->mm, 0); @@ -1029,7 +1029,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 */ diff --git a/mm/util.c b/mm/util.c index b8ed9dbc7fd5..a93e832f4065 100644 --- a/mm/util.c +++ b/mm/util.c @@ -539,7 +539,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);