Skip to contentSkip to conversation

drivers/net/wan/lmc/lmc_main.c

PATCH In review Akash Jain 2 participants 2 messages May 22, 2001 Networking

lore
Share & tools
lore

Akash Jain

author
#0 lore raw

PATCH 1/1 drivers/net/wan/lmc/lmc_main.c

Hey All,
I am working with Dawson Engler's meta-compillation group @ stanford. Sorry if this is reposted, previous one seemed to get tied up. Here is a patch to the drivers/net/wan/lmc/lmc_main.c file.

On line 503, the authors use the GFP_KERNEL argument to kmalloc, how ever
they are holding a spin lock during this period. They should use GFP_ATOMIC here.

On line 510, the authors rely on a macro, LMC_COPY_FROM_USER which is designed to work with stack memory, not heap memory. In all other cases it is fine, here however, the memory must be deallocated before -EFAULT can be returned. Note that this is a potential security hole as it is leaking memory and can be exploited by passing bogus pointers to copy_to_user - thus creating a DOS situation.

net/wan/lmc/lmc_main.c renamed from net/wan/lmc/lmc_main.c.orig +5 -2
@@ -500,14 +500,17 @@
                             break;
                     }
 
-                    data = kmalloc(xc.len, GFP_KERNEL);
+                    data = kmalloc(xc.len, GFP_ATOMIC);
                     if(data == 0x0){
                             printk(KERN_WARNING "%s: Failed to allocate memory for copy\n", dev->name);
                             ret = -ENOMEM;
                             break;
                     }
                     
-                    LMC_COPY_FROM_USER(data, xc.data, xc.len);
+		    if(copy_from_user(data, xc.data, xc.len)){
+		            kfree(data);
+		            return -EFAULT;
+		    }
 
                     printk("%s: Starting load of data Len: %d at 0x%p == 0x%p\n", dev->name, xc.len, xc.data, data)
 

Thanks!
-Akash Jain

#1 lore raw
Quoted 3 lines · Akash Jain

Sorry if this is reposted, previous one seemed to get tied up. Here is a patch to the drivers/net/wan/lmc/lmc_main.c file.

I got the previous one, here's a copy of my reply to the people who weren't cc'd on that one.

Linus

--- in a previous email, Linus wrote ---

lmc_main.c is _soo_ broken than this patch only scratches the surface and only hides a small small part of the offenders.

In particular, the fact that it does allocations with GFP_KERNEL while holding a spinlock is the _least_ of its troubles: it also does a "copy_from/to_user()" while holding the same spinlock (and has timeouts of up to half a second with interrupts disabled from the same spinlock).

The kmalloc() is likely to succeed: a copy_from_user() can be trivially made to cause IO every time by a wily user.

In short, the whole locking strategy is broken, and there's no way to fix it with small micro-patches. So not applied.

(And it also looks like your sanity checker doesn't trap "copy to/from user space with spinlocks held or irq's disabled", hint hint ;).

Btw, what's the right address to send this kind of feedback to the stanford group?

Good work by the checker, btw. it's not your fault that the problem goes deeper than what you found.

Thanks,

Linus