From: John Belmonte <john-wanGne27zNesTnJN9+BGXg@public.gmane.org>
To: "Brown, Len" <len.brown-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: Julien Lerouge <julien.lerouge-GANU6spQydw@public.gmane.org>,
acpi-devel
<acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Subject: [PATCH] toshiba_acpi 0.18
Date: Sat, 13 Mar 2004 21:35:01 -0500 [thread overview]
Message-ID: <4053C4D5.8000703@neggie.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 364 bytes --]
Attached is a patch for linux-2.6.4 which yields toshiba_acpi 0.18. It
should apply against the 2.4 kernel also.
This version fixes illegal userspace memory access reported at
<http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=117682>.
It appears that the asus_acpi driver has the same issue, as it was
derived from mine.
-John
--
http:// if ile.org/
[-- Attachment #2: toshiba_acpi_0.18-linux_2.6.4.patch --]
[-- Type: text/x-patch, Size: 3207 bytes --]
diff -urN linux-2.6.4/drivers/acpi/toshiba_acpi.c new/drivers/acpi/toshiba_acpi.c
--- linux-2.6.4/drivers/acpi/toshiba_acpi.c 2004-03-13 21:09:26.000000000 -0500
+++ new/drivers/acpi/toshiba_acpi.c 2004-03-13 21:09:35.000000000 -0500
@@ -33,7 +33,7 @@
*
*/
-#define TOSHIBA_ACPI_VERSION "0.17"
+#define TOSHIBA_ACPI_VERSION "0.18"
#define PROC_INTERFACE_VERSION 1
#include <linux/kernel.h>
@@ -41,6 +41,7 @@
#include <linux/init.h>
#include <linux/types.h>
#include <linux/proc_fs.h>
+#include <asm/uaccess.h>
#include <acpi/acpi_drivers.h>
@@ -105,24 +106,6 @@
*word = (*word & ~mask) | (mask * value);
}
-/* an sscanf that takes explicit string length */
-static int
-snscanf(const char* str, int n, const char* format, ...)
-{
- va_list args;
- int result;
- char* str2 = kmalloc(n + 1, GFP_KERNEL);
- if (str2 == 0) return 0;
- /* NOTE: don't even _think_ about replacing this with strlcpy */
- strncpy(str2, str, n);
- str2[n] = 0;
- va_start(args, format);
- result = vsscanf(str2, format, args);
- va_end(args);
- kfree(str2);
- return result;
-}
-
/* acpi interface wrappers
*/
@@ -272,7 +255,23 @@
dispatch_write(struct file* file, const char* buffer, unsigned long count,
ProcItem* item)
{
- return item->write_func(buffer, count);
+ int result;
+ 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 (copy_from_user(tmp_buffer, buffer, count)) {
+ result = -EFAULT;
+ }
+ else {
+ tmp_buffer[count] = 0;
+ result = item->write_func(tmp_buffer, count);
+ }
+ kfree(tmp_buffer);
+ return result;
}
static char*
@@ -300,7 +299,7 @@
int value;
u32 hci_result;
- if (snscanf(buffer, count, " brightness : %i", &value) == 1 &&
+ if (sscanf(buffer, " brightness : %i", &value) == 1 &&
value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) {
value = value << HCI_LCD_BRIGHTNESS_SHIFT;
hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result);
@@ -350,11 +349,11 @@
* NOTE: to keep scanning simple, invalid fields are ignored
*/
while (remain) {
- if (snscanf(buffer, remain, " lcd_out : %i", &value) == 1)
+ if (sscanf(buffer, " lcd_out : %i", &value) == 1)
lcd_out = value & 1;
- else if (snscanf(buffer, remain, " crt_out : %i", &value) == 1)
+ else if (sscanf(buffer, " crt_out : %i", &value) == 1)
crt_out = value & 1;
- else if (snscanf(buffer, remain, " tv_out : %i", &value) == 1)
+ else if (sscanf(buffer, " tv_out : %i", &value) == 1)
tv_out = value & 1;
/* advance to one character past the next ; */
do {
@@ -407,7 +406,7 @@
int value;
u32 hci_result;
- if (snscanf(buffer, count, " force_on : %i", &value) == 1 &&
+ if (sscanf(buffer, " force_on : %i", &value) == 1 &&
value >= 0 && value <= 1) {
hci_write1(HCI_FAN, value, &hci_result);
if (hci_result != HCI_SUCCESS)
@@ -458,7 +457,7 @@
{
int value;
- if (snscanf(buffer, count, " hotkey_ready : %i", &value) == 1 &&
+ if (sscanf(buffer, " hotkey_ready : %i", &value) == 1 &&
value == 0) {
key_event_valid = 0;
} else {
next reply other threads:[~2004-03-14 2:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-14 2:35 John Belmonte [this message]
[not found] ` <4053C4D5.8000703-wanGne27zNesTnJN9+BGXg@public.gmane.org>
2004-03-14 5:38 ` [PATCH] toshiba_acpi 0.18 Len Brown
[not found] ` <1079242701.2168.121.camel-D2Zvc0uNKG8@public.gmane.org>
2004-03-14 6:02 ` John Belmonte
[not found] ` <4053F592.80001-wanGne27zNesTnJN9+BGXg@public.gmane.org>
2004-03-23 7:01 ` Len Brown
2004-03-25 14:34 ` Sergey Vlasov
[not found] ` <20040325173453.77fed4e9.vsu-u2l5PoMzF/Uox3rIn2DAYQ@public.gmane.org>
2004-03-25 15:48 ` John Belmonte
2004-03-14 13:07 ` [PATCH] " Karol Kozimor
[not found] ` <20040314130724.GA1994-DETuoxkZsSqrDJvtcaxF/A@public.gmane.org>
2004-03-23 23:24 ` Karol Kozimor
[not found] ` <20040323232438.GA9223-DETuoxkZsSqrDJvtcaxF/A@public.gmane.org>
2004-03-24 4:09 ` John Belmonte
[not found] ` <40610A01.9070904-wanGne27zNesTnJN9+BGXg@public.gmane.org>
2004-03-24 11:17 ` Karol Kozimor
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=4053C4D5.8000703@neggie.net \
--to=john-wangne27znestnjn9+bgxg@public.gmane.org \
--cc=acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
--cc=julien.lerouge-GANU6spQydw@public.gmane.org \
--cc=len.brown-ral2JQCrhuEAvxtiuMwx3w@public.gmane.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.