+ proc-simpler-iterations-for-proc-cmdline.patch added to -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled
     Subject: proc: simpler iterations for /proc/*/cmdline
has been added to the -mm tree.  Its filename is
     proc-simpler-iterations-for-proc-cmdline.patch

This patch should soon appear at
    http://ozlabs.org/~akpm/mmots/broken-out/proc-simpler-iterations-for-proc-cmdline.patch
and later at
    http://ozlabs.org/~akpm/mmotm/broken-out/proc-simpler-iterations-for-proc-cmdline.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Alexey Dobriyan <adobriyan@xxxxxxxxx>
Subject: proc: simpler iterations for /proc/*/cmdline

"rv" variable is used both as a counter of bytes transferred and an error
value holder but it can be reduced solely to error values if original
start of userspace buffer is stashed and used at the very end.

Link: http://lkml.kernel.org/r/20180221193009.GA28678@avx2
Signed-off-by: Alexey Dobriyan <adobriyan@xxxxxxxxx>
Reviewed-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Andy Shevchenko <andy.shevchenko@xxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

 fs/proc/base.c |   36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff -puN fs/proc/base.c~proc-simpler-iterations-for-proc-cmdline fs/proc/base.c
--- a/fs/proc/base.c~proc-simpler-iterations-for-proc-cmdline
+++ a/fs/proc/base.c
@@ -238,8 +238,9 @@ static ssize_t proc_pid_cmdline_read(str
 	unsigned long arg_start, arg_end, env_start, env_end;
 	unsigned long len1, len2, len;
 	unsigned long p;
+	char __user *buf0 = buf;
 	char c;
-	ssize_t rv;
+	int rv;
 
 	BUG_ON(*pos < 0);
 
@@ -269,25 +270,20 @@ static ssize_t proc_pid_cmdline_read(str
 	len2 = env_end - env_start;
 
 	/* Empty ARGV. */
-	if (len1 == 0) {
-		rv = 0;
-		goto out_free_page;
-	}
+	if (len1 == 0)
+		goto end;
+
 	/*
 	 * Inherently racy -- command line shares address space
 	 * with code and data.
 	 */
-	if (access_remote_vm(mm, arg_end - 1, &c, 1, 0) != 1) {
-		rv = 0;
-		goto out_free_page;
-	}
-
-	rv = 0;
+	if (access_remote_vm(mm, arg_end - 1, &c, 1, 0) != 1)
+		goto end;
 
 	if (c == '\0') {
 		/* Command line (set of strings) occupies whole ARGV. */
 		if (len1 <= *pos)
-			goto out_free_page;
+			goto end;
 
 		p = arg_start + *pos;
 		len = len1 - *pos;
@@ -297,7 +293,7 @@ static ssize_t proc_pid_cmdline_read(str
 			nr_read = min3(count, len, PAGE_SIZE);
 			nr_read = access_remote_vm(mm, p, page, nr_read, 0);
 			if (nr_read == 0)
-				goto out_free_page;
+				goto end;
 
 			if (copy_to_user(buf, page, nr_read)) {
 				rv = -EFAULT;
@@ -308,7 +304,6 @@ static ssize_t proc_pid_cmdline_read(str
 			len	-= nr_read;
 			buf	+= nr_read;
 			count	-= nr_read;
-			rv	+= nr_read;
 		}
 	} else {
 		/*
@@ -339,7 +334,7 @@ static ssize_t proc_pid_cmdline_read(str
 				nr_read = min3(count, len, PAGE_SIZE);
 				nr_read = access_remote_vm(mm, p, page, nr_read, 0);
 				if (nr_read == 0)
-					goto out_free_page;
+					goto end;
 
 				/*
 				 * Command line can be shorter than whole ARGV
@@ -356,10 +351,9 @@ static ssize_t proc_pid_cmdline_read(str
 				len	-= nr_write;
 				buf	+= nr_write;
 				count	-= nr_write;
-				rv	+= nr_write;
 
 				if (nr_write < nr_read)
-					goto out_free_page;
+					goto end;
 			}
 
 			/* Only first chunk can be read partially. */
@@ -368,12 +362,16 @@ static ssize_t proc_pid_cmdline_read(str
 		}
 	}
 
+end:
+	free_page((unsigned long)page);
+	mmput(mm);
+	*pos += buf - buf0;
+	return buf - buf0;
+
 out_free_page:
 	free_page((unsigned long)page);
 out_mmput:
 	mmput(mm);
-	if (rv > 0)
-		*pos += rv;
 	return rv;
 }
 
_

Patches currently in -mm which might be from adobriyan@xxxxxxxxx are

proc-revalidate-kernel-thread-inodes-to-root-root.patch
proc-fix-proc-loadavg-regression.patch
proc-make-proc-cmdline-go-through-lsm.patch
proc-more-unsigned-int-in-proc-cmdline.patch
proc-somewhat-simpler-code-for-proc-cmdline.patch
proc-simpler-iterations-for-proc-cmdline.patch
proc-deduplicate-proc-cmdline-implementation.patch
coredump-fix-spam-with-zero-vma-process.patch
seq_file-delete-small-value-optimization.patch

--
To unsubscribe from this list: send the line "unsubscribe mm-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux