[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1397780183-24633-3-git-send-email-keescook@chromium.org>
Date: Thu, 17 Apr 2014 17:16:21 -0700
From: Kees Cook <keescook@...omium.org>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: linux-kernel@...r.kernel.org, Kees Cook <keescook@...omium.org>,
David Howells <dhowells@...hat.com>,
Randy Dunlap <rdunlap@...radead.org>,
Ingo Molnar <mingo@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Rik van Riel <riel@...hat.com>, Mel Gorman <mgorman@...e.de>,
Li Zefan <lizefan@...wei.com>,
Dave Hansen <dave@...ux.vnet.ibm.com>,
Aaron Tomlin <atomlin@...hat.com>,
Dario Faggioli <raistlin@...ux.it>,
Andrew Shewmaker <agshew@...il.com>,
Andi Kleen <ak@...ux.intel.com>, Jens Axboe <axboe@...com>,
Wanpeng Li <liwanp@...ux.vnet.ibm.com>,
Benjamin Herrenschmidt <benh@...nel.crashing.org>,
Frederic Weisbecker <fweisbec@...il.com>,
Pavel Emelyanov <xemul@...allels.com>,
Andrey Vagin <avagin@...nvz.org>,
Michael Ellerman <michael@...erman.id.au>
Subject: [PATCH v2 2/4] sysctl: refactor sysctl string writing logic
Consolidate buffer length checking with new-line/end-of-line checking.
Additionally, instead of reading user memory twice, just do the assignment
during the loop.
Signed-off-by: Kees Cook <keescook@...omium.org>
---
kernel/sysctl.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index e7ff80a73c44..0e08103a69c8 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1712,21 +1712,18 @@ static int _proc_do_string(char *data, int maxlen, int write,
}
if (write) {
+ /* Start writing from beginning of buffer. */
len = 0;
+ *ppos += *lenp;
p = buffer;
- while (len < *lenp) {
+ while ((p - buffer) < *lenp && len < maxlen - 1) {
if (get_user(c, p++))
return -EFAULT;
if (c == 0 || c == '\n')
break;
- len++;
+ data[len++] = c;
}
- if (len >= maxlen)
- len = maxlen-1;
- if(copy_from_user(data, buffer, len))
- return -EFAULT;
data[len] = 0;
- *ppos += *lenp;
} else {
len = strlen(data);
if (len > maxlen)
--
1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists