# fdescfs nodup lookup can self-deadlock during final file close

## Summary

A metadata lookup through an fdescfs mount configured with `nodup` can
stall during a concurrent descriptor close. The lookup holds the target
vnode lock when it drops the final file reference. That drop runs close
in the lookup thread, which then tries to acquire the same lock.

## Mount prerequisite

FreeBSD leaves `nodup` off by default. A plain fdescfs mount uses
descriptor-duplication semantics. The FreeBSD Samba 4.24 port's startup
script explicitly mounts fdescfs with `nodup` under its PID directory.
[FreeBSD fdescfs manual](https://man.freebsd.org/cgi/man.cgi?manpath=FreeBSD+15.0-RELEASE&query=fdescfs&sektion=4) ·
[Samba startup script](https://cgit.freebsd.org/ports/tree/net/samba424/files/samba_server.in)

`nodup` is required for this specific self-deadlock path. It selects the
lookup that locks the underlying vnode before dropping the file reference.
A plain fdescfs lookup skips that path. The archived p6 reproduction used
`nodup`. The requirement follows from the source and observed stack. The
archived evidence contains no plain-mount control run.

## Affected builds and impact

| Environment | Evidence |
| --- | --- |
| FreeBSD 15.1-RELEASE-p1, amd64, `releng/15.1-n283582-0f691888dc56` | Incident stack and live dump. The dump confirms the lookup worker owns the underlying ZFS vnode lock. |
| FreeBSD 15.1-RELEASE-p6, amd64, `releng/15.1-n283643-95719d8a895b GENERIC` | Reproduced on attempt 1 in an isolated, stock single-vCPU guest with a separate scratch ZFS pool. |

- **Guest reproduction.** The p6 run confirmed a process stall on a
  private scratch ZFS filesystem.
- **Impact on another process.** A p1 dump shows an unrelated `ls`
  waiting on the ZFS vnode lock held by the stalled worker.
- **Reported system-wide impact.** The reporter observed a system-wide
  hang when the locked directory was critical to OS operation. The
  reporter describes running from an unprivileged local account after
  an administrator mounted fdescfs with `nodup`. The system-wide
  outcome and privilege context await independent confirmation.

The affected version range beyond the two listed builds is unknown.

## Expected and observed behavior

**Expected.** Lookup and final close complete without the calling thread
trying to reacquire its own vnode lock. A lookup that loses the descriptor
race may return a normal lookup error.

**Observed.** In the p6 guest, the lookup worker stayed in the kernel and
the process remained present after `SIGKILL`.

## Reproduction

Run only in a disposable bhyve guest with its own scratch disk. The payload
creates a ZFS pool on the guest's `vtbd2` disk and mounts fdescfs with
`nodup`. It races metadata lookups against closing a descriptor for a ZFS
directory. Directory scanning and disabled ARC data caching widen the race
window. This is a timing-based reproducer.

From this project's root on a FreeBSD bhyve host with FTF's prerequisites
installed, run:

```sh
VM_DIR=/tmp/ftf ./ftf/vm-run.sh --output-dir ./results --boot-timeout 60 \
    15.1 ./test_dir
```

FTF calls `test_dir/ftf-build.sh` on the host to compile and stage the
static reproducer. Use a compiler targeting the guest's FreeBSD ABI.
Runtime guests contain no compiler. Attach `test_dir/repro.c`,
`test_dir/Makefile`, `test_dir/ftf-build.sh`, and `test_dir/run.sh`
together with the pinned FTF source and its provenance, so recipients
can run this command independently of the submitter's checkout.

The expected test verdict is `REPRODUCED`. The harness reports success
when it observes the expected hang. Interpret that result with the captured
stacks and lock evidence below. A surviving PID alone establishes a
suspected hang.

## CURRENT testing status

The December 1, 2026 smoke run booted
`16.0-CURRENT main-n291880-6b2f09d0b9e0 GENERIC`. It tested guest startup
only. The archived focused run on
`main-n290699-c502df9eb193` was interrupted. These runs establish no
conclusion about reproduction or a fix on CURRENT.
[December smoke metadata](results/16-current/run.yDBSK0/results.json) ·
[Interrupted focused run metadata](results/16-current/run.Ygvq1F/results.json)

## Kernel evidence

**Selected guest stack** — The frames below are from PID 526, TID 100227,
in the stock p6 guest. The process had accumulated 45.098922 seconds of
system CPU time at capture. Frame order and offsets are preserved.

```text
_vn_lock_fallback+0x9e vn_close1+0x1b0 vn_closefile+0x3d _fdrop+0x11
fdesc_get_ino_alloc+0x91 vn_vget_ino_gen+0x16b fdesc_lookup+0x145
vfs_lookup+0x401 namei+0x26d kern_statat+0xfe sys_fstatat+0x27
```

**Independent incident dump observation** — On p1, the file's vnode and the
callback's output vnode matched. The vnode lock owner matched the stalled
worker. The file reference count was zero and the callback's `fdropped` flag
was still clear, consistent with a stall inside the final drop before the
callback could mark it complete. The dump was decoded with CTF and symbol
tables using archived binaries whose hashes matched the incident artifacts.

**Derived lock comparison from a single p1 dump**

| Field | Value |
| --- | --- |
| Waiting `ls` process and thread | PID 6844, TID 100718 |
| Wait channel and ZFS vnode lock address | `0xfffff800c1aa7070` |
| Lock owner/state word | `0xfffff8001c6a6002` |
| Owner address after masking the low five flag bits | `0xfffff8001c6a6000` |
| Matching `dust` worker | PID 6417, TID 100877, thread address `0xfffff8001c6a6000` |

**Source interpretation** — In `sys/fs/fdescfs/fdesc_vnops.c`,
`fdesc_lookup()` passes `LK_EXCLUSIVE` to `vn_vget_ino_gen()`. In the
`nodup` vnode path, `fdesc_get_ino_alloc()` calls `vget()` before
`fdrop()`. If that drop is final, `vn_closefile()` reaches
`vn_close1()` in `sys/kern/vfs_vnops.c`. On the observed ZFS path it requests a shared lock
with `LK_RETRY` while the worker still holds the exclusive lock. The holder and waiter are the same
thread, so the caller cannot unwind and unlock the vnode. The p6 stack
matches this path. Direct lock-owner evidence comes from the p1 dump.

## Workaround and fix status

Where applications can tolerate the descriptor-duplication semantics of a
regular fdescfs mount, removing the `nodup` mount option is a candidate
workaround for this path. Compatibility and workaround behavior have not
been tested in the affected deployment.

A candidate kernel change would retain the target vnode independently,
drop the lookup's file reference before acquiring the target vnode lock,
and then complete vnode acquisition. Review failed acquisition and doomed
vnode cleanup, parent relocking, and preservation of descriptor metadata.
The candidate has not been implemented or validated here.

## Attachments and attribution

The inline excerpts summarize the p6 guest diagnostics and the p1 dump
observations. Supporting material includes the guest console excerpt,
guest build and image metadata, and derived p1 lock comparison.

OpenAI Codex assisted with the public duplicate search and preparation
of this report.

---

## Where and how to submit

Use private security triage initially because the report includes possible
local denial of service affecting essential filesystem access. Email
`secteam@FreeBSD.org`. For greater confidentiality, encrypt with the
Security Officer PGP key linked in the official guidance and send to
`security-officer@FreeBSD.org`. This is a kernel issue, so the operating
system Security Team is the appropriate contact even when Samba provides
the mount.
[FreeBSD security reporting guidance](https://www.freebsd.org/security/reporting/)

Suggested subject is `Private report: fdescfs nodup lookup self-deadlock during final close`.
Send the report through “Attachments and attribution” as the message body,
with the reviewed reproducer and diagnostic attachments. Ask for a tracking
reference, security classification, and coordinated disclosure. Include any
handling restrictions and preferred attribution. Let the team determine
whether advisory/CVE or errata handling is appropriate.

If the team directs public bug tracking, file at
[FreeBSD Bugzilla](https://bugs.freebsd.org/bugzilla/), using the Base System
product and the kernel component offered by the form. Carry over the
version identities, reproduction steps, impact qualifications, and reviewed
attachments, and reference the private tracking number as directed.

## Submitter checklist

- Send the report above privately to `secteam@FreeBSD.org`. For encrypted
  reporting, use the Security Officer's PGP key and send to
  `security-officer@FreeBSD.org`. Ask for private triage, a tracking
  reference, and guidance on advisory, CVE, or errata handling.
  [FreeBSD security reporting guidance](https://www.freebsd.org/security/reporting/)
- Attach reviewed excerpts from the [guest console](results/15.1/run.fq85Wo/console.log#L168),
  [guest build and image metadata](results/15.1/run.fq85Wo/results.json),
  and [p1 dump analysis](../vfs-hang/dust-6417-analysis.md#12-fresh-dump-ls-waits-on-the-exact-lock-owned-by-dust).
  Keep the raw dump private. The guest harness passed because it observed
  the expected stall. A [second p6 run](results/15.1/run.t93D2N/console.log#L268)
  reported reproduction with incomplete diagnostics. Additional context is
  in the [engineering notes](ROOT-CAUSE.md) and [technical paper](fdesc-hang-paper.md).
- Add contact details, preferred credit if desired, and any automation or
  AI used during discovery beyond the assistance already disclosed.
- Public duplicate searches found no exact match. The direct Bugzilla
  query was inaccessible during the search. Prior reports cover root
  vnode locking, descriptor metadata on reopen, and truncation permissions.
  [D39207](https://reviews.freebsd.org/D39207) ·
  [D59886](https://reviews.freebsd.org/D59886) ·
  [FreeBSD-SA-26:91.fdescfs](https://lists.freebsd.org/archives/freebsd-announce/2026-November/000360.html)

- Package the reproducer and pinned runner, and replace local evidence links
  in the outgoing report with named attachments. Review logs for private
  paths and identifiers before sharing.
- Confirm the reporter's account of privileges and system-wide impact, or
  retain the current qualifications. List known successful and interrupted
  attempts without treating smoke tests as reproductions.
- A focused test on a recent CURRENT build and a plain-mount control would
  strengthen the report. Record them as pending until performed. A verified
  patch is also pending. These limitations can be disclosed in the initial
  report without delaying private triage.
