mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] UP locking fix for net/socket.c
@ 2002-10-31 11:57 Duncan Sands
  0 siblings, 0 replies; only message in thread
From: Duncan Sands @ 2002-10-31 11:57 UTC (permalink / raw)
  To: Linux Kernel; +Cc: Alan Cox

[-- Attachment #1: Type: text/plain, Size: 1123 bytes --]

This race occurs on UP (not SMP) systems.  socket.c must
not continue using net_family after sock_unregister(net_family)
has returned.  Here is a scenario for this to occur: go to sleep in
the following call:

if ((i = net_families[family]->create(sock, protocol)) < 0)

While sleeping, a task calls sock_unregister(family), which
succeeds since on UP there is currently no locking of any kind.

Duncan.

Patches against 2.4.19 and 2.5.45 attached.  2.4.19 patch:

--- linux/net/socket.c.orig	2002-08-03 02:39:46.000000000 +0200
+++ linux/net/socket.c	2002-10-31 09:16:50.000000000 +0100
@@ -132,7 +132,6 @@
 
 static struct net_proto_family *net_families[NPROTO];
 
-#ifdef CONFIG_SMP
 static atomic_t net_family_lockct = ATOMIC_INIT(0);
 static spinlock_t net_family_lock = SPIN_LOCK_UNLOCKED;
 
@@ -170,13 +169,6 @@
 	atomic_dec(&net_family_lockct);
 }
 
-#else
-#define net_family_write_lock() do { } while(0)
-#define net_family_write_unlock() do { } while(0)
-#define net_family_read_lock() do { } while(0)
-#define net_family_read_unlock() do { } while(0)
-#endif
-
 
 /*
  *	Statistics counters of the socket lists

[-- Attachment #2: patch_no_race_2.5 --]
[-- Type: text/x-diff, Size: 691 bytes --]

--- Yield/net/socket.c.orig	2002-10-31 09:10:07.000000000 +0100
+++ Yield/net/socket.c	2002-10-31 09:13:48.000000000 +0100
@@ -138,7 +138,6 @@
 
 static struct net_proto_family *net_families[NPROTO];
 
-#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT)
 static atomic_t net_family_lockct = ATOMIC_INIT(0);
 static spinlock_t net_family_lock = SPIN_LOCK_UNLOCKED;
 
@@ -175,13 +174,6 @@
 	atomic_dec(&net_family_lockct);
 }
 
-#else
-#define net_family_write_lock() do { } while(0)
-#define net_family_write_unlock() do { } while(0)
-#define net_family_read_lock() do { } while(0)
-#define net_family_read_unlock() do { } while(0)
-#endif
-
 
 /*
  *	Statistics counters of the socket lists

[-- Attachment #3: patch_no_race_2.4 --]
[-- Type: text/x-diff, Size: 658 bytes --]

--- linux/net/socket.c.orig	2002-08-03 02:39:46.000000000 +0200
+++ linux/net/socket.c	2002-10-31 09:16:50.000000000 +0100
@@ -132,7 +132,6 @@
 
 static struct net_proto_family *net_families[NPROTO];
 
-#ifdef CONFIG_SMP
 static atomic_t net_family_lockct = ATOMIC_INIT(0);
 static spinlock_t net_family_lock = SPIN_LOCK_UNLOCKED;
 
@@ -170,13 +169,6 @@
 	atomic_dec(&net_family_lockct);
 }
 
-#else
-#define net_family_write_lock() do { } while(0)
-#define net_family_write_unlock() do { } while(0)
-#define net_family_read_lock() do { } while(0)
-#define net_family_read_unlock() do { } while(0)
-#endif
-
 
 /*
  *	Statistics counters of the socket lists

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-10-31 11:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-31 11:57 [PATCH] UP locking fix for net/socket.c Duncan Sands

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®