mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Jiri Kosina <jkosina@suse.cz>
Cc: Michael Gilbert <michael.s.gilbert@gmail.com>,
	Michael Buesch <mb@bu3sch.de>, Jack Steiner <steiner@sgi.com>,
	linux-kernel@vger.kernel.org, stable@kernel.org
Subject: Re: CVE-2009-2584
Date: Thu, 5 Nov 2009 08:32:35 -0800 (PST)	[thread overview]
Message-ID: <alpine.LFD.2.01.0911050831330.31845@localhost.localdomain> (raw)
In-Reply-To: <alpine.LRH.2.00.0911051620510.31913@twin.jikos.cz>


On Thu, 5 Nov 2009, Jiri Kosina wrote:
>  
> +	memset(buf, 0, sizeof(buf));
>  	if (strncpy_from_user(buf, userbuf, sizeof(buf) - 1) < 0)
>  		return -EFAULT;
> -	buf[count - 1] = '\0';

Why isn't this just

	buf[sizeof(buf) - 1] = 0;

which was almost certainly the _intention_ of the code in the first 
place, since 'count' has absolutely nothing to do with the copy from user 
space as it is written.

I'm also convinced we do _not_ want 'strncpy' there, since we do have the 
size of the write. Doing a strncpy_from_user() is actually _wrong_ if the 
user buffer itself is smaller than the kernel buffer and isn't 
NUL-terminated.

So that strncpy crap needs to go. It's wrong.

In other words it would all look a whole lot more natural (and correct) 
like the appended patch.

Untested, of course. And since almost nobody has the hardware, so it's not 
like it's ever likely to _be_ tested.

		Linus

---
 drivers/misc/sgi-gru/gruprocfs.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
index ccd4408..c0e17b0 100644
--- a/drivers/misc/sgi-gru/gruprocfs.c
+++ b/drivers/misc/sgi-gru/gruprocfs.c
@@ -164,7 +164,9 @@ static ssize_t options_write(struct file *file, const char __user *userbuf,
 	unsigned long val;
 	char buf[80];
 
-	if (strncpy_from_user(buf, userbuf, sizeof(buf) - 1) < 0)
+	if (count >= sizeof(buf))
+		count = sizeof(buf)-1;
+	if (copy_from_user(buf, userbuf, count))
 		return -EFAULT;
 	buf[count - 1] = '\0';
 	if (!strict_strtoul(buf, 10, &val))

  reply	other threads:[~2009-11-05 16:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-04 22:05 CVE-2009-2584 Michael Gilbert
2009-11-04 22:08 ` CVE-2009-2584 Justin P. Mattock
2009-11-04 22:21   ` CVE-2009-2584 Michael Gilbert
2009-11-04 22:49     ` CVE-2009-2584 Justin P. Mattock
2009-11-05 15:27 ` CVE-2009-2584 Jiri Kosina
2009-11-05 16:32   ` Linus Torvalds [this message]
2009-11-05 17:38     ` CVE-2009-2584 Linus Torvalds
2009-11-05 17:47       ` CVE-2009-2584 Linus Torvalds
2009-11-05 17:47       ` CVE-2009-2584 Michael Buesch
2009-11-05 18:16         ` CVE-2009-2584 Jack Steiner
2009-11-05 18:22           ` CVE-2009-2584 Linus Torvalds
2009-11-05 18:41             ` CVE-2009-2584 Jack Steiner
2009-11-05 18:19         ` CVE-2009-2584 Linus Torvalds
2009-11-05 17:56       ` CVE-2009-2584 Roland Dreier

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=alpine.LFD.2.01.0911050831330.31845@localhost.localdomain \
    --to=torvalds@linux-foundation.org \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mb@bu3sch.de \
    --cc=michael.s.gilbert@gmail.com \
    --cc=stable@kernel.org \
    --cc=steiner@sgi.com \
    /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

Powered by JetHome