opnsense-src/sys/sys
Robert Watson 0daccb9c94 In the current world order, solisten() implements the state transition of
a socket from a regular socket to a listening socket able to accept new
connections.  As part of this state transition, solisten() calls into the
protocol to update protocol-layer state.  There were several bugs in this
implementation that could result in a race wherein a TCP SYN received
in the interval between the protocol state transition and the shortly
following socket layer transition would result in a panic in the TCP code,
as the socket would be in the TCPS_LISTEN state, but the socket would not
have the SO_ACCEPTCONN flag set.

This change does the following:

- Pushes the socket state transition from the socket layer solisten() to
  to socket "library" routines called from the protocol.  This permits
  the socket routines to be called while holding the protocol mutexes,
  preventing a race exposing the incomplete socket state transition to TCP
  after the TCP state transition has completed.  The check for a socket
  layer state transition is performed by solisten_proto_check(), and the
  actual transition is performed by solisten_proto().

- Holds the socket lock for the duration of the socket state test and set,
  and over the protocol layer state transition, which is now possible as
  the socket lock is acquired by the protocol layer, rather than vice
  versa.  This prevents additional state related races in the socket
  layer.

This permits the dual transition of socket layer and protocol layer state
to occur while holding locks for both layers, making the two changes
atomic with respect to one another.  Similar changes are likely require
elsewhere in the socket/protocol code.

Reported by:		Peter Holm <peter@holm.cc>
Review and fixes from:	emax, Antoine Brodin <antoine.brodin@laposte.net>
Philosophical head nod:	gnn
2005-02-21 21:58:17 +00:00
..
_iovec.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
_label.h Improve consistency of include file guards in src/sys/sys by terminating 2004-05-10 18:38:07 +00:00
_lock.h Include <sys/_lock.h>'s prerequisite <sys/queue.h> before including the 2004-06-19 14:58:35 +00:00
_mutex.h
_null.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
_semaphore.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
_sigset.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
_task.h Add taskqueue_drain. This waits for the specified task to finish, if 2004-10-05 04:16:01 +00:00
_timespec.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
_timeval.h
_types.h Document why rlim_t needs to be a signed type. 2004-11-08 18:05:43 +00:00
aac_ioctl.h Do some small cleanups to comments and remove AACQ_COMPLETE definitions since 2004-02-07 17:40:38 +00:00
acct.h Second half of the dev_t cleanup. 2004-06-17 17:16:53 +00:00
acl.h Improve consistency of include file guards in src/sys/sys by terminating 2004-05-10 18:38:07 +00:00
agpio.h
aio.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
alq.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
assym.h These are changes to allow to use the Intel C/C++ compiler (lang/icc) 2004-03-12 21:45:33 +00:00
ata.h Whitespace cleanup 2004-05-20 15:09:41 +00:00
bio.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
bitstring.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
blist.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
buf.h make cluster_callback() static 2005-02-10 12:17:48 +00:00
bufobj.h Try to unbreak the vnode locking around vop_reclaim() (based mostly on 2005-02-19 11:44:57 +00:00
bus.h Introduce bus_free_resource. It is a convenience function which wraps 2005-01-19 06:52:19 +00:00
bus_dma.h Introduce bus_dmamap_load_mbuf_sg(). Instead of taking a callback arg, this 2005-01-07 07:57:18 +00:00
callout.h Add a mechanism for associating a mutex with a callout when the 2005-02-07 02:47:33 +00:00
cdefs.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
cdio.h Boot away another stackgap (one of the lest ones in linuxlator/i386) by 2005-01-30 08:12:37 +00:00
cdrio.h
chio.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
clist.h Remove advertising clause from University of California Regent's license, 2004-04-07 04:19:52 +00:00
clock.h
condvar.h Name the pri argument to cv_broadcastpri() to match the existing style of 2004-05-05 21:57:44 +00:00
conf.h Add MAXMINOR #define, we should have had this long time ago. 2005-01-29 15:07:13 +00:00
cons.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
consio.h
copyright.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
cpu.h Add a new field to struct cf_setting for special values. These are driver- 2005-02-19 06:13:26 +00:00
ctype.h Remove advertising clause from University of California Regent's license, 2004-04-07 04:19:52 +00:00
dataacq.h
device_port.h Remove code for pre-4.0 versions of FreeBSD. It is there in prior 2005-01-19 01:31:33 +00:00
devicestat.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
digiio.h
dir.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
dirent.h Remove advertising clause from University of California Regent's license, 2004-04-07 04:19:52 +00:00
disk.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
disklabel.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
diskmbr.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
diskpc98.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
dkstat.h Remove advertising clause from University of California Regent's license, 2004-04-07 04:19:52 +00:00
domain.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
dvdio.h
elf32.h
elf64.h
elf_common.h Fix typo (in comment): s/IA-46/IA-64/ 2004-05-05 02:38:54 +00:00
elf_generic.h
endian.h
errno.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
eui64.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
event.h move the declaration of struct kqlist into the non-KERNEL visable section 2004-08-15 15:36:18 +00:00
eventhandler.h Use 'const char *' for a few prototypes. 2004-12-06 10:53:40 +00:00
eventvar.h Add locking to the kqueue subsystem. This also makes the kqueue subsystem 2004-08-15 06:24:42 +00:00
exec.h Do a pass over all modules in the kernel and make them return EOPNOTSUPP 2004-07-15 08:26:07 +00:00
extattr.h
fbio.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
fcntl.h Remove advertising clause from University of California Regent's license, 2004-04-07 04:19:52 +00:00
fdcio.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
file.h Make some file/filedesc related functions static 2005-02-10 12:27:58 +00:00
filedesc.h Make some file/filedesc related functions static 2005-02-10 12:27:58 +00:00
filio.h Remove advertising clause from University of California Regent's license, 2004-04-07 04:19:52 +00:00
fnv_hash.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
gmon.h Add prototypes for the userland gmon support functions, which normally 2004-06-14 18:39:28 +00:00
gpt.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
iconv.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
imgact.h o Split out kernel part of execve(2) syscall into two parts: one that 2005-01-29 23:12:00 +00:00
imgact_aout.h Adjust the system endian and a.out headers to be more MI and cross-building 2004-06-22 17:05:39 +00:00
imgact_elf.h Add __elfN(dump_thread). This function is called from __elfN(coredump) 2004-08-11 02:35:06 +00:00
inflate.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
interrupt.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
ioccom.h Remove advertising clause from University of California Regent's license, 2004-04-07 04:19:52 +00:00
ioctl.h Deorbit COMPAT_SUNOS. 2004-06-11 11:16:26 +00:00
ioctl_compat.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
ipc.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
jail.h Add a new sysctl, "security.jail.chflags_allowed", which controls the 2005-02-08 21:31:11 +00:00
joystick.h Comment typo. 2005-01-07 19:31:43 +00:00
kbio.h
kdb.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
kenv.h
kernel.h Define SI_SUB_AUDIT, the system boot event to initialize the audit 2005-02-02 14:41:03 +00:00
kerneldump.h
kobj.h
kse.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
kthread.h
ktr.h - Somehow I mangled KTR_CRITICAL. 2005-01-24 10:52:32 +00:00
ktrace.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
libkern.h Add strspn() to libkern. 2005-02-10 20:39:39 +00:00
limits.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
linedisc.h Fix line discipline switching issues: If opening a new ldisc fails, 2004-06-26 08:44:04 +00:00
link_aout.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
link_elf.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
linker.h Add a new module information type MODINFOMD_SHDR that will be used 2004-08-27 01:10:16 +00:00
linker_set.h Typo fix. 2005-01-14 09:51:29 +00:00
lock.h Rework witness_lock() to make it slightly more useful and flexible. 2004-01-28 20:39:57 +00:00
lockf.h - Make lf_print static and move its prototype into kern_lockf.c 2005-01-25 10:15:26 +00:00
lockmgr.h - Include LK_INTERLOCK in LK_EXTFLG_MASK so that it makes its way into 2005-01-25 16:06:05 +00:00
mac.h Define new MAC framework and policy entry points for System V IPC 2004-11-17 13:10:16 +00:00
mac_policy.h Define new MAC framework and policy entry points for System V IPC 2004-11-17 13:10:16 +00:00
malloc.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
mbpool.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
mbuf.h Allocate the M_VLANTAG m_pkthdr flag, and use it to indicate that 2005-02-18 22:31:19 +00:00
mchain.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
md4.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
md5.h MD5Pad() should never have been exposed. 2005-02-10 12:20:42 +00:00
mdioctl.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
memrange.h Fix module builds for i386 and amd64. 2004-08-04 18:30:31 +00:00
mman.h Remove mlockall() and munlockall() from the list of unimplemented 2004-04-27 13:13:20 +00:00
module.h Give kldunload a -f(orce) argument. 2004-07-13 19:36:59 +00:00
mount.h Remove VFS_START(). Its original purpose involved the mfs filesystem, 2005-02-20 23:02:20 +00:00
mouse.h Don't export the 'dt' field as that would break the exisiting ABI. 2004-12-13 01:23:49 +00:00
msg.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
msgbuf.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
mtio.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
mutex.h Rework the optimization for spinlocks on UP to be slightly less drastic and 2005-01-05 21:13:27 +00:00
namei.h - Add two new flags to the nd structure. MPSAFE indicates that the 2005-01-24 09:57:35 +00:00
nlist_aout.h Remove advertising clause from University of California Regent's license, 2004-04-07 04:19:52 +00:00
param.h Bump __FreeBSD_version for vswprintf(3) fix. Some ports depend on it. 2005-02-21 19:43:18 +00:00
pciio.h
pcpu.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
pioctl.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
pipe.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
poll.h
posix4.h
power.h
priority.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
proc.h Backout previous change (disabling of security checks for signals delivered 2005-02-13 17:37:20 +00:00
procfs.h type prgregset_t really should be an array. this is odd, however, other 2004-07-15 03:52:17 +00:00
protosw.h Initialize struct pr_userreqs in new/sparse style and fill in common 2004-11-08 14:44:54 +00:00
ptio.h
ptrace.h Add pl_flags to ptrace_lwpinfo, two flags PL_FLAG_SA and PL_FLAG_BOUND 2004-08-08 22:26:11 +00:00
queue.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
random.h Add a note ahea of the esource enum that if new entropy source 2004-10-12 14:55:59 +00:00
reboot.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
regression.h Improve consistency of include file guards in src/sys/sys by terminating 2004-05-10 18:38:07 +00:00
resource.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
resourcevar.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
rman.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
rtprio.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
runq.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
sbuf.h Have sbuf_bcat() and sbuf_bcpy() take a const void * instead of a 2004-07-09 11:35:30 +00:00
sched.h Rework the interface between priority propagation (lending) and the 2004-12-30 20:52:44 +00:00
select.h Remove advertising clause from University of California Regent's license, 2004-04-07 04:19:52 +00:00
selinfo.h Add locking to the kqueue subsystem. This also makes the kqueue subsystem 2004-08-15 06:24:42 +00:00
sem.h In the kernel-only portionss of System V IPC objects (messages, 2004-11-17 13:12:06 +00:00
sema.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
semaphore.h The sem_timedwait() and ksem_timedwait() functions both 2004-02-03 22:27:03 +00:00
serial.h Make the relationship between modem control bits and their delta cousins 2004-06-25 10:56:43 +00:00
sf_buf.h Introduce two new options, "CPU private" and "no wait", to sf_buf_alloc(). 2004-11-08 00:43:46 +00:00
shm.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
sigio.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
signal.h Make this look less dubious :-) 2004-06-11 11:43:46 +00:00
signalvar.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
sleepqueue.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
smp.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
snoop.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
socket.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
socketvar.h In the current world order, solisten() implements the state transition of 2005-02-21 21:58:17 +00:00
sockio.h Remove advertising clause from University of California Regent's license, 2004-04-07 04:19:52 +00:00
soundcard.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
stat.h Second half of the dev_t cleanup. 2004-06-17 17:16:53 +00:00
statvfs.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
stddef.h
stdint.h
sun_disklabel.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
sx.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
syscall.h - Regen for recent vfs syscall changes. 2005-01-24 10:50:42 +00:00
syscall.mk - Regen for recent vfs syscall changes. 2005-01-24 10:50:42 +00:00
syscallsubr.h Backout previous change (disabling of security checks for signals delivered 2005-02-13 17:37:20 +00:00
sysctl.h Add a missing prefix to a struct field for consistency. 2005-02-07 07:40:39 +00:00
sysent.h Remove advertising clause from University of California Regent's license, 2004-04-07 04:19:52 +00:00
syslimits.h For non-embedded platforms, increase the size of the argument list. 2005-02-18 08:01:59 +00:00
syslog.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
sysproto.h - Regen for recent vfs syscall changes. 2005-01-24 10:50:42 +00:00
systm.h Add VNASSERT() which is just like KASSERT() but takes a vnode argument 2005-02-07 12:56:19 +00:00
taskqueue.h Add taskqueue_drain. This waits for the specified task to finish, if 2004-10-05 04:16:01 +00:00
termios.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
thr.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
tiio.h
time.h move kern_nanosleep to sys/syscallsubr.h 2005-01-19 18:09:50 +00:00
timeb.h Remove advertising clause from University of California Regent's license, 2004-04-07 04:19:52 +00:00
timepps.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
timers.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
times.h Remove advertising clause from University of California Regent's license, 2004-04-07 04:19:52 +00:00
timespec.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
timetc.h
timex.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
tree.h Add FreeBSD tag 2005-01-07 02:28:28 +00:00
tty.h Add new function ttyinitmode() which sets our systemwide default 2004-10-18 21:51:27 +00:00
ttychars.h Put the pre FreeBSD-2.x tty compat code under BURN_BRIDGES. 2004-06-21 22:57:16 +00:00
ttycom.h Retire the TIOC_REMOTE ioctl. 2004-06-25 21:54:49 +00:00
ttydefaults.h Restore TTYDEF_LFLAG to set echo bits. 2004-11-03 19:16:55 +00:00
ttydev.h Put the pre FreeBSD-2.x tty compat code under BURN_BRIDGES. 2004-06-21 22:57:16 +00:00
turnstile.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
types.h Define __lwpid_t as an int32_t in <sys/_types.h> and define lwpid_t 2004-06-19 17:58:32 +00:00
ucontext.h
ucred.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
uio.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
umtx.h unbreak libthr binary compatibility. 2005-01-26 12:07:06 +00:00
un.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
unistd.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
unpcb.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
user.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
utsname.h Remove advertising clause from University of California Regent's license, 2004-04-07 04:19:52 +00:00
uuid.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00
vmmeter.h Remove remnants of PGINPROF. 2004-06-08 10:37:30 +00:00
vnode.h Introduce vx_wait{l}() and use it instead of home-rolled versions. 2005-02-17 10:49:51 +00:00
wait.h - Move the function prototypes for kern_setrlimit() and kern_wait() to 2005-01-05 22:19:44 +00:00
watchdog.h Add a generic watchdog facility which through a single device entry 2004-02-28 20:06:59 +00:00
xrpuio.h /* -> /*- for license, minor formatting changes 2005-01-07 02:29:27 +00:00