From: Oleg Nesterov <oleg@tv-sign.ru>
To: Andrew Morton <akpm@osdl.org>
Cc: Michael Tokarev <mjt@tls.msk.ru>,
Kernel Mailing List <linux-kernel@vger.kernel.org>,
"Eric W. Biederman" <ebiederm@xmission.com>
Subject: Re: bug reading /proc/sys/kernel/*: only first byte read.
Date: Tue, 30 Jan 2007 16:25:59 +0300 [thread overview]
Message-ID: <20070130132559.GA315@tv-sign.ru> (raw)
In-Reply-To: <20070130022457.d0159eba.akpm@osdl.org>
On 01/30, Andrew Morton wrote:
>
> @@ -1705,18 +1704,38 @@ static int _proc_do_string(void* data, i
> ((char *) data)[len] = 0;
> *ppos += *lenp;
> } else {
> - len = strlen(data);
> + loff_t pos = *ppos;
> + const size_t slen = strlen(data);
> +
> + /*
> + * len is the amount of data to copy, and becomes the amount of
> + * data which was copied
> + */
> + len = slen;
> + if (pos > len) {
> + *lenp = 0;
> + return 0;
> + }
> if (len > maxlen)
> len = maxlen;
> if (len > *lenp)
> len = *lenp;
> - if (len)
> - if(copy_to_user(buffer, data, len))
> - return -EFAULT;
> - if (len < *lenp) {
> - if(put_user('\n', ((char __user *) buffer) + len))
> + /* Don't copy past the end of the string */
> + if (len > slen - pos)
> + len = slen - pos;
> + data += pos;
> + /* Copy as much of the string as we can */
> + if (len) {
> + if (copy_to_user(buffer, data, len))
> return -EFAULT;
> - len++;
> + }
> + /* If we copied the whole string, now write a \n */
> + if (len + pos == slen) {
> + if (len + pos < maxlen) {
^^^^^^^^^^^^^^^^^^^^^^^
Shouldn't this be
if (len < *lenp)
?
> + if (put_user('\n', (char __user *)buffer + len))
> + return -EFAULT;
> + len++;
> + }
> }
> *lenp = len;
> *ppos += len;
next prev parent reply other threads:[~2007-01-30 13:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-20 12:43 Michael Tokarev
2007-01-30 10:24 ` Andrew Morton
2007-01-30 13:25 ` Oleg Nesterov [this message]
2007-01-30 14:00 ` Oleg Nesterov
2007-01-30 15:07 ` Eric W. Biederman
2007-01-30 15:57 ` Michael Tokarev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070130132559.GA315@tv-sign.ru \
--to=oleg@tv-sign.ru \
--cc=akpm@osdl.org \
--cc=ebiederm@xmission.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mjt@tls.msk.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®