Bug 222951 - Re-starting a jail with mount.devfs mounts devfs multiple times
Summary: Re-starting a jail with mount.devfs mounts devfs multiple times
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 11.1-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-jail (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-12 13:07 UTC by VK
Modified: 2023-01-17 10:02 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description VK freebsd_triage 2017-10-12 13:07:17 UTC
Starting a jail that's configured with 'mount.devfs' with `jail -c` does not check if devfs is already mounted and mounts it again.

The problem seems to be when the (nopersist) jail is stopped by itself because all the processes in it have exited, so it wasn't explicitly `jail -r`. When that happens, devfs is not unmounted.

So next time the jail is started, devfs is mounted again, resulting with multiple mounts of devfs into $JAIL_ROOT/dev:

> % mount | grep /zroot/jails/test/dev
> devfs on /zroot/jails/test/dev (devfs, local, multilabel)
> devfs on /zroot/jails/test/dev (devfs, local, multilabel)
> devfs on /zroot/jails/test/dev (devfs, local, multilabel)
> devfs on /zroot/jails/test/dev (devfs, local, multilabel)

If the jail is explicitly stopped with `jail -r`, devfs is unmounted.
Comment 1 Robert Wing freebsd_committer freebsd_triage 2021-11-11 00:59:57 UTC
proposed fix: https://reviews.freebsd.org/D32934
Comment 2 Zhenlei Huang freebsd_committer freebsd_triage 2023-01-17 10:02:31 UTC
(In reply to VK from comment #0)

> The problem seems to be when the (nopersist) jail is stopped by itself because all
> the processes in it have exited, so it wasn't explicitly `jail -r`. When that 
> happens, devfs is not unmounted.

For non-persist jails I think this is the expected behavior.
`mount.devfs` is a pseudo-parameter and as per jail(8):
>  There are pseudo-parameters that are not passed to the kernel, but are
>     used by jail to set up the jail environment, often by running specified
>     commands when jails are created or removed.


> So next time the jail is started, devfs is mounted again, resulting with multiple 
> mounts of devfs into $JAIL_ROOT/dev:

Maybe we can teach /usr/sbin/jail to check existing mount of devfs(5) before starting jails.