kevans 43aa0eb3b2 tun(4): Don't allow open of open or dying devices
Previously, a pid check was used to prevent open of the tun(4); this works,
but may not make the most sense as we don't prevent the owner process from
opening the tun device multiple times.

The potential race described near tun_pid should not be an issue: if a
tun(4) is to be handed off, its fd has to have been sent via control message
or some other mechanism that duplicates the fd to the receiving process so
that it may set the pid. Otherwise, the pid gets cleared when the original
process closes it and you have no effective handoff mechanism.

Close up another potential issue with handing a tun(4) off by not clobbering
state if the closer isn't the controller anymore. If we want some state to
be cleared, we should do that a little more surgically.

Additionally, nothing prevents a dying tun(4) from being "reopened" in the
middle of tun_destroy as soon as the mutex is unlocked, quickly leading to a
bad time. Return EBUSY if we're marked for destruction, as well, and the
consumer will need to deal with it. The associated character device will be
destroyed in short order.

MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D20033
2019-04-25 13:46:12 +00:00
..
2018-05-31 09:11:21 +00:00
2019-04-17 17:18:43 +00:00
2019-04-17 17:18:43 +00:00
2019-03-09 01:12:59 +00:00
2019-04-17 17:18:43 +00:00
2018-11-26 13:42:18 +00:00
2019-04-24 13:32:04 +00:00
2019-03-15 11:08:44 +00:00
2018-06-16 19:21:09 +00:00
2017-07-24 03:59:50 +00:00
2018-11-26 13:42:18 +00:00