1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-24 11:29:10 +00:00
freebsd/sys/modules
John Baldwin 6bc1e9cd84 Rework the lifetime management of the kernel implementation of POSIX
semaphores.  Specifically, semaphores are now represented as new file
descriptor type that is set to close on exec.  This removes the need for
all of the manual process reference counting (and fork, exec, and exit
event handlers) as the normal file descriptor operations handle all of
that for us nicely.  It is also suggested as one possible implementation
in the spec and at least one other OS (OS X) uses this approach.

Some bugs that were fixed as a result include:
- References to a named semaphore whose name is removed still work after
  the sem_unlink() operation.  Prior to this patch, if a semaphore's name
  was removed, valid handles from sem_open() would get EINVAL errors from
  sem_getvalue(), sem_post(), etc.  This fixes that.
- Unnamed semaphores created with sem_init() were not cleaned up when a
  process exited or exec'd.  They were only cleaned up if the process
  did an explicit sem_destroy().  This could result in a leak of semaphore
  objects that could never be cleaned up.
- On the other hand, if another process guessed the id (kernel pointer to
  'struct ksem' of an unnamed semaphore (created via sem_init)) and had
  write access to the semaphore based on UID/GID checks, then that other
  process could manipulate the semaphore via sem_destroy(), sem_post(),
  sem_wait(), etc.
- As part of the permission check (UID/GID), the umask of the proces
  creating the semaphore was not honored.  Thus if your umask denied group
  read/write access but the explicit mode in the sem_init() call allowed
  it, the semaphore would be readable/writable by other users in the
  same group, for example.  This includes access via the previous bug.
- If the module refused to unload because there were active semaphores,
  then it might have deregistered one or more of the semaphore system
  calls before it noticed that there was a problem.  I'm not sure if
  this actually happened as the order that modules are discovered by the
  kernel linker depends on how the actual .ko file is linked.  One can
  make the order deterministic by using a single module with a mod_event
  handler that explicitly registers syscalls (and deregisters during
  unload after any checks).  This also fixes a race where even if the
  sem_module unloaded first it would have destroyed locks that the
  syscalls might be trying to access if they are still executing when
  they are unloaded.

  XXX: By the way, deregistering system calls doesn't do any blocking
  to drain any threads from the calls.
- Some minor fixes to errno values on error.  For example, sem_init()
  isn't documented to return ENFILE or EMFILE if we run out of semaphores
  the way that sem_open() can.  Instead, it should return ENOSPC in that
  case.

Other changes:
- Kernel semaphores now use a hash table to manage the namespace of
  named semaphores nearly in a similar fashion to the POSIX shared memory
  object file descriptors.  Kernel semaphores can now also have names
  longer than 14 chars (up to MAXPATHLEN) and can include subdirectories
  in their pathname.
- The UID/GID permission checks for access to a named semaphore are now
  done via vaccess() rather than a home-rolled set of checks.
- Now that kernel semaphores have an associated file object, the various
  MAC checks for POSIX semaphores accept both a file credential and an
  active credential.  There is also a new posixsem_check_stat() since it
  is possible to fstat() a semaphore file descriptor.
- A small set of regression tests (using the ksem API directly) is present
  in src/tools/regression/posixsem.

Reported by:	kris (1)
Tested by:	kris
Reviewed by:	rwatson (lightly)
MFC after:	1 month
2008-06-27 05:39:04 +00:00
..
3dfx
3dfx_linux
aac
accf_data
accf_http
acpi Rewrite the EC driver event model. The main goal is to avoid 2007-09-24 16:59:06 +00:00
age Hook up age(4) to the build. 2008-05-19 01:53:47 +00:00
agp Move the agp(4) driver from sys/pci to sys/dev/agp. __FreeBSD_version was 2007-11-12 21:51:38 +00:00
aha
ahb
aic
aic7xxx
aio
amd
amr The AR_SCSI_PASSTHROUGH conditional no longer exists, remove it from the 2007-12-02 18:39:38 +00:00
an
aout
apm
ar
arcmsr
arcnet
arl
asmc Remove isa_if.h. 2008-04-07 11:26:13 +00:00
asr
ata
ath
ath_hal
ath_rate_amrr Always create opt_ah.h regardless of KERNBUILDDIR. 2008-06-23 00:51:34 +00:00
ath_rate_onoe don't let KERNBUILDDIR control whether we copy opt_ah.h 2008-05-30 03:36:52 +00:00
ath_rate_sample opt_ah.h is not constructed by config, it always comes from 2008-05-29 00:16:58 +00:00
aue
auxio
axe
bce
bfe
bge Add ofw_bus_if.h as a dependency on sparc64. Without this sparc64 kernel 2007-06-10 00:58:41 +00:00
bios
bktr Remove option headers that do not exist and are not used 2008-03-27 20:38:03 +00:00
bm Add support for the Apple Big Mac (BMAC) Ethernet controller, 2008-06-07 22:58:32 +00:00
bridgestp
cam Add the CAM 'SG' peripheral device. This device implements a subset of the 2007-04-07 19:40:58 +00:00
canbepm
canbus
cardbus
cbb
cd9660
cd9660_iconv
cdce
ce
ciss
cm
cmx Commit cmx(4), a driver for Omnikey CardMan 4040 PCMCIA smartcard readers. 2008-03-06 08:09:45 +00:00
cnw Add a module for cnw(4) and build it on i386. 2008-05-28 20:26:25 +00:00
coda Rather than having the Coda module use its own namecache, use the global 2008-02-13 13:06:22 +00:00
coda5 Remove coda_namecache from coda5 as well. We should probably GC coda5 2008-02-13 16:31:04 +00:00
coff
coretemp Add a driver for the on-die digital thermal sensor found on Intel Core 2007-08-15 19:26:03 +00:00
cp
cpufreq
crypto Integrate the Camellia Block Cipher. For more information see RFC 4132 2007-05-09 19:37:02 +00:00
cryptodev
cs
ctau
cue
cx
cxgb only build iw_cxgb on i386 and amd64 2008-05-06 02:31:27 +00:00
cyclic The cyclic code is in sys/cddl/dev/cyclic to be consistent with 2008-05-23 22:23:28 +00:00
dc
dcons Fix a breakage with "MODULES_WITH_WORLD=true make buildworld". 2007-06-01 00:23:34 +00:00
dcons_crom
de
digi
dpt On i386 compile the back-end with EISA support as well as the EISA 2007-04-10 20:33:31 +00:00
drm
dtrace Add the DTrace test kernel module so that people can run the tests. 2008-05-31 09:37:40 +00:00
dummynet
ed
elink
em This delta has a few important items: 2008-04-25 21:19:41 +00:00
en
ep
esp Don't build unused SBus front-ends for sun4v, don't build EBus front-ends 2008-05-04 14:59:25 +00:00
et Add et(4), a port of DragonFly's Agere ET1310 10/100/Gigabit 2008-06-20 19:28:33 +00:00
ex
exca
ext2fs
fatm
fdc
fdescfs
fe
firewire
firmware Unbreak firmware.ko build without kernel. 2008-04-20 16:11:14 +00:00
fxp
gem
geom Add support for PC-9800 partition tables. 2008-03-28 17:58:55 +00:00
hatm
hifn
hme Don't build unused SBus front-ends for sun4v, don't build EBus front-ends 2008-05-04 14:59:25 +00:00
hpfs
hptiop Introduce a driver for the Highpoint RocketRAID 3xxx series of controllers. 2007-05-09 07:07:26 +00:00
hptmv
hptrr Add the 'hptrr' driver for supporting the following Highpoint RocketRAID 2007-12-15 00:56:17 +00:00
hwpmc Remove WARNS from here and compile with default kernel flags. 2008-02-21 11:09:59 +00:00
i2c The viapm module build had what appear to be some debugging CFLAGS left 2007-06-24 20:35:59 +00:00
ibcs2
ichwd
ida
ie
if_bridge
if_disc
if_edsc
if_ef
if_faith
if_gif
if_gre
if_lagg Rename the trunk(4) driver to lagg(4) as it is too similar to vlan trunking. 2007-04-17 00:35:11 +00:00
if_ndis
if_ppp
if_sl
if_stf
if_tap
if_tun
if_vlan
igb This update primarily addresses the ability to have both the em 2008-04-02 22:00:36 +00:00
iir
io
ip_mroute_mod Options spring cleanup: 2007-06-13 02:08:04 +00:00
ipdivert
ipfilter
ipfw Link pf 4.1 to the build: 2007-07-03 12:46:08 +00:00
ipfw_nat Move ipfw's nat code into its own kld: ipfw_nat. 2008-02-29 22:27:19 +00:00
ipmi
ips
ipw
ipwfw
iscsi Introduce Danny Braniss' iSCSI initiator, version 2.0.99. Please read the 2007-07-24 15:35:02 +00:00
isp Don't build unused SBus front-ends for sun4v, don't build EBus front-ends 2008-05-04 14:59:25 +00:00
ispfw Don't build unused SBus front-ends for sun4v, don't build EBus front-ends 2008-05-04 14:59:25 +00:00
iwi
iwifw
iwn clear out crud 2008-05-22 21:53:15 +00:00
iwnfw Intel 4965 wireless driver (derived from openbsd driver of the same name) 2008-04-29 21:36:17 +00:00
ixgb
ixgbe Remove compile of tcp_lro since its now in netinet 2008-06-11 22:18:50 +00:00
jme Hook up jme(4) to the build. 2008-05-27 01:54:45 +00:00
joy
k8temp Connect k8temp(4) to the build. 2008-04-12 14:20:22 +00:00
kbdmux
krpc Add nfslockd and krpc modules. 2008-03-27 11:55:03 +00:00
kue
le Don't build unused SBus front-ends for sun4v, don't build EBus front-ends 2008-05-04 14:59:25 +00:00
lge
libalias The old PacketAlias* API is not exported when 2007-04-09 17:08:27 +00:00
libiconv
libmbpool
libmchain
linprocfs
linsysfs
linux Fix the dependency for the linux_support.s, explicitely add linux_assym.h. 2007-05-23 15:45:52 +00:00
lmc
lpt
mac_biba
mac_bsdextended
mac_ifoff
mac_lomac
mac_mls
mac_none
mac_partition
mac_portacl
mac_seeotheruids
mac_stub
mac_test
malo Multi-bss (aka vap) support for 802.11 devices. 2008-04-20 20:35:46 +00:00
mcd
md
mem
mfi Add the 'mfip' sub-driver for gaining SCSI-passthrough access to devices 2007-05-16 17:19:47 +00:00
mii Add et(4), a port of DragonFly's Agere ET1310 10/100/Gigabit 2008-06-20 19:28:33 +00:00
mlx
mly
mmc
mmcsd
mpt Add a new personality to mpt(4) devices to allow userland applications to 2008-05-06 20:49:53 +00:00
mqueue
msdosfs
msdosfs_iconv
mse
msk
mxge Add optional support to mxge for MSI-X interrupts and multiple receive 2008-01-15 20:34:49 +00:00
my
ncp
ncv
ndis
netgraph Remove netatm from HEAD as it is not MPSAFE and relies on the now removed 2008-05-25 22:11:40 +00:00
nfe
nfs4client
nfsclient
nfslockd Re-implement the client side of rpc.lockd in the kernel. This implementation 2008-06-26 10:21:54 +00:00
nfsserver
nge
nmdm
nsp
ntfs
ntfs_iconv
nullfs
nve
nvram Split /dev/nvram driver out of isa/clock.c for i386 and amd64. I have not 2007-10-26 03:23:54 +00:00
nwfs
nxge Merge Neterion if_nxge driver version 2.0.9.11230 with the following 2007-10-29 14:19:32 +00:00
oltr
opensolaris Add the DTrace kernel module makefiles. 2008-05-17 02:31:19 +00:00
padlock
patm
pccard
pcfclock
pcn
pf Link pf 4.1 to the build: 2007-07-03 12:46:08 +00:00
pflog
plip
pmc
portalfs
powermac_nvram
ppbus
ppc
ppi
pps
procfs
pseudofs
pst
puc
ral Multi-bss (aka vap) support for 802.11 devices. 2008-04-20 20:35:46 +00:00
ralfw Remove the non-existent rt2860 subdir. Note, the ralfw module is not used in 2008-06-26 18:58:01 +00:00
random
ray
rc
rc4
rdma add makefiles for rdma 2008-05-05 20:19:33 +00:00
re
reiserfs
rl
rndtest
rp
rue
rum Add support for Ralink Technology RT2501USB/RT2601USB devices. 2007-05-06 10:07:21 +00:00
s3
safe
sbni
sbsh
scc Don't build unused SBus front-ends for sun4v, don't build EBus front-ends 2008-05-04 14:59:25 +00:00
scd
scsi_low
sem Rework the lifetime management of the kernel implementation of POSIX 2008-06-27 05:39:04 +00:00
sf Update file list and Makefile after repocopying sf(4) from 2008-01-21 04:27:32 +00:00
sio
sis
sk
slhci Use .CURDIR when referring source code. This fixes build 2007-06-20 00:29:51 +00:00
smbfs
sn
snc
snp
sound Restore SUBDIR+= accidentally removed in the previous revision. 2008-05-04 16:02:45 +00:00
speaker
splash
sppp
sr
ste
stg
stge
streams
svr4
sym
syscons
sysvipc
ti
tl
tmpfs MFp4: 2007-06-29 05:23:15 +00:00
trm
twa Import version 3.60.03.006 of the TWA driver: 2007-05-09 04:16:32 +00:00
twe
tx
txp
uark
uart
ubsa
ubsec
ubser
uchcom Add Winchiphead (or Nanjin QinHeng Electronics) USB Serial converter driver. 2007-10-18 10:51:06 +00:00
ucom
ucycom
udav
udbp
udf
udf_iconv
ufm
ufoma
ufs
uftdi
ugen
uhid
uipaq
ukbd
ulpt
umass
umct
umodem
ums
unionfs
uplcom
ural
urio
usb
uscanner
uslcom Remove option headers that do not exist and are not used 2008-03-27 20:38:03 +00:00
utopia
uvisor
uvscom
vesa
vge
vkbd
vpo
vr Update file list and Makefile after repocopying vr(4) from 2008-03-11 03:50:57 +00:00
vx
wb
wi
wlan enable IEEE80211_AMDPU_AGE by default 2008-05-03 17:06:59 +00:00
wlan_acl Multi-bss (aka vap) support for 802.11 devices. 2008-04-20 20:35:46 +00:00
wlan_amrr Multi-bss (aka vap) support for 802.11 devices. 2008-04-20 20:35:46 +00:00
wlan_ccmp Multi-bss (aka vap) support for 802.11 devices. 2008-04-20 20:35:46 +00:00
wlan_rssadapt Multi-bss (aka vap) support for 802.11 devices. 2008-04-20 20:35:46 +00:00
wlan_tkip Multi-bss (aka vap) support for 802.11 devices. 2008-04-20 20:35:46 +00:00
wlan_wep Multi-bss (aka vap) support for 802.11 devices. 2008-04-20 20:35:46 +00:00
wlan_xauth Multi-bss (aka vap) support for 802.11 devices. 2008-04-20 20:35:46 +00:00
wpi Remove option headers that do not exist and are not used 2008-03-27 20:38:03 +00:00
wpifw Initial Import of wpi driver based on p4 changeset 128641. 2007-11-05 11:47:19 +00:00
xe
xfs
xl
zfs Add atomic operations for ZFS/sparc64. 2008-04-11 22:59:33 +00:00
zlib
zyd Makefile for building zyd kernel module. 2007-08-29 21:04:26 +00:00
Makefile Add et(4), a port of DragonFly's Agere ET1310 10/100/Gigabit 2008-06-20 19:28:33 +00:00
Makefile.inc