Zfs Core
Why FreeBSD left a zero-byte core dump on ZFS
When the Red Baron browser crashed on FreeBSD, it left a core file with nothing in it. A tiny native program reproduced the same failure, and pre-filling the destination file changed the outcome. The evidence points to a ZFS direct I/O path that tries to pin a kernel buffer using the crashing process’s address map. Disabling ZFS direct I/O restored fresh core dumps on the affected host. The exact failing function remains a source-based inference.
Contents
- §1. The crash and the missing dump
- §2. Taking the browser out of the test
- §3. Following the first write
- §4. Testing the direct I/O explanation
- §5. Reproducer and evidence
1. The crash and the missing dump
A core dump is a snapshot of a process at the time it crashes. A debugger can use it to inspect the process’s memory and registers. In this case, the core file’s timestamp matched a kernel log entry for the same process.
Selected output from the original host
Nov 5 02:13:28 mba kernel: Failed to write core file for process redbaron_3.10 (error 14)
Nov 5 02:13:28 mba kernel: pid 23934 (redbaron_3.10), jid 0, uid 1001: exited on signal 11 (no core dump - bad address)
Observation. FreeBSD tried to write the dump and returned error 14, or EFAULT. The original investigation verified that core dumps were enabled, the diagnostic shell had an unlimited core size, and disk space was available.
2. Taking the browser out of the test
The browser ran through Linux compatibility with a preload shim. A native FreeBSD amd64 program made it possible to test core writing without either dependency. Its entry point executes one instruction that deliberately raises SIGILL.
Annotated reconstruction of the reproducer’s entry point
void
_start(void)
{
__asm__ volatile("ud2"); /* Raise SIGILL so FreeBSD attempts a core dump. */
__builtin_unreachable();
}
Observation. The native program also left an empty core. On the original host, pre-filling the destination with 4 KiB or 8 KiB still gave an empty core. Pre-fills from 16 KiB through 256 KiB in the tested size sweep yielded a 143,360-byte core. The native core opened in LLDB at _start.
Correction (see §3). It was tempting to explain the result by the number of bytes already in the file. A follow-up wrote 128 KiB, flushed it, then truncated the file back to zero before crashing the program. The resulting core still had 143,360 bytes. The file’s logical size at the time of the crash could no longer explain the result.
3. Following the first write
Annotated reconstruction from the affected host’s source. FreeBSD’s core_vn_write() requests IO_DIRECT. The ELF header and notes come from a kernel buffer marked UIO_SYSSPACE in sbuf_drain_core_output(). The buffer has a 16 KiB capacity. In OpenZFS, zfs_setup_direct() can send an aligned write down the direct I/O path, but it falls back to buffered I/O for a write shorter than the file’s internal ZFS block size, zp->z_blksz.
On the FreeBSD direct I/O path, zfs_uio_iov_step() and zfs_uio_hold_pages() can reach code that pins pages through the current process’s user VM map. Pinning keeps memory pages available while the I/O is in progress. The kernel buffer holding the core header lives outside that user map, so looking for its pages there can return EFAULT.
Inference. The first header write can fail after the destination has been created or truncated but before any bytes reach it. The follow-up in §2 fits the source condition because a large internal ZFS block can send a short header write through buffered I/O even after the file’s logical size returns to zero. A newly created file could also report a large st_blksize, so that value alone did not establish which path the write took. DTrace was unavailable on the affected host, leaving the exact error return unconfirmed by a live probe.
4. Testing the direct I/O explanation
The strongest control was to keep the host and reproducer the same and change only vfs.zfs.dio_enabled. A separate bhyve run checked whether the failure also occurred on FreeBSD 15.1.
Observed results from the host comparison and guest console
| Environment | ZFS direct I/O | Fresh core | Pre-filled core |
|---|---|---|---|
| FreeBSD 16.0-CURRENT host | Enabled | 0 bytes | Nonempty |
| Same host and executable | Disabled | 147,456 bytes | 147,456 bytes |
| FreeBSD 15.1-RELEASE-p7 amd64 bhyve guest | Enabled | 0 bytes | 143,360 bytes |
Selected output from the bhyve guest
vfs.zfs.dio_enabled: 0 -> 1
Failed to write core file for process core_test (error 14)
Fresh core file: 0 bytes
Pre-filled core file: 143360 bytes
The same-host comparison verified a workaround. Disabling direct I/O changes behavior system-wide. Pre-filling the destination worked for the tested file and avoided that global change. A kernel fix would need to keep a kernel-space buffer out of any path that assumes a user-space address. The investigation verified the workaround. The first affected version and a kernel fix remain open.
5. Reproducer and evidence
The standalone script builds the native test program, runs both cases, and prints the resulting sizes. The README covers prerequisites and bhyve setup. The bug report draft records the affected builds and retains the relevant console excerpt. A passing script run means the comparison completed. Read the fresh core size to see whether the failure reproduced.