From: Chris Wright <chrisw@sous-sol.org>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Chris Wright <chrisw@sous-sol.org>,
linux-kernel@vger.kernel.org, stable@kernel.org,
git-commits-head@vger.kernel.org,
Justin Forbes <jmforbes@linuxtx.org>,
Zwane Mwaikambo <zwane@arm.linux.org.uk>,
"Theodore Ts'o" <tytso@mit.edu>,
Randy Dunlap <rdunlap@xenotime.net>,
Dave Jones <davej@redhat.com>,
Chuck Wolber <chuckw@quantumlinux.com>,
akpm@osdl.org, alan@lxorguk.ukuu.org.uk,
Greg Kroah-Hartman <gregkh@suse.de>
Subject: Re: [PATCH 4/6] sysctl: dont overflow the user-supplied buffer with 0
Date: Thu, 5 Jan 2006 19:40:11 -0800 [thread overview]
Message-ID: <20060106034011.GS3335@sorel.sous-sol.org> (raw)
In-Reply-To: <Pine.LNX.4.64.0601051727070.3169@g5.osdl.org>
* Linus Torvalds (torvalds@osdl.org) wrote:
> Don't use this one. It doesn't zero-pad the string if the result buffer is
> too small (which _could_ cause problems) and it actually returns the wrong
> length too.
>
> There's a better one in the final 2.6.15.
Thanks, adding this (it's got both rolled together so it's the same as
upstream).
thanks,
-chris
--
Subject: sysctl: make sure to terminate strings with a NUL
From: Linus Torvalds <torvalds@osdl.org>
This is a slightly more complete fix for the previous minimal sysctl
string fix. It always terminates the returned string with a NUL, even
if the full result wouldn't fit in the user-supplied buffer.
The returned length is the full untruncated length, so that you can
tell when truncation has occurred.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
[chrisw: inclusive of minimal fix so it's same as upstream]
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
---
kernel/sysctl.c | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
--- linux-2.6.14.5.orig/kernel/sysctl.c
+++ linux-2.6.14.5/kernel/sysctl.c
@@ -2191,29 +2191,32 @@ int sysctl_string(ctl_table *table, int
void __user *oldval, size_t __user *oldlenp,
void __user *newval, size_t newlen, void **context)
{
- size_t l, len;
-
if (!table->data || !table->maxlen)
return -ENOTDIR;
if (oldval && oldlenp) {
- if (get_user(len, oldlenp))
+ size_t bufsize;
+ if (get_user(bufsize, oldlenp))
return -EFAULT;
- if (len) {
- l = strlen(table->data);
- if (len > l) len = l;
- if (len >= table->maxlen)
+ if (bufsize) {
+ size_t len = strlen(table->data), copied;
+
+ /* This shouldn't trigger for a well-formed sysctl */
+ if (len > table->maxlen)
len = table->maxlen;
- if(copy_to_user(oldval, table->data, len))
- return -EFAULT;
- if(put_user(0, ((char __user *) oldval) + len))
+
+ /* Copy up to a max of bufsize-1 bytes of the string */
+ copied = (len >= bufsize) ? bufsize - 1 : len;
+
+ if (copy_to_user(oldval, table->data, copied) ||
+ put_user(0, (char __user *)(oldval + copied)))
return -EFAULT;
- if(put_user(len, oldlenp))
+ if (put_user(len, oldlenp))
return -EFAULT;
}
}
if (newval && newlen) {
- len = newlen;
+ size_t len = newlen;
if (len > table->maxlen)
len = table->maxlen;
if(copy_from_user(table->data, newval, len))
@@ -2222,7 +2225,7 @@ int sysctl_string(ctl_table *table, int
len--;
((char *) table->data)[len] = 0;
}
- return 0;
+ return 1;
}
/*
next prev parent reply other threads:[~2006-01-06 3:38 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20060105235845.967478000@sorel.sous-sol.org>
2006-01-05 21:47 ` [PATCH 0/6] -stable review Chris Wright
2006-01-06 0:45 ` [PATCH 1/6] drivers/net/sungem.c: gem_remove_one mustnt be __devexit Chris Wright
2006-01-06 0:45 ` [PATCH 2/6] ieee80211_crypt_tkip depends on NET_RADIO Chris Wright
2006-01-06 0:45 ` [PATCH 3/6] Insanity avoidance in /proc (CVE-2005-4605) Chris Wright
2006-01-06 0:45 ` [PATCH 4/6] sysctl: dont overflow the user-supplied buffer with 0 Chris Wright
2006-01-06 1:30 ` Linus Torvalds
2006-01-06 3:40 ` Chris Wright [this message]
2006-01-06 10:17 ` [PATCH, RFC] RCU : OOM avoidance and lower latency Eric Dumazet
2006-01-06 12:52 ` [PATCH, RFC] RCU : OOM avoidance and lower latency (Version 2), HOTPLUG_CPU fix Eric Dumazet
2006-01-06 12:58 ` [PATCH, RFC] RCU : OOM avoidance and lower latency Andi Kleen
2006-01-06 13:09 ` Eric Dumazet
2006-01-06 19:26 ` Lee Revell
2006-01-06 22:18 ` Andi Kleen
2006-01-06 13:37 ` Alan Cox
2006-01-06 14:00 ` Eric Dumazet
2006-01-06 14:45 ` Alan Cox
2006-01-06 16:47 ` Paul E. McKenney
2006-01-06 17:19 ` Eric Dumazet
2006-01-06 20:26 ` Paul E. McKenney
2006-01-06 20:33 ` David S. Miller
2006-01-06 20:57 ` Andi Kleen
2006-01-07 0:17 ` David S. Miller
2006-01-07 1:09 ` Andi Kleen
2006-01-07 7:10 ` David S. Miller
2006-01-07 7:34 ` Eric Dumazet
2006-01-07 7:44 ` David S. Miller
2006-01-07 7:53 ` Eric Dumazet
2006-01-07 8:36 ` David S. Miller
2006-01-07 20:30 ` Paul E. McKenney
2006-01-07 8:30 ` Eric Dumazet
2006-01-06 19:24 ` Lee Revell
2006-01-06 0:46 ` [PATCH 5/6] UFS: inode->i_sem is not released in error path Chris Wright
2006-01-06 0:46 ` [PATCH 6/6] [ATYFB]: Fix onboard video on SPARC Blade 100 for 2.6.{13,14,15} Chris Wright
2006-01-06 0:53 ` [PATCH 0/6] -stable review Chris Wright
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=20060106034011.GS3335@sorel.sous-sol.org \
--to=chrisw@sous-sol.org \
--cc=akpm@osdl.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=chuckw@quantumlinux.com \
--cc=davej@redhat.com \
--cc=git-commits-head@vger.kernel.org \
--cc=gregkh@suse.de \
--cc=jmforbes@linuxtx.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rdunlap@xenotime.net \
--cc=stable@kernel.org \
--cc=torvalds@osdl.org \
--cc=tytso@mit.edu \
--cc=zwane@arm.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).