# bd-j exploit chain

Five chained PS4/PS5 flaws in BD-J Java sandbox and UDF driver yield a write-what-where into JIT memory, enabling arbitrary payload execution and kernel panic.

- Payout: $20,000
- Severity: high
- Program: PlayStation
- Found by: theflow0
- Disclosed: 2022-06-10
- Write-up quality: 9/10
- Original: https://hackerone.com/reports/1379975
- Library page: https://bugbountylibrary.com/r/h1%3A1379975
- Tags: area:os domain:desktop impact:privesc impact:rce kind:bounty platform:hackerone sev:high tech:java technique:chained technique:source-review vuln:access-control vuln:deserialization vuln:memory-corruption vuln:privilege-escalation

**Target:** PlayStation 4/5 BD-J Java runtime (com.sony.gemstack, com.oracle.security) and UDF filesystem driver
**Root cause:** Insecure Java deserialization and reflection under privileged context bypass the security manager; the compiler receiver thread trusts an attacker-supplied compiler_data pointer for a memcpy; the UDF driver memcpy's inf_len bytes into a sector_size buffer without bounds check.
**Steps:**
1. Craft malicious serialized `userprefs` object; place at RootCertManager.getOriginalPersistentRoot()/userprefs so UserPreferenceManagerImpl.readObject() instantiates attacker classes under doPrivileged.
2. Use com.oracle.security.Service.newInstance via a custom ProviderAccessor (setProviderAccessor) to instantiate restricted sun.* classes with public single-arg constructors.
3. Subclass a public non-final class implementing a Remote interface whose method throws RemoteException (e.g. FileImpl extends File implements FileInterface) to bypass permission checks in IxcProxy.invokeMethod and read /app0/.
4. Send a CompilerAgentRequest over the compiler socket with compiler_data pointing into JIT memory and payload bytes in the struct; the receiver memcpy's the struct to compiler_data + 0x28, achieving write-what-where and code execution.
5. Trigger vuln 5 by crafting a UDF image where /PWN/0 uses internal allocation with inf_len=4MB > sector_size, causing memcpy overflow and kernel panic; the payload is sent via `nc $PS4IP 1337 < payload.bin`.
6. Burn bd-jb .iso with UDF 2.5 and load on PS4 to run the chain.
**How found:** Source review of Sony's Java stack (gemstack, oracle security) for doPrivileged deserialization and reflection sinks; reverse engineering of the compiler receiver thread protocol to spot the trusted compiler_data pointer; auditing the open-source UDF driver for missing bounds checks on inf_len vs sector_size.
**Exploitation:** Attacker supplies a malicious BD-J disc image. Deserialization and reflection flaws escape the Java sandbox to privileged context; IxcProxy bypass leaks filesystem; the compiler thread write-what-where writes attacker payload into JIT memory for arbitrary code execution; UDF overflow crashes the kernel. No kernel exploit needed for JIT-level payloads.
**Escalation:** Chained four medium/high Java and native flaws to move from sandboxed BD-J to JIT code execution, then used UDF overflow to demonstrate kernel panic; enables pirated game loading and trivial kernel exploitation (no SMEP).
**Insight:** On console/embedded Java stacks, grep for readObject() inside AccessController.doPrivileged and for reflection helpers like Class.forName in provider/service classes; also treat any IPC struct field that is a pointer from the peer as a write-what-where candidate, and check open-source filesystem drivers bundled in firmware for memcpy length fields not validated against sector_size.

