aboutsummaryrefslogtreecommitdiff
path: root/sys/security
diff options
context:
space:
mode:
authorAttilio Rao <attilio@FreeBSD.org>2011-08-25 15:51:54 +0000
committerAttilio Rao <attilio@FreeBSD.org>2011-08-25 15:51:54 +0000
commit6aba400a7055ed2427c6aa297774fb91f5d8db79 (patch)
treebb41d1180cbc15eb092da87c3197b83cc6d4191f /sys/security
parent745e9ba27db9bbf6b4c449507740bc9acc4dabee (diff)
downloadsrc-6aba400a7055ed2427c6aa297774fb91f5d8db79.tar.gz
src-6aba400a7055ed2427c6aa297774fb91f5d8db79.zip
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
Notes
Notes: svn path=/head/; revision=225177
Diffstat (limited to 'sys/security')
-rw-r--r--sys/security/audit/audit_pipe.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/sys/security/audit/audit_pipe.c b/sys/security/audit/audit_pipe.c
index a8db1135db76..a953eb0200da 100644
--- a/sys/security/audit/audit_pipe.c
+++ b/sys/security/audit/audit_pipe.c
@@ -646,6 +646,7 @@ audit_pipe_free(struct audit_pipe *ap)
cv_destroy(&ap->ap_cv);
AUDIT_PIPE_SX_LOCK_DESTROY(ap);
AUDIT_PIPE_LOCK_DESTROY(ap);
+ seldrain(&ap->ap_selinfo);
knlist_destroy(&ap->ap_selinfo.si_note);
TAILQ_REMOVE(&audit_pipe_list, ap, ap_list);
free(ap, M_AUDIT_PIPE);