Fix a sockbuf race. Currently the m_free*() path can block, due to
authorMatthew Dillon <dillon@dragonflybsd.org>
Sat, 23 Jul 2005 07:28:36 +0000 (07:28 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Sat, 23 Jul 2005 07:28:36 +0000 (07:28 +0000)
commit857caa4ae0295b7a41c847081e72419eb1f12f57
treec02a3caa7003bdc94338f93d4d2a7e7d7f172277
parentd64a7617dd89f8fdb1aaa10228ea92d1dcd9cf08
Fix a sockbuf race.  Currently the m_free*() path can block, due to
objcache_put() blocking when it must access the global depot.  This breaks
the critical section *AND the BGL during a time when the sockbuf state is
inconsistent.  Another process accessing the same sockbuf would then
corrupt it.  Since depot access is fairly rare, this bug typically required
a number of hours to reproduce.

Delay the actual freeing of mbufs until after the sockbuf state has been
updated.  Encapsulate common operations in a procedure, and add additional
assertions.  NULL out sb_lastrecord when it becomes invalid, and add a
considerable amount of debugging code.

SOCKBUF_DEBUG has been added.  Note that this is a VERY EXPENSIVE
kernel compile option which should only be used when specifically debugging
the networking subsystem.

This is a stabilization patch is rather hackish.  A better cleanup will
occur once we are sure we've fixed all the bugs.

sbcheck provided by: Jeffrey Hsu
Reported-by: David Rhodus, Peter Avalos, YONETANI Tomokazu,
     Tomaz Borstnar, and numerous other people.
sys/kern/uipc_socket.c
sys/kern/uipc_socket2.c
sys/sys/socketvar.h