Skip to content

Commit

Permalink
[PATCH] _proc_do_string(): fix short reads
Browse files Browse the repository at this point in the history
If you try to read things like /proc/sys/kernel/osrelease with single-byte
reads, you get just one byte and then EOF.  This is because _proc_do_string()
assumes that the caller is read()ing into a buffer which is large enough to
fit the whole string in a single hit.

Fix.

Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Oleg Nesterov authored and Linus Torvalds committed Feb 11, 2007
1 parent c75fb88 commit 8d06087
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions kernel/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1686,13 +1686,12 @@ static int _proc_do_string(void* data, int maxlen, int write,
size_t len;
char __user *p;
char c;

if (!data || !maxlen || !*lenp ||
(*ppos && !write)) {

if (!data || !maxlen || !*lenp) {
*lenp = 0;
return 0;
}

if (write) {
len = 0;
p = buffer;
Expand All @@ -1713,6 +1712,15 @@ static int _proc_do_string(void* data, int maxlen, int write,
len = strlen(data);
if (len > maxlen)
len = maxlen;

if (*ppos > len) {
*lenp = 0;
return 0;
}

data += *ppos;
len -= *ppos;

if (len > *lenp)
len = *lenp;
if (len)
Expand Down

0 comments on commit 8d06087

Please sign in to comment.