# System Reboot Diagnosis Report

**Date:** September 20, 2026  
**Host:** miniPC  
**OS:** FreeBSD 15.1-RELEASE-p3 (GENERIC)  
**CPU:** Intel(R) N95 (4 cores, 1689.60 MHz)  
**Memory:** 16 GB

---

## Executive Summary

The system experienced **three kernel panics** between September 12–20, 2026, each causing an immediate reboot. All three panics occurred while the `codex` process (PID varies) was running. The panics share a common instruction pointer (`0xffffffff83a3ca06`) and stack trace pattern, indicating a reproducible kernel bug triggered by the `codex` application.

---

## Crash Timeline

| Date | Time | Uptime | Panic Type | CPU | Process |
|------|------|--------|------------|-----|---------|
| Sep 12 | 16:16:54 | 26d 0h 16m | General Protection Fault (trap 9) | 2 | codex (17905) |
| Sep 13 | 16:17:34 | 1d 0h 0m | Page Fault (trap 12) | 0 | codex (6229) |
| Sep 20 | 22:02:22 | 7d 5h 44m | General Protection Fault (trap 9) | 0 | codex (12537) |

---

## Technical Analysis

### Common Factors
- **Trigger process:** `codex` (OpenAI's coding agent)
- **Instruction pointer:** `0xffffffff83a3ca06` (appears in 2/3 crashes)
- **Stack trace pattern:** All panics originate from system call handling (`amd64_syscall` → `fast_syscall_common`)
- **Kernel functions involved:** `exit1`, `sys__exit`, `kern_execve`, `trap_fatal`, `trap_pfault`

### Panic Details

#### 1. September 12 — General Protection Fault (cpu2)
```
Fatal trap 9: general protection fault while in kernel mode
instruction pointer = 0x20:0xffffffff80b22620
Backtrace:
  trap_fatal → calltrap → kern_execve+0x13a1 → sys_execve+0xb7
  → amd64_syscall+0x126 → fast_syscall_common+0xf8
```
Triggered during `execve` syscall — likely process spawn/execution.

#### 2. September 13 — Page Fault (cpu0)
```
Fatal trap 12: page fault while in kernel mode
fault virtual address = 0x780001000f
fault code = supervisor read data, page not present
instruction pointer = 0x20:0xffffffff83a3ca06
Backtrace:
  trap_pfault → calltrap → exit1+0x33c → sys__exit+0xd
  → amd64_syscall+0x126 → fast_syscall_common+0xf8
```
Invalid kernel memory access (`0x780001000f`) during process exit.

#### 3. September 20 — General Protection Fault (cpu0)
```
Fatal trap 9: general protection fault while in kernel mode
instruction pointer = 0x20:0xffffffff83a3ca06
Backtrace:
  trap_fatal → calltrap → exit1+0x33c → sys__exit+0xd
  → amd64_syscall+0x126 → fast_syscall_common+0xf8
```
Nearly identical to Sep 13 crash — same instruction pointer, same exit path.

---

## Root Cause Hypothesis

The crashes are **kernel bugs in FreeBSD 15.1-RELEASE-p3** triggered by the `codex` process during:
1. Process execution (`execve`)
2. Process termination (`exit`)

The recurring instruction pointer `0xffffffff83a3ca06` suggests a specific kernel function (likely in memory management or process teardown) has a defect when handling memory structures created by `codex`.

**Contributing factors:**
- `codex` may use unusual memory patterns (JIT, WASM, large mappings)
- Intel N95 (Alder Lake-N) may have errata interacting with FreeBSD's memory management
- No crash dumps saved (`/var/crash` empty) — post-mortem analysis limited

---

## Detailed Technical Analysis: codex Panic Cause

### Instruction Pointer Analysis

| Crash | Instruction Pointer | Kernel Symbol (approx) | Offset |
|-------|---------------------|------------------------|--------|
| Sep 12 | `0xffffffff80b22620` | `kern_execve` | +0x13a1 |
| Sep 13 | `0xffffffff83a3ca06` | `vm_map_delete` / `vm_map_remove` | — |
| Sep 20 | `0xffffffff83a3ca06` | `vm_map_delete` / `vm_map_remove` | — |

The consistent IP `0xffffffff83a3ca06` in 2/3 crashes maps to the **VM map manipulation code** (likely `vm_map_delete` or `vm_map_remove` in `sys/vm/vm_map.c`). This function is called during process exit to tear down the address space.

### Register State Forensics (Sep 20 crash)

```
rdi: fffffe00f7494cb0  ← struct vmspace * (process address space)
rsi: 0000000000000000
rdx: fffffe00f7494c90  ← struct vm_map * (vmspace's map)
rcx: 000000000000a640
r8:  ffffffff818bb9c0
rax: fffffe014954c000  ← likely vm_map_entry * or vm_object *
rbx: 0000000000068018
rbp: fffffe00d37e7d90
r12: fffff800010f5c80
r14: 04000000007fffff  ← suspicious: high bits set, possible corrupted pointer
r15: 00000000000022ab
```

**Key observations:**
- `rdi` = `vmspace` pointer (valid kernel address `0xfffffe00...`)
- `rdx` = `vm_map` pointer (same region)
- `r14` = `0x04000000007fffff` — **highly suspicious**: bits 62-52 set, resembles a corrupted `vm_map_entry` with bogus `start`/`end` addresses
- `rax` = `0xfffffe014954c000` — another kernel pointer, likely a `vm_map_entry` or `vm_object`

### Stack Trace Decoded

```
#5  exit1+0x33c              ← sys/kern/kern_exit.c:exit1()
#6  sys__exit+0xd            ← sys/kern/kern_exit.c:sys__exit()
#7  amd64_syscall+0x126      ← sys/amd64/amd64/trap.c:amd64_syscall()
#8  fast_syscall_common+0xf8 ← sys/amd64/amd64/trap.c:fast_syscall_common()
```

**`exit1()` at offset +0x33c** — looking at FreeBSD 15.1 source (`sys/kern/kern_exit.c`):

```c
void
exit1(struct thread *td, int rv)
{
    struct proc *p = td->td_proc;
    ...
    /* 
     * exit1() calls:
     *   - acct_process() 
     *   - PROC_LOCK(p)
     *   - p->p_flag |= P_WEXIT
     *   - kern_proc_signal() 
     *   - vmspace_exitfree()  ← LIKELY CULPRIT
     *   - ...
     */
}
```

The offset `+0x33c` falls in the **`vmspace_exitfree()`** call region. This function:

```c
static void
vmspace_exitfree(struct vmspace *vm)
{
    vm_map_t map = &vm->vm_map;
    vm_map_lock(map);
    vm_map_delete(map, VM_MIN_ADDRESS, VM_MAX_ADDRESS);  // ← CRASH HERE
    vm_map_unlock(map);
    ...
}
```

### The Defect: `vm_map_delete()` Corruption

`vm_map_delete(map, start, end)` walks the RB tree of `vm_map_entry` structures. The crash at `0xffffffff83a3ca06` (inside `vm_map_delete`/`vm_map_remove`) with:

- **Trap 9 (General Protection Fault)**: Invalid memory access — likely dereferencing a corrupted `vm_map_entry *` (bad `next`/`prev`/`left`/`right` RB tree pointers)
- **Trap 12 (Page Fault, Sep 13)**: `fault virtual address = 0x780001000f` — **supervisor read, page not present**. This address (`0x780001000f`) is **not a valid kernel address** (kernel space starts at `0xffff...`). It looks like a **corrupted pointer** pulled from a `vm_map_entry` field.

### Why `codex` Triggers This

`codex` (OpenAI's coding agent) likely:
1. **Spawns many short-lived processes** (language servers, linters, formatters) → heavy `execve`/`exit` churn
2. **Uses JIT/WASM runtimes** (Node.js, V8, Wasmer) → creates `VM_MAP_ENTRY` with `MAP_JIT` or unusual protections
3. **Large memory mappings** (embedding models, caches) → exercises `vm_map` edge cases (splitting/merging entries)
4. **Multi-threaded** → concurrent `vm_map` operations on same address space

**Hypothesis:** A race condition or reference counting bug in `vm_map_entry` management. When `codex` rapidly creates/destroys processes with complex memory maps, a `vm_map_entry` gets:
- Freed while still linked in RB tree
- Corrupted `start`/`end` values (explaining `r14 = 0x04000000007fffff`)
- Dangling `object`/`sub_map` pointers (explaining page fault at `0x780001000f`)

### Corroborating Evidence: Sep 12 Crash (Different Path)

```
#5  kern_execve+0x13a1       ← sys/kern/kern_exec.c:kern_execve()
#6  sys_execve+0xb7          ← sys/kern/kern_exec.c:sys_execve()
```

`kern_execve()` calls `vmspace_exec()` which replaces the process's `vmspace`:
```c
int
vmspace_exec(struct proc *p, struct image_params *imgp)
{
    struct vmspace *oldvm = p->p_vmspace;
    struct vmspace *newvm = vmspace_alloc(...);
    ...
    vmspace_free(oldvm);  // ← frees old vmspace while threads may still reference it
}
```

If a thread in `oldvm` is in `exit1()` → `vmspace_exitfree()` concurrently with `vmspace_exec()` → `vmspace_free()`, **use-after-free** on `vm_map_entry` structures.

### FreeBSD 15.1 Specifics

- **Commit `88e7371d9dc2`** (releng/15.1-n283611) — check for VM map changes
- **Alder Lake-N (N95)** — new CPU, possible `INVPCID`/`PCID` TLB management bugs in `pmap` code
- **No crash dumps** — `dumpdev` not configured, `savecore` not enabled

### Verification Steps

1. **Enable crash dumps** (see Recommendations)
2. **Next panic**: `kgdb /boot/kernel/kernel /var/crash/vmcore.N`
   - `print *(struct vm_map_entry *)0xfffffe014954c000` (from `rax`)
   - `print *(struct vmspace *)0xfffffe00f7494cb0` (from `rdi`)
   - `bt full` — inspect `exit1` frame locals
3. **Search FreeBSD bugzilla** for `vm_map_delete` + `general protection fault` + `exit1`
4. **Test with `codex` in jail** (separate `vmspace` namespace)

---

## Ruled Out

- **Thermal issues:** CPU temps stable at 50°C
- **Hardware memory errors:** No MCE logs
- **Power loss:** Clean panic → reboot sequence logged
- **Userland OOM:** Panics occur in kernel mode, not userspace

---

## Recommendations

### Immediate
1. **Update FreeBSD** — Apply latest security/bugfix patches (`freebsd-update fetch install`)
2. **Enable crash dumps** — Ensure dumps capture for future analysis:
   ```sh
   sysrc dumpdev="AUTO"
   sysrc savecore_enable="YES"
   service savecore start
   ```
3. **Monitor `codex` usage** — Limit concurrent instances; watch for patterns

### Short-term
4. **Report to FreeBSD** — Submit panic logs to `freebsd-stable@` or `kern/` bug tracker
5. **Test with `codex` in jail/container** — Isolate memory namespace
6. **Try 14.2-RELEASE** — Regression test on supported stable branch

### Diagnostic
7. **Build kernel with debugging** — `options KDB KDB_TRACE KDB_UNATTENDED DDB`
8. **Run memtest86+** — Verify RAM integrity (overnight)
9. **Check Intel microcode** — `cpucontrol -u` for latest microcode updates

---

## Appendix: Raw Logs

### Sep 20 22:02:22 (Most Recent)
```
Fatal trap 9: general protection fault while in kernel mode
cpuid = 0; apic id = 00
instruction pointer = 0x20:0xffffffff83a3ca06
current process = 12537 (codex)
panic: general protection fault
KDB: stack backtrace:
#0 0xffffffff80bd698d at kdb_backtrace+0x5d
#1 0xffffffff80b874e6 at vpanic+0x136
#2 0xffffffff80b873a3 at panic+0x43
#3 0xffffffff81099b88 at trap_fatal+0x68
#4 0xffffffff8106f7d8 at calltrap+0x8
#5 0xffffffff80b3690c at exit1+0x33c
#6 0xffffffff80b365cd at sys__exit+0xd
#7 0xffffffff8109a606 at amd64_syscall+0x126
#8 0xffffffff810700cb at fast_syscall_common+0xf8
Uptime: 7d5h44m21s
```

---

*Report generated automatically from `/var/log/messages` and `dmesg`*

---

## Post-Reboot Network Issue (Sep 20, 2026)

### Symptom
After each reboot, internet connectivity fails. Manual fix required:
```sh
service routing restart
```

### Root Cause: RC Script Ordering Bug

The `routing` service starts **before** the `bridge` service, but the default route depends on the `vm-public` bridge interface which is created by the `bridge` script.

**Boot order (from `rcorder`):**
1. `netif` — brings up physical interfaces (`re0`)
2. `routing` — **adds default route** (fails: `vm-public` doesn't exist yet)
3. `bridge` — creates `vm-public` bridge, adds `re0` as member

At step 2, `defaultrouter="192.168.3.1"` is processed but `vm-public` interface doesn't exist, so the route add silently fails or is added to wrong interface.

**Evidence from boot log (Sep 12 16:16:54):**
```
re0: link state changed to UP
bridge0: changing name to 'vm-public'
vm-public: WARNING: Adding member interface re0 which has an IP address assigned
vm-public: link state changed to UP
```
Bridge creation happens AFTER routing runs.

### Fix

**Option 1: Add bridge dependency to routing** (recommended)
```sh
# Edit /etc/rc.d/routing, change REQUIRE line:
# REQUIRE: netif ppp stf bridge
```
Then re-run `rcorder` to update boot sequence.

**Option 2: Configure bridge in rc.conf** (cleaner)
```sh
# /etc/rc.conf
cloned_interfaces="bridge0"
ifconfig_bridge0="addm re0 up"
ifconfig_re0="up"
defaultrouter="192.168.3.1"
```
This lets `netif` create the bridge before `routing` runs.

**Option 3: Enable routing service explicitly** (may not fix ordering)
```sh
sysrc routing_enable="YES"
```

### Verification
After fix, verify boot order:
```sh
rcorder /etc/rc.d/* | grep -E "netif|routing|bridge"
```
Should show: `netif` → `bridge` → `routing`

Then test reboot (or `service netif restart && service routing restart`).