Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8d060877 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds
Browse files

[PATCH] _proc_do_string(): fix short reads



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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent c75fb88d
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -1687,8 +1687,7 @@ static int _proc_do_string(void* data, int maxlen, int write,
	char __user *p;
	char c;

	if (!data || !maxlen || !*lenp ||
	    (*ppos && !write)) {
	if (!data || !maxlen || !*lenp) {
		*lenp = 0;
		return 0;
	}
@@ -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)