Skip to contentSkip to conversation

wmi: avoid a double-fetch issue in wmi_ioctl

PATCH NAK Kangjie Lu 2 participants 2 messages Dec 25, 2018 – Feb 5, 2019 x86 platform drivers

lore
Share & tools
lore

Kangjie Lu

author
#0 lore raw

PATCH 1/1 wmi: avoid a double-fetch issue in wmi_ioctl

buf->length is first copied in from user space and security-checked. The second copy issued by copy_from_user copies it again. The data in user space may have been modified by malicious users. filter_callback() further uses the potentially modified data. The fix avoids the double-fetch that overwrites buf->length.

---
 drivers/platform/x86/wmi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/x86/wmi.c +2 -1
index bea35be68706..93cab9a70ad7 100644
@@ -850,7 +850,8 @@ static long wmi_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 			buf->length, wblock->req_buf_size);
 
 	/* copy the structure from userspace */
-	if (copy_from_user(buf, input, wblock->req_buf_size)) {
+	if (copy_from_user(buf->data, input->data,
+				wblock->req_buf_size - sizeof(buf->length))) {
 		dev_dbg(&wblock->dev.dev, "Copy %llu from user failed\n",
 			wblock->req_buf_size);
 		ret = -EFAULT;
Signature · 1 line
2.17.2 (Apple Git-113)
#1 lore raw
Quoted 4 lines · Kangjie Lu

buf->length is first copied in from user space and security-checked. The second copy issued by copy_from_user copies it again. The data in user space may have been modified by malicious users.

So, we already did a check and copied not more than we would expect.

Quoted 2 lines

filter_callback()
further uses the potentially modified data.

How?

Quoted 2 lines

The fix avoids the
double-fetch that overwrites buf->length.

NAK.

Quoted 22 lines
---
 drivers/platform/x86/wmi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/x86/wmi.c +2 -2
index bea35be68706..93cab9a70ad7 100644
@@ -850,7 +850,8 @@ static long wmi_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
                        buf->length, wblock->req_buf_size);
 
        /* copy the structure from userspace */
-       if (copy_from_user(buf, input, wblock->req_buf_size)) {
+       if (copy_from_user(buf->data, input->data,
+                               wblock->req_buf_size - sizeof(buf->length))) {
                dev_dbg(&wblock->dev.dev, "Copy %llu from user failed\n",
                        wblock->req_buf_size);
                ret = -EFAULT;
--

2.17.2 (Apple Git-113)

Signature · 2 lines
With Best Regards,
Andy Shevchenko