Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1500020

[PATCH 09/10] mm: replace access_remote_vm() write parameter with gup_flags

From Lorenzo Stoakes <lstoakes@gmail.com>
Newsgroups linux.kernel
Subject [PATCH 09/10] mm: replace access_remote_vm() write parameter with gup_flags
Date 2016-10-13 06:10 +0200
Message-ID <srFvb-6Bm-5@gated-at.bofh.it> (permalink)
References <srC4h-3JZ-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


This patch removes the write parameter from access_remote_vm() and replaces it
with a gup_flags parameter as use of this function previously _implied_
FOLL_FORCE, whereas after this patch callers explicitly pass this flag.

We make this explicit as use of FOLL_FORCE can result in surprising behaviour
(and hence bugs) within the mm subsystem.

Signed-off-by: Lorenzo Stoakes <lstoakes@gmail.com>
---
 fs/proc/base.c     | 19 +++++++++++++------
 include/linux/mm.h |  2 +-
 mm/memory.c        | 11 +++--------
 mm/nommu.c         |  7 +++----
 4 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index c2964d8..8e65446 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -252,7 +252,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf,
 	 * Inherently racy -- command line shares address space
 	 * with code and data.
 	 */
-	rv = access_remote_vm(mm, arg_end - 1, &c, 1, 0);
+	rv = access_remote_vm(mm, arg_end - 1, &c, 1, FOLL_FORCE);
 	if (rv <= 0)
 		goto out_free_page;
 
@@ -270,7 +270,8 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf,
 			int nr_read;
 
 			_count = min3(count, len, PAGE_SIZE);
-			nr_read = access_remote_vm(mm, p, page, _count, 0);
+			nr_read = access_remote_vm(mm, p, page, _count,
+					FOLL_FORCE);
 			if (nr_read < 0)
 				rv = nr_read;
 			if (nr_read <= 0)
@@ -305,7 +306,8 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf,
 			bool final;
 
 			_count = min3(count, len, PAGE_SIZE);
-			nr_read = access_remote_vm(mm, p, page, _count, 0);
+			nr_read = access_remote_vm(mm, p, page, _count,
+					FOLL_FORCE);
 			if (nr_read < 0)
 				rv = nr_read;
 			if (nr_read <= 0)
@@ -354,7 +356,8 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf,
 			bool final;
 
 			_count = min3(count, len, PAGE_SIZE);
-			nr_read = access_remote_vm(mm, p, page, _count, 0);
+			nr_read = access_remote_vm(mm, p, page, _count,
+					FOLL_FORCE);
 			if (nr_read < 0)
 				rv = nr_read;
 			if (nr_read <= 0)
@@ -832,6 +835,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
 	unsigned long addr = *ppos;
 	ssize_t copied;
 	char *page;
+	unsigned int flags = FOLL_FORCE;
 
 	if (!mm)
 		return 0;
@@ -844,6 +848,9 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
 	if (!atomic_inc_not_zero(&mm->mm_users))
 		goto free;
 
+	if (write)
+		flags |= FOLL_WRITE;
+
 	while (count > 0) {
 		int this_len = min_t(int, count, PAGE_SIZE);
 
@@ -852,7 +859,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
 			break;
 		}
 
-		this_len = access_remote_vm(mm, addr, page, this_len, write);
+		this_len = access_remote_vm(mm, addr, page, this_len, flags);
 		if (!this_len) {
 			if (!copied)
 				copied = -EIO;
@@ -965,7 +972,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
 		this_len = min(max_len, this_len);
 
 		retval = access_remote_vm(mm, (env_start + src),
-			page, this_len, 0);
+			page, this_len, FOLL_FORCE);
 
 		if (retval <= 0) {
 			ret = retval;
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 2a481d3..3e5234e 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1268,7 +1268,7 @@ static inline int fixup_user_fault(struct task_struct *tsk,
 
 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
-		void *buf, int len, int write);
+		void *buf, int len, unsigned int gup_flags);
 
 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
 		      unsigned long start, unsigned long nr_pages,
diff --git a/mm/memory.c b/mm/memory.c
index 79ebed3..bac2d99 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3935,19 +3935,14 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
  * @addr:	start address to access
  * @buf:	source or destination buffer
  * @len:	number of bytes to transfer
- * @write:	whether the access is a write
+ * @gup_flags:	flags modifying lookup behaviour
  *
  * The caller must hold a reference on @mm.
  */
 int access_remote_vm(struct mm_struct *mm, unsigned long addr,
-		void *buf, int len, int write)
+		void *buf, int len, unsigned int gup_flags)
 {
-	unsigned int flags = FOLL_FORCE;
-
-	if (write)
-		flags |= FOLL_WRITE;
-
-	return __access_remote_vm(NULL, mm, addr, buf, len, flags);
+	return __access_remote_vm(NULL, mm, addr, buf, len, gup_flags);
 }
 
 /*
diff --git a/mm/nommu.c b/mm/nommu.c
index bde7df3..93d5bb5 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1847,15 +1847,14 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
  * @addr:	start address to access
  * @buf:	source or destination buffer
  * @len:	number of bytes to transfer
- * @write:	whether the access is a write
+ * @gup_flags:	flags modifying lookup behaviour
  *
  * The caller must hold a reference on @mm.
  */
 int access_remote_vm(struct mm_struct *mm, unsigned long addr,
-		void *buf, int len, int write)
+		void *buf, int len, unsigned int gup_flags)
 {
-	return __access_remote_vm(NULL, mm, addr, buf, len,
-			write ? FOLL_WRITE : 0);
+	return __access_remote_vm(NULL, mm, addr, buf, len, gup_flags);
 }
 
 /*
-- 
2.10.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/10] mm: adjust get_user_pages* functions to explicitly pass FOLL_* flags Lorenzo Stoakes <lstoakes@gmail.com> - 2016-10-13 02:30 +0200
  [PATCH 02/10] mm: remove write/force parameters from __get_user_pages_unlocked() Lorenzo Stoakes <lstoakes@gmail.com> - 2016-10-13 02:30 +0200
    Re: [PATCH 02/10] mm: remove write/force parameters from  __get_user_pages_unlocked() Paolo Bonzini <pbonzini@redhat.com> - 2016-10-13 09:00 +0200
    Re: [PATCH 02/10] mm: remove write/force parameters from  __get_user_pages_unlocked() Jan Kara <jack@suse.cz> - 2016-10-18 14:50 +0200
  [PATCH 03/10] mm: replace get_user_pages_unlocked() write/force parameters with gup_flags Lorenzo Stoakes <lstoakes@gmail.com> - 2016-10-13 02:30 +0200
    Re: [PATCH 03/10] mm: replace get_user_pages_unlocked() write/force  parameters with gup_flags Jan Kara <jack@suse.cz> - 2016-10-18 15:00 +0200
  [PATCH 07/10] mm: replace get_user_pages_remote() write/force parameters with gup_flags Lorenzo Stoakes <lstoakes@gmail.com> - 2016-10-13 05:00 +0200
    Re: [PATCH 07/10] mm: replace get_user_pages_remote() write/force  parameters with gup_flags Jan Kara <jack@suse.cz> - 2016-10-19 11:10 +0200
  [PATCH 09/10] mm: replace access_remote_vm() write parameter with gup_flags Lorenzo Stoakes <lstoakes@gmail.com> - 2016-10-13 06:10 +0200
  [PATCH 08/10] mm: replace __access_remote_vm() write parameter with gup_flags Lorenzo Stoakes <lstoakes@gmail.com> - 2016-10-13 06:20 +0200
    Re: [PATCH 08/10] mm: replace __access_remote_vm() write parameter  with gup_flags Michal Hocko <mhocko@kernel.org> - 2016-10-19 11:10 +0200
      Re: [PATCH 08/10] mm: replace __access_remote_vm() write parameter  with gup_flags Lorenzo Stoakes <lstoakes@gmail.com> - 2016-10-19 16:50 +0200
        Re: [PATCH 08/10] mm: replace __access_remote_vm() write parameter  with gup_flags Michal Hocko <mhocko@kernel.org> - 2016-10-19 18:10 +0200
    Re: [PATCH 08/10] mm: replace __access_remote_vm() write parameter  with gup_flags Lorenzo Stoakes <lstoakes@gmail.com> - 2016-10-19 16:30 +0200
    Re: [PATCH 08/10] mm: replace __access_remote_vm() write parameter  with gup_flags Jan Kara <jack@suse.cz> - 2016-10-19 16:50 +0200
      Re: [PATCH 08/10] mm: replace __access_remote_vm() write parameter  with gup_flags Michal Hocko <mhocko@kernel.org> - 2016-10-19 18:30 +0200
  [PATCH 05/10] mm: replace get_vaddr_frames() write/force parameters with gup_flags Lorenzo Stoakes <lstoakes@gmail.com> - 2016-10-13 06:20 +0200
    Re: [PATCH 05/10] mm: replace get_vaddr_frames() write/force  parameters with gup_flags Jan Kara <jack@suse.cz> - 2016-10-19 18:30 +0200
  [PATCH 10/10] mm: replace access_process_vm() write parameter with gup_flags Lorenzo Stoakes <lstoakes@gmail.com> - 2016-10-13 06:40 +0200
    Re: [PATCH 10/10] mm: replace access_process_vm() write parameter  with gup_flags Jesper Nilsson <jesper.nilsson@axis.com> - 2016-10-17 11:30 +0200
  [PATCH 06/10] mm: replace get_user_pages() write/force parameters with gup_flags Lorenzo Stoakes <lstoakes@gmail.com> - 2016-10-13 06:40 +0200
    Re: [PATCH 06/10] mm: replace get_user_pages() write/force  parameters with gup_flags Jesper Nilsson <jesper.nilsson@axis.com> - 2016-10-17 11:30 +0200
    Re: [PATCH 06/10] mm: replace get_user_pages() write/force  parameters with gup_flags Jan Kara <jack@suse.cz> - 2016-10-19 11:10 +0200
  [PATCH 04/10] mm: replace get_user_pages_locked() write/force parameters with gup_flags Lorenzo Stoakes <lstoakes@gmail.com> - 2016-10-13 08:10 +0200
    Re: [PATCH 04/10] mm: replace get_user_pages_locked() write/force  parameters with gup_flags Jan Kara <jack@suse.cz> - 2016-10-18 15:00 +0200
      Re: [PATCH 04/10] mm: replace get_user_pages_locked() write/force  parameters with gup_flags Lorenzo Stoakes <lstoakes@gmail.com> - 2016-10-18 16:00 +0200
        Re: [PATCH 04/10] mm: replace get_user_pages_locked() write/force  parameters with gup_flags Jan Kara <jack@suse.cz> - 2016-10-19 09:40 +0200
    Re: [PATCH 04/10] mm: replace get_user_pages_locked() write/force  parameters with gup_flags Jan Kara <jack@suse.cz> - 2016-10-19 17:30 +0200
  Re: [PATCH 00/10] mm: adjust get_user_pages* functions to explicitly  pass FOLL_* flags Michal Hocko <mhocko@kernel.org> - 2016-10-18 17:40 +0200
    Re: [PATCH 00/10] mm: adjust get_user_pages* functions to explicitly  pass FOLL_* flags Michal Hocko <mhocko@kernel.org> - 2016-10-19 16:20 +0200
      Re: [PATCH 00/10] mm: adjust get_user_pages* functions to explicitly  pass FOLL_* flags Dave Hansen <dave.hansen@linux.intel.com> - 2016-10-19 19:00 +0200
        Re: [PATCH 00/10] mm: adjust get_user_pages* functions to explicitly  pass FOLL_* flags Michal Hocko <mhocko@kernel.org> - 2016-10-19 19:10 +0200
          Re: [PATCH 00/10] mm: adjust get_user_pages* functions to explicitly  pass FOLL_* flags Dave Hansen <dave.hansen@linux.intel.com> - 2016-10-19 19:30 +0200
            Re: [PATCH 00/10] mm: adjust get_user_pages* functions to explicitly  pass FOLL_* flags Michal Hocko <mhocko@kernel.org> - 2016-10-20 21:30 +0200
    Re: [PATCH 00/10] mm: adjust get_user_pages* functions to explicitly  pass FOLL_* flags Lorenzo Stoakes <lstoakes@gmail.com> - 2016-10-19 18:20 +0200
    Re: [PATCH 00/10] mm: adjust get_user_pages* functions to explicitly  pass FOLL_* flags Lorenzo Stoakes <lstoakes@gmail.com> - 2016-10-26 11:00 +0200

csiph-web