Bug 172334 - unionfs permits recursive union mounts; causes panic quickly
Summary: unionfs permits recursive union mounts; causes panic quickly
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 9.0-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: Jason A. Harmening
URL:
Keywords: crash
Depends on:
Blocks:
 
Reported: 2012-10-04 20:00 UTC by Enji Cooper
Modified: 2025-12-26 07:38 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 Enji Cooper freebsd_committer freebsd_triage 2012-10-04 20:00:21 UTC
I accidentally got my invocation backwards, was impatient and tried the opposite form and it blew up looking in the VOP code when I did the following:

1. Boot 9.0-RELEASE as a LiveCD.
2. Execute the following commands:
   mkdir /tmp/etc
   mount_unionfs /tmp/etc /etc
   mount_unionfs /etc /tmp/etc
3. Accessing either /etc or /tmp/etc after that should result in a panic.
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2012-10-05 03:14:13 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-fs

Over to maintainer(s).
Comment 2 daichi 2012-10-18 09:17:59 UTC
You could around this issue with a following patch.

  http://people.freebsd.org/~daichi/unionfs/unionfs-cross-mount3.diff

And above patch is rejected at ml discussion some years ago. 
We need more radical changes to improve this kind of issues.

--
Daichi GOTO
81-42-316-7945 | daichi@ongs.co.jp | http://www.ongs.co.jp
LinkedIn: http://linkedin.com/in/daichigoto
Comment 3 Enji Cooper freebsd_committer freebsd_triage 2013-06-12 01:10:20 UTC
I finally got around to testing this. Yup -- the patch looks good to me.
Thank you Daichi!
-Garrett
Comment 4 Brad Davis freebsd_committer freebsd_triage 2015-07-30 21:41:30 UTC
ping
Comment 5 Eitan Adler freebsd_committer freebsd_triage 2018-05-28 19:47:31 UTC
batch change:

For bugs that match the following
-  Status Is In progress 
AND
- Untouched since 2018-01-01.
AND
- Affects Base System OR Documentation

DO:

Reset to open status.


Note:
I did a quick pass but if you are getting this email it might be worthwhile to double check to see if this bug ought to be closed.
Comment 6 Jason A. Harmening freebsd_committer freebsd_triage 2024-02-04 00:58:59 UTC
See comments 9 & 10 on https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=275871 for a more recent reproduction.
Comment 7 commit-hook freebsd_committer freebsd_triage 2025-12-12 06:33:10 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=0247b4018de2c341ac59a585362c10044cea86ad

commit 0247b4018de2c341ac59a585362c10044cea86ad
Author:     Jason A. Harmening <jah@FreeBSD.org>
AuthorDate: 2025-11-29 07:53:16 +0000
Commit:     Jason A. Harmening <jah@FreeBSD.org>
CommitDate: 2025-12-12 06:32:05 +0000

    unionfs: detect common deadlock-producing mount misconfigurations

    When creating a unionfs mount, it's fairly easy to shoot oneself
    in the foot by specifying upper and lower file hierarchies that
    resolve back to the same vnodes.  This is fairly easy to do if
    the sameness is not obvious due to aliasing through nullfs or other
    unionfs mounts (as in the associated PR), and will produce either
    deadlock or failed locking assertions on any attempt to use the
    resulting unionfs mount.

    Leverage VOP_GETLOWVNODE() to detect the most common cases of
    foot-shooting at mount time and fail the mount with EDEADLK.
    This is not meant to be an exhaustive check for all possible
    deadlock-producing scenarios, but it is an extremely cheap and
    simple approach that, unlike previous proposed fixes, also works
    in the presence of nullfs aliases.

    PR:             172334
    Reported by:    ngie, Karlo Miličević <karlo98.m@gmail.com>
    Reviewed by:    kib, olce
    Tested by:      pho
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D53988

 sys/fs/unionfs/union_vfsops.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
Comment 8 Mark Linimon freebsd_committer freebsd_triage 2025-12-12 17:40:24 UTC
^Triage: committed via D53988.
Comment 9 commit-hook freebsd_committer freebsd_triage 2025-12-26 07:38:39 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=da6f395119a5eb1ed1dad56874c1c55a5721e220

commit da6f395119a5eb1ed1dad56874c1c55a5721e220
Author:     Jason A. Harmening <jah@FreeBSD.org>
AuthorDate: 2025-11-29 07:53:16 +0000
Commit:     Jason A. Harmening <jah@FreeBSD.org>
CommitDate: 2025-12-26 06:38:06 +0000

    unionfs: detect common deadlock-producing mount misconfigurations

    When creating a unionfs mount, it's fairly easy to shoot oneself
    in the foot by specifying upper and lower file hierarchies that
    resolve back to the same vnodes.  This is fairly easy to do if
    the sameness is not obvious due to aliasing through nullfs or other
    unionfs mounts (as in the associated PR), and will produce either
    deadlock or failed locking assertions on any attempt to use the
    resulting unionfs mount.

    Leverage VOP_GETLOWVNODE() to detect the most common cases of
    foot-shooting at mount time and fail the mount with EDEADLK.
    This is not meant to be an exhaustive check for all possible
    deadlock-producing scenarios, but it is an extremely cheap and
    simple approach that, unlike previous proposed fixes, also works
    in the presence of nullfs aliases.

    PR:             172334
    Reported by:    ngie, Karlo Miličević <karlo98.m@gmail.com>
    Reviewed by:    kib, olce
    Tested by:      pho
    Differential Revision:  https://reviews.freebsd.org/D53988

    (cherry picked from commit 0247b4018de2c341ac59a585362c10044cea86ad)

 sys/fs/unionfs/union_vfsops.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)