freebsd-skq/sys/security
attilio 683d7a54ce Fix a deficiency in the selinfo interface:
If a selinfo object is recorded (via selrecord()) and then it is
quickly destroyed, with the waiters missing the opportunity to awake,
at the next iteration they will find the selinfo object destroyed,
causing a PF#.

That happens because the selinfo interface has no way to drain the
waiters before to destroy the registered selinfo object. Also this
race is quite rare to get in practice, because it would require a
selrecord(), a poll request by another thread and a quick destruction
of the selrecord()'ed selinfo object.

Fix this by adding the seldrain() routine which should be called
before to destroy the selinfo objects (in order to avoid such case),
and fix the present cases where it might have already been called.
Sometimes, the context is safe enough to prevent this type of race,
like it happens in device drivers which installs selinfo objects on
poll callbacks. There, the destruction of the selinfo object happens
at driver detach time, when all the filedescriptors should be already
closed, thus there cannot be a race.
For this case, mfi(4) device driver can be set as an example, as it
implements a full correct logic for preventing this from happening.

Sponsored by:	Sandvine Incorporated
Reported by:	rstone
Tested by:	pluknet
Reviewed by:	jhb, kib
Approved by:	re (bz)
MFC after:	3 weeks
2011-08-25 15:51:54 +00:00
..
audit Fix a deficiency in the selinfo interface: 2011-08-25 15:51:54 +00:00
mac Add the fo_chown and fo_chmod methods to struct fileops and use them 2011-08-16 20:07:47 +00:00
mac_biba Update device-labeling logic for Biba, LOMAC, and MLS to recognize new-style 2010-03-02 15:05:48 +00:00
mac_bsdextended Add hierarchical jails. A jail may further virtualize its environment 2009-05-27 14:11:23 +00:00
mac_ifoff Rather than having MAC policies explicitly declare what object types 2009-01-10 10:58:41 +00:00
mac_lomac Update device-labeling logic for Biba, LOMAC, and MLS to recognize new-style 2010-03-02 15:05:48 +00:00
mac_mls Update device-labeling logic for Biba, LOMAC, and MLS to recognize new-style 2010-03-02 15:05:48 +00:00
mac_none Rather than having MAC policies explicitly declare what object types 2009-01-10 10:58:41 +00:00
mac_partition Rather than having MAC policies explicitly declare what object types 2009-01-10 10:58:41 +00:00
mac_portacl Fix typos. 2010-11-09 10:59:09 +00:00
mac_seeotheruids sysctl(9) cleanup checkpoint: amd64 GENERIC builds cleanly. 2011-01-12 19:54:14 +00:00
mac_stub Add the fo_chown and fo_chmod methods to struct fileops and use them 2011-08-16 20:07:47 +00:00
mac_test Add the fo_chown and fo_chmod methods to struct fileops and use them 2011-08-16 20:07:47 +00:00