alloc_socket: interrupt lock
authorAlan Cox <alan@linux.intel.com>
Fri, 25 Mar 2016 21:07:07 +0000 (21:07 +0000)
committerAlan Cox <alan@linux.intel.com>
Fri, 25 Mar 2016 21:07:07 +0000 (21:07 +0000)
In the normal case this is safe because we always allocate from in kernel.
Likewise it's safe for accept with the native TCP/IP. However it's not safe
if we have a hardware TCP/IP and it implements accept() and thus allocates
accepting sockets from an interrupt.

So block IRQs for the brief scan.

[noted by Brett]

Kernel/syscall_net.c

index d8d4685..c4a4a8f 100644 (file)
@@ -90,12 +90,17 @@ static int sock_wait_enter(struct socket *s, uint8_t flag, uint8_t state)
 
 static struct socket *alloc_socket(void)
 {
+       irqflags_t irq = di();
        struct socket *s = sockets;
        while (s < sockets + NSOCKET) {
-               if (s->s_state == SS_UNUSED)
+               if (s->s_state == SS_UNUSED) {
+                       s->s_state = SS_INIT;
+                       irqrestore(irq);
                        return s;
+               }
                s++;
        }
+       irqrestore(irq);
        return NULL;
 }