From patchwork Wed Jul 19 22:47:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 122918 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2772095vqt; Wed, 19 Jul 2023 16:29:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlEYqwSlIRrWqdinY34FBILGkBD4xWOdSiYOaDCM/eNZTBCUlp3TOKR/NkCv3xbwYUBDEbNV X-Received: by 2002:a17:906:2219:b0:993:f9d4:eaac with SMTP id s25-20020a170906221900b00993f9d4eaacmr602729ejs.24.1689809366460; Wed, 19 Jul 2023 16:29:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689809366; cv=none; d=google.com; s=arc-20160816; b=BJM4EE3BWnPSLMx8bXvPS+rq1JCglxMqOBe9sSVPeiR++QPZwMs0Jp5vwcRRBs3LCL c9N7ylsg94j5nJJu3KBNzE0eTCSLBfzB5cF/9dlYiGqfd7mpNrX9t4gZK7TtWoFmIvhl rjfyz6w3CSREJ/Eycb1FVPPjoNho7pb1bHIrvOUnkTZTu1XRHuYxvNRkf+6F8hwTgNf7 GWzMpksLmbaT+6Znhruf5c6uAbkC90EQccZA/ZnDBRNtonnUVajJpa+OjzwT5Pf1UdP6 s6zAW4Rcfd8Z2uckwtGSH/BcSolW9ca25gOX52Z19jvzxVJxmcpaAlTAM5YYgbIdKlJc dQBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=CPdu7/bMDcFal7nJQRHJvJoovbdFmKduQyX9dhjdvyM=; fh=ZR4pEuy69rgh5364BKBFaXZRW8HRoV9lb/1dfyOEOyI=; b=YjTs39ofwwHjrHfAQpyzN9FLbHfVoDSj4o6GTjtRBCq/D0pTaj0AwJyuyOBRJu8avd 1ADTnAqMfNIiWeZua3ec4bRBL0HyvmLdD4v0Sao3g8pFJrD3FLTNTl01XuLckqa5Cx// o8oUwZdrMsilxcWUeS+CgHlG6RcNNNQqfOepN+PkwaHk4JDPeHqq+Hvgv33rmJLt/ryW GaeeIjJtby+WRpyAu5FXMIpTUkO+YigDXxCxnaUYMqE5KlV8mouXQzW5pV4OEBnz7mrl ARHtK0r5yX61u33lRrjlqb79TU6aSwGjm72KRvrP2qASG1Go5t05oivN/TdCjUt4XuO5 298w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Z23zETA2; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z10-20020a1709063aca00b00991f5659833si3558575ejd.152.2023.07.19.16.29.03; Wed, 19 Jul 2023 16:29:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Z23zETA2; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231426AbjGSWt5 (ORCPT + 99 others); Wed, 19 Jul 2023 18:49:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231320AbjGSWr5 (ORCPT ); Wed, 19 Jul 2023 18:47:57 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46DB22100; Wed, 19 Jul 2023 15:47:45 -0700 (PDT) Date: Wed, 19 Jul 2023 22:47:42 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1689806863; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=CPdu7/bMDcFal7nJQRHJvJoovbdFmKduQyX9dhjdvyM=; b=Z23zETA2vq1oEY9zD+HgjIvqq15Xy6L0Q88+4bGgRCTaRDzEXSKXqdJ0s0mbM3xqGwDv4s XMp/fBPmlQGuYfL+hzcS/0A2mrLHhpwqiJjlPZiV35INWxaC/ujfxBnkkD9Q6il5RkXpdj QK1V3vobvCMH7mFKzp0VGUG/kiYYMFg7EoipoCeaGVSNZnANU7VhiLKTqJPrmHhRtkX7h6 RZ9QKcEjLzk864+Ma7C0d/0KF+ufV1Fd2SczO/mf94q7gnw4ex9pCDMIwp0L5H29mQDwCu MSdG7CNtbtwvdQTsXjNaMRXHwRCUbfHWq6KXntRKY4dqI9K6h41PLk+fGb5wtQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1689806863; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=CPdu7/bMDcFal7nJQRHJvJoovbdFmKduQyX9dhjdvyM=; b=ZkzZmretZCVLnDTYwWWm6UxPFuNo+o8QvZHLtcw8x7lqNhcl/X4DG5opi+0k3CS3WiJTj4 V2EJAI8Hd9u0kRBA== From: "tip-bot2 for Yu-cheng Yu" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/shstk] mm: Re-introduce vm_flags to do_mmap() Cc: "Yu-cheng Yu" , Rick Edgecombe , Dave Hansen , "Borislav Petkov (AMD)" , Peter Collingbourne , Kees Cook , "Kirill A. Shutemov" , Mark Brown , "Mike Rapoport (IBM)" , David Hildenbrand , Pengfei Xu , John Allen , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <168980686257.28540.10813286743933877729.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771893545999932840 X-GMAIL-MSGID: 1771893545999932840 The following commit has been merged into the x86/shstk branch of tip: Commit-ID: 592b5fad1677aa98a578ae50eb81d7383752c9c8 Gitweb: https://git.kernel.org/tip/592b5fad1677aa98a578ae50eb81d7383752c9c8 Author: Yu-cheng Yu AuthorDate: Mon, 12 Jun 2023 17:10:30 -07:00 Committer: Rick Edgecombe CommitterDate: Tue, 11 Jul 2023 14:12:18 -07:00 mm: Re-introduce vm_flags to do_mmap() 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(). Co-developed-by: Rick Edgecombe Signed-off-by: Yu-cheng Yu Signed-off-by: Rick Edgecombe Signed-off-by: Dave Hansen Reviewed-by: Borislav Petkov (AMD) Reviewed-by: Peter Collingbourne Reviewed-by: Kees Cook Reviewed-by: Kirill A. Shutemov Reviewed-by: Mark Brown Acked-by: Mike Rapoport (IBM) Acked-by: David Hildenbrand Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook Tested-by: Mark Brown Link: https://lore.kernel.org/all/20230613001108.3040476-5-rick.p.edgecombe%40intel.com --- 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 77e3361..c7c8918 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 d40fa0f..f9a627c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3176,7 +3176,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 unlock); diff --git a/ipc/shm.c b/ipc/shm.c index 60e45e7..576a543 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 3eda23c..4900f74 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1189,11 +1189,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); @@ -1254,7 +1254,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) @@ -2995,7 +2995,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 c072a66..fe19614 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -1015,6 +1015,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) @@ -1022,7 +1023,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); @@ -1042,7 +1042,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 dd12b95..8e7fc6c 100644 --- a/mm/util.c +++ b/mm/util.c @@ -540,7 +540,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);