linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] acpi: debugfs: fix buffer overflows, double free
@ 2011-01-20 20:08 Vasiliy Kulikov
  2011-01-21  8:06 ` WANG Cong
  0 siblings, 1 reply; 3+ messages in thread
From: Vasiliy Kulikov @ 2011-01-20 20:08 UTC (permalink / raw)
  To: kernel-janitors; +Cc: Len Brown, linux-acpi, linux-kernel

File position is not controlled, it may lead to overwrites of arbitrary
kernel memory.  Also the code may kfree() the same pointer multiple
times.

One more flaw is still present: if multiple processes open the file then
all 3 static variables are shared, leading to various race conditions.
They should be moved to file->private_data.

Signed-off-by: Vasiliy Kulikov <segoon@openwall.com>
---
 drivers/acpi/debugfs.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/acpi/debugfs.c b/drivers/acpi/debugfs.c
index 5df67f1..384f7ab 100644
--- a/drivers/acpi/debugfs.c
+++ b/drivers/acpi/debugfs.c
@@ -26,7 +26,9 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
 			size_t count, loff_t *ppos)
 {
 	static char *buf;
-	static int uncopied_bytes;
+	static u32 max_size;
+	static u32 uncopied_bytes;
+
 	struct acpi_table_header table;
 	acpi_status status;
 
@@ -37,19 +39,24 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
 		if (copy_from_user(&table, user_buf,
 				   sizeof(struct acpi_table_header)))
 			return -EFAULT;
-		uncopied_bytes = table.length;
-		buf = kzalloc(uncopied_bytes, GFP_KERNEL);
+		uncopied_bytes = max_size = table.length;
+		buf = kzalloc(max_size, GFP_KERNEL);
 		if (!buf)
 			return -ENOMEM;
 	}
 
-	if (uncopied_bytes < count) {
-		kfree(buf);
+	if (buf == NULL)
+		return -EINVAL;
+
+	if ((*ppos > max_size) ||
+	    (*ppos + count > max_size) ||
+	    (*ppos + count < count) ||
+	    (count > uncopied_bytes))
 		return -EINVAL;
-	}
 
 	if (copy_from_user(buf + (*ppos), user_buf, count)) {
 		kfree(buf);
+		buf = NULL;
 		return -EFAULT;
 	}
 
@@ -59,6 +66,7 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
 	if (!uncopied_bytes) {
 		status = acpi_install_method(buf);
 		kfree(buf);
+		buf = NULL;
 		if (ACPI_FAILURE(status))
 			return -EINVAL;
 		add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] acpi: debugfs: fix buffer overflows, double free
  2011-01-20 20:08 [PATCH] acpi: debugfs: fix buffer overflows, double free Vasiliy Kulikov
@ 2011-01-21  8:06 ` WANG Cong
  2011-01-21  9:37   ` Eugene Teo
  0 siblings, 1 reply; 3+ messages in thread
From: WANG Cong @ 2011-01-21  8:06 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-acpi, kernel-janitors, linux-acpi, linux-kernel

On Thu, 20 Jan 2011 23:08:06 +0300, Vasiliy Kulikov wrote:

> File position is not controlled, it may lead to overwrites of arbitrary
> kernel memory.  Also the code may kfree() the same pointer multiple
> times.
> 
> One more flaw is still present: if multiple processes open the file then
> all 3 static variables are shared, leading to various race conditions.
> They should be moved to file->private_data.
> 
> Signed-off-by: Vasiliy Kulikov <segoon@openwall.com>

Reviewed-by: WANG Cong <xiyou.wangcong@gmail.com>

Thanks.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] acpi: debugfs: fix buffer overflows, double free
  2011-01-21  8:06 ` WANG Cong
@ 2011-01-21  9:37   ` Eugene Teo
  0 siblings, 0 replies; 3+ messages in thread
From: Eugene Teo @ 2011-01-21  9:37 UTC (permalink / raw)
  To: WANG Cong; +Cc: linux-kernel, linux-acpi, kernel-janitors

On 1/21/11, WANG Cong <xiyou.wangcong@gmail.com> wrote:
> On Thu, 20 Jan 2011 23:08:06 +0300, Vasiliy Kulikov wrote:
>
>> File position is not controlled, it may lead to overwrites of arbitrary
>> kernel memory.  Also the code may kfree() the same pointer multiple
>> times.
>>
>> One more flaw is still present: if multiple processes open the file then
>> all 3 static variables are shared, leading to various race conditions.
>> They should be moved to file->private_data.
>>
>> Signed-off-by: Vasiliy Kulikov <segoon@openwall.com>
>
> Reviewed-by: WANG Cong <xiyou.wangcong@gmail.com>

Reviewed-by: Eugene Teo <eugeneteo@kernel.org>

Thanks, Eugene

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-01-21  9:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-20 20:08 [PATCH] acpi: debugfs: fix buffer overflows, double free Vasiliy Kulikov
2011-01-21  8:06 ` WANG Cong
2011-01-21  9:37   ` Eugene Teo

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).