Bug 289700 - unionfs: page fault in unionfs_find_node_status when closing a file within a socket's receive buffer
Summary: unionfs: page fault in unionfs_find_node_status when closing a file within a ...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 15.0-CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Jason A. Harmening
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-09-19 22:33 UTC by Alan Somers
Modified: 2025-11-04 04:30 UTC (History)
1 user (show)

See Also:
linimon: mfc-stable14?


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Somers freebsd_committer freebsd_triage 2025-09-19 22:33:07 UTC
Yesterday a user reported a panic in fusefs, bug 289686 .  From inspection, it appears that unionfs is vulnerable to the same panic.  The steps to reproduce the panic would be:

* A process opens a regular file on a unionfs file system
* That process sends the file descriptor through a unix domain socket, using SCM_RIGHTS
* That process closes the original file descriptor
* Whatever process (which might be the same one) that owns the receiving side of the unix domain socket closes it, without reading the file descriptor out first.
* That will cause unp_dispose to attempt to close every file descriptor residing in the socket's receive buffer.
* Several frames down the stack, that will call VOP_CLOSE with ap->a_td == NULL
* unionfs_close will pass ap->a_td to unionfs_find_node_status, without checking it.
* unionfs_find_node_status will attempt to dereference it, without checking it either.

Note that I haven't attempted to trigger the panic myself.
Comment 1 commit-hook freebsd_committer freebsd_triage 2025-10-14 18:50:23 UTC
A commit in branch main references this bug:

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

commit 880d180bb21c764aec6bd5bc8c0a6b07b8c2e199
Author:     Jason A. Harmening <jah@FreeBSD.org>
AuthorDate: 2025-10-13 20:40:46 +0000
Commit:     Jason A. Harmening <jah@FreeBSD.org>
CommitDate: 2025-10-14 18:48:51 +0000

    unionfs: fix NULL deref on closing an fd passed through SCM_RIGHTS

    If the last reference to an open file is contained in an SCM_RIGHTS
    message in a UNIX domain socket, and that message is discarded without
    being read out by the receiver, VOP_CLOSE will ultimately be called
    with ap->a_td == NULL.

    Change unionfs_close() to check for this condition instead of blindly
    passing the thread to unionfs_find_node_status() which will try to
    dereference it.  Also add relevant asserts on the node status lookup
    paths.

    PR:             289700
    Reported by:    asomers
    Reviewed by:    asomers, olce
    MFC after:      3 days
    Differential Revision: https://reviews.freebsd.org/D53079

 sys/fs/unionfs/union_subr.c  | 2 ++
 sys/fs/unionfs/union_vnops.c | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
Comment 2 commit-hook freebsd_committer freebsd_triage 2025-11-03 05:31:54 UTC
A commit in branch stable/15 references this bug:

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

commit 8a873a86059f13c829315b7867e188d27e314b51
Author:     Jason A. Harmening <jah@FreeBSD.org>
AuthorDate: 2025-10-13 20:40:46 +0000
Commit:     Jason A. Harmening <jah@FreeBSD.org>
CommitDate: 2025-11-03 04:32:50 +0000

    unionfs: fix NULL deref on closing an fd passed through SCM_RIGHTS

    If the last reference to an open file is contained in an SCM_RIGHTS
    message in a UNIX domain socket, and that message is discarded without
    being read out by the receiver, VOP_CLOSE will ultimately be called
    with ap->a_td == NULL.

    Change unionfs_close() to check for this condition instead of blindly
    passing the thread to unionfs_find_node_status() which will try to
    dereference it.  Also add relevant asserts on the node status lookup
    paths.

    PR:             289700
    Reported by:    asomers
    Reviewed by:    asomers, olce
    Differential Revision: https://reviews.freebsd.org/D53079

    (cherry picked from commit 880d180bb21c764aec6bd5bc8c0a6b07b8c2e199)

 sys/fs/unionfs/union_subr.c  | 2 ++
 sys/fs/unionfs/union_vnops.c | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
Comment 3 Mark Linimon freebsd_committer freebsd_triage 2025-11-03 13:21:46 UTC
^Triage: set mfc-stable14? flag.  Please just close if no MFC planned.