All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brandon Niemczyk <brandon@snprogramming.com>
To: kernel-janitors@vger.kernel.org
Subject: Re: [KJ] [PATCH] toshiba_acpi check kmalloc return value
Date: Mon, 11 Jul 2005 11:24:39 +0000	[thread overview]
Message-ID: <1121081079.3453.44.camel@localhost> (raw)
In-Reply-To: <1121044844.3554.25.camel@localhost>

[-- Attachment #1: Type: text/plain, Size: 1686 bytes --]

On Mon, 2005-07-11 at 11:53 +0200, walter harms wrote:
> hi Brandon,
> keep it simple


this better?

Signed-off-by: Brandon Niemczyk <brandon@snprogramming.com>

--- p1/drivers/acpi/toshiba_acpi.c.orig	2005-07-11 07:14:14.000000000 -0400
+++ p1/drivers/acpi/toshiba_acpi.c	2005-06-17 15:48:29.000000000 -0400
@@ -252,24 +252,26 @@ dispatch_read(char* page, char** start, 
 }
 
 static int
-dispatch_write(struct file* file, const char __user * buffer,
-	unsigned long count, ProcItem* item)
+dispatch_write(struct file *file, const char __user * buffer,
+	       unsigned long count, ProcItem * item)
 {
 	int result;
-	char* tmp_buffer;
+	char *tmp_buffer;
 
-	/* Arg buffer points to userspace memory, which can't be accessed
-	 * directly.  Since we're making a copy, zero-terminate the
-	 * destination so that sscanf can be used on it safely.
-	 */
 	tmp_buffer = kmalloc(count + 1, GFP_KERNEL);
+	if (!tmp_buffer)
+		return -ENOMEM;
+
 	if (copy_from_user(tmp_buffer, buffer, count)) {
 		result = -EFAULT;
+		goto out;
 	}
-	else {
-		tmp_buffer[count] = 0;
-		result = item->write_func(tmp_buffer, count);
-	}
+
+	/* make sure sscanf can be used safely */
+	tmp_buffer[count] = 0;
+	result = item->write_func(tmp_buffer, count);
+
+out:
 	kfree(tmp_buffer);
 	return result;
 }



> tmp_buffer = kmalloc(count + 1, GFP_KERNEL);
> if (!tmp_buffer)
> 	return -ENOMEM;
> 
> if ( copy_from_user(tmp_buffer, buffer, count) )
> 	result = -EFAULT;
> 
> tmp_buffer[count] = 0;
> result = item->write_func(tmp_buffer, count);
> 
> 
> just for the paranoid:
>   should tmp_buffer be filled with \0 to avoid an information leak ?
>   (schroedinger bug ?)

Not sure.
-- 
Brandon Niemczyk


[-- Attachment #2: Type: text/plain, Size: 168 bytes --]

_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors

  parent reply	other threads:[~2005-07-11 11:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-11  1:20 [KJ] [PATCH] toshiba_acpi check kmalloc return value Brandon Niemczyk
2005-07-11  2:32 ` randy_dunlap
2005-07-11  3:07 ` Brandon Niemczyk
2005-07-11  9:53 ` walter harms
2005-07-11 11:24 ` Brandon Niemczyk [this message]
2005-07-11 13:01 ` Domen Puncer
2005-07-11 15:55 ` walter harms
2005-07-11 17:08 ` Domen Puncer

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=1121081079.3453.44.camel@localhost \
    --to=brandon@snprogramming.com \
    --cc=kernel-janitors@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.