Page MenuHomeFreeBSD

if_ovpn: Destroy cloned interfaces via a prison removal callback
ClosedPublic

Authored by markj on Fri, Jul 25, 2:22 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Aug 21, 2:54 AM
Unknown Object (File)
Mon, Aug 18, 10:40 PM
Unknown Object (File)
Thu, Aug 14, 11:12 PM
Unknown Object (File)
Thu, Aug 14, 12:10 AM
Unknown Object (File)
Fri, Aug 1, 10:58 AM
Unknown Object (File)
Tue, Jul 29, 6:11 AM
Unknown Object (File)
Mon, Jul 28, 4:28 PM
Unknown Object (File)
Mon, Jul 28, 11:51 AM

Details

Summary

A if_ovpn interface carries a reference to a socket, which has a
credential reference, which holds a reference on the containing prison
and prevents SYSUNINITs from being invoked. So, register a
PR_METHOD_REMOVE callback and destroy the cloner from there instead,
since that mechanism doesn't require the prison refcount to drop to zero
first.

This fixes a bug where jails get left stuck in the DYING state after
running if_ovpn regression tests.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 65802
Build 62685: arc lint + arc unit

Event Timeline

markj requested review of this revision.Fri, Jul 25, 2:22 PM

Should we unconditionally detach the V_ovpn_cloner cloner in the non-VIMAGE case? Or under MOD_UNLOAD?
If I'm reading this right we wouldn't do so now, so we could end up unloading if_ovpn.ko and being left with the cloner functions pointing to now uninitialised memory.

Be sure to detach the root VNET's cloner during module unload.

In D51526#1178362, @kp wrote:

Should we unconditionally detach the V_ovpn_cloner cloner in the non-VIMAGE case? Or under MOD_UNLOAD?
If I'm reading this right we wouldn't do so now, so we could end up unloading if_ovpn.ko and being left with the cloner functions pointing to now uninitialised memory.

Yes, you're completely right. I think it has to happen under MOD_UNLOAD.

sys/net/if_ovpn.c
2608

I think I'd feel better if we did V_ovpn_cloner = NULL here, because I can't quite convince myself that we're not going to double-detach the host vnet's cloner on module unload.

markj marked an inline comment as done.

Defend against double detaches of the cloner.

sys/net/if_ovpn.c
2605
/usr/src/sys/net/if_ovpn.c:2796:23: error: incompatible pointer types passing 'struct prison *' to parameter of type 'struct ucred *' [-Werror,-Wincompatible-pointer-types]
 2796 |         if (prison_owns_vnet(pr)) {
      |                              ^~
/usr/src/sys/sys/jail.h:438:37: note: passing argument to parameter here
  438 | bool prison_owns_vnet(struct ucred *);
      |                                     ^
1 error generated.
sys/net/if_ovpn.c
2605

Sorry, yes, this depends on D51524. I forgot to create a link in the patch stack.

Ah, that makes sense. I was pretty surprised that your patch didn't build.

This revision is now accepted and ready to land.Mon, Jul 28, 3:06 PM