Something something, kernel internals?

I have, for a long time, been specialising in “exotic systems”, taking a liking in undocumented environments such as iOS, its most secure components iBoot and SecureROM, and I want to document the internals of the PS4 and PS5 operating systems in a very organised, steamlined and detailed manner, in what is perhaps the first public endeavour of its kind, omitting semi-private forums and disorganised wikis.

As such:

What follows is a documentation of Orbis, the operating system of the PlayStation 4, and of its successor on the PlayStation 5. It is documented for educational purposes only, as a case study of an operating system’s internal workings. It is to the reader to perform more work on their systems if so they like.

I. Origins

For all intents and purposes, PS4 and PS5 are interchangeable.

The PS4’s operating system is Orbis, based off FreeBSD 9. It includes a list of proprietary syscalls, appended to this work and documented to the best of my ability, with prototypes and other useful information.

Sony had shipped BSD code before; the PS3’s network stack was BSD-derived and the PlayStation Vita’s operating system was built on BSD foundations as well. Futher explaining this, the BSD licence lets a vendor modify a kernel without forcing an open-source release. FreeBSD in particular brings a mature TCP/IP stack, a complete POSIX userland, the GEOM storage framework, and a hardened virtual memory system that had already survived two decades of servers, more or less fitting Sony’s requirements for an operating system for a machine that is, under the hood, an x86-64 PC with unusual memory and an unusual GPU.

Orbis is a codename that leaked a year before the console shipped in November 2013 and stuck to the operating system itself. The PS5’s operating system descends from an indepenent FreeBSD 11.0 fork and was codenamed Prospero, with 3 sysvec structures, “PS4 SELF” for retro-compat. with PS4 ELFs, “FreeBSD ELF64” for standard FreeBSD elfs though unused in practice and “Native SELF” for PS5 processes.

Sony built a second, private layer on top of FreeBSD, a dynamic linker that loads signed modules at runtime through dedicated syscalls, a sandbox for every title (game), a package and filesystem format of its own and a separate hardware ecurity module (HSM) dedicated to important cryptographic operations and that answers to the kernel via a narrow opcode-based command interface BUS. More on this later, the SAMU HSM is a very interesting piece of hardware Orbis is thus best understood as a junction of two systems sharing one kernel.

I.II. Hardware

The PS4 is built around a single CXD90026G AMD SoC (system on a chip) codenamed Liverpool. The CPU is eight ordinary x86-64 Jaguar cores at 1.6 GHz, two clusters of four sharing an L2 cache each and a Marvell 88W8897 Wi-Fi+BT chipset. The GPU sits on the same die with 18 compute units of AMD’s Graphics Core Next architecture, 1.84 teraflops, sharing one pool of 8 GB of GDDR5 with the CPU. There is no separate video memory.

The GPU reaches memory over two buses: Garlic, built for speed with high bandwidth and no coherency guarantees, used for rendering data the CPU has finished with and Onion, the slow cache-coherent path used for data the CPU and GPU share.

Below the main chip sits the southbridge, Aeolia on the launch model and Belize on the later revisions. It is an isolated computer in its own right, an ARM processor with its own RAM running its own BSD-derived system, and it owns everything that must keep working while the main system sleeps: network downloads in rest mode, USB, the disc drive, storage. The hard drive hangs off the southbridge. Ever downloaded a game overnight? That was Aeolia.

Inside the main die, next to the CPU cores, sits SAMU, the System Architecture Management Unit, a secure processor (akin to SecureROM) with its own firmware, RAM and custody of the cryptographic material that decrypt signed executables, the keys that unwrap title content. The root of the chain of trust that starts at the boot ROM, with verification of SAMU’s signature through self-hashing against a Sony RSA-signed hash. The main CPU can ask SAMU to perform operations to prevent user-mode/kernel-mode from having access to them.

The PS5 keeps the general architecture, with an eight Zen 2 cores CPU at up to 3.5 GHz, a RDNA 2 GPU with 36 compute units reaching 10.28 teraflops. Memory doubles to 16 GB of GDDR6. Storage became the famous part with a custom NVMe SSD and an I/O complex beside it with dedicated DMA engines, coherency engines and a hardware decompressor for the Kraken format, built so that compressed data moves from flash to RAM at speeds the CPU alone cannot sustain. And the security architecture hardens; the PS5 kernel runs under a custom ring-3 (minus three) hypervisor whose main visible job is to enforce execute-only memory on the kernel itself.

I.III. Code execution

Orbis OS allows execution of ELF binaries, relying on the hardware security mechanisms described above, without verifying binary integrity/chain of trust, allowing any app-level sandbox escape (or vulnerability) to be substantially easier to exploit. Compare against: difficulties of exploiting iOS systems.

The executable format is FreeBSD’s ELF64 for x86-64, wrapped in a container Sony calls SELF, signed ELF. Every eboot.bin on every disc and every game download is a SELF, a container with a header and an unique magic, a table of the keys that encrypt the ELF segments, and metadata the kernel and SAMU need before execution. The ELF inside is a position-independent executable with Sony-specific program headers and dynamic tags.

One such header, PT_SCE_DYNLIBDATA, carries the module’s import and export data. The dynamic section carries a build-specific fingerprint.

The SELF segments are encrypted and SAMU is involved in getting them decrypted. That much is real. But there is no iOS-style SSV chain where every page of every binary is hash-checked against a signature the kernel trusts before it is allowed to run and keeps being checked. Once you are in, you are in! This is why PS4 jailbreaks, once a kernel exploit lands, end up running unsigned code with very little further complex exploitation, and why the same class of bug on other mobile platforms is the start of a much longer week (Or month).

The rest of the loading model is modules; Userland is not statically linked the way a FreeBSD program is, a title is an eboot plus a set of .prx modules, each one a SELF, loaded at runtime by the kernel. You ask the kernel to load a module, you get a handle back, you resolve symbols by name with dynlib_dlsym. The kernel does the relocations and keeps the module list. The syscalls for this are in the appendix beginning with dynlib_, and there are a lot of them.

Every title also runs in a sandbox; its own mount namespace, inside a per-title directory under /mnt/sandbox with a randomised suffix, mounted as its root, and very little visibility of anything else. There are syscalls, is_in_sandbox and sandbox_path, for this.

Memory rules are the standard, nothing interesting; W^X since the removal of WebKit JIT in 1.76, a page is writable or executable and flipping it is a syscall. (k)ASLR on top, the executable is position-independent and lands at a random base.

On PS5 all of this still applies, with the hypervisor underneath it, only memory’s adversarial usage differs because of the execute-only kernel described above. The public PS5 work of the last few years is mostly people fighting the hypervisor, which tells you where the actual security budget went that generation.

Proprietary syscalls, a working list

Orbis keeps the FreeBSD syscall table and appends Sony’s entries. This list is partial, grouped by what the syscalls are for.

Category Function/Item Description
Dynamic linking dynlib_load_prx Loads a .prx and returns a handle.
Dynamic linking dynlib_unload_prx Releases a loaded .prx.
Dynamic linking dynlib_dlsym Resolves a symbol by name in a loaded module.
Dynamic linking dynlib_get_list / dynlib_get_info Enumerate and describe loaded modules.
Dynamic linking dynlib_do_copy_relocations / dynlib_process_needed_and_relocate The kernel-mode linker stuff.
Dynamic linking dynlib_get_proc_param Returns the loading process’s parameter block.
Synchronisation evf_create, evf_open, evf_wait, evf_trywait, evf_set, evf_clear, evf_cancel, evf_delete, evf_close Event flags family. Titles use these instead of the POSIX ones for anything that matters.
Synchronisation osem_create, osem_open, osem_wait, osem_trywait, osem_post, osem_cancel, osem_delete, osem_close Semaphores family. Titles use these instead of the POSIX ones for anything that matters.
Memory and process batch_map Applies a batch of map and unmap operations in one call; exists for the graphics stack.
Memory and process mdbg_call The debugger’s entry point.
Memory and process get_proc_type_info Describes a process to the system.
Memory and process query_memory_protection Reports what protection a mapping actually has.
Identity and sandbox is_in_sandbox / sandbox_path As above.
Identity and sandbox get_self_auth_info Returns the caller’s authority information, which the system checks before letting a title ask SAMU for things.
Identity and sandbox get_sdk_compiled_version / get_ppr_sdk_compiled_version Report which SDK generation a binary was built with.
Platform services regmgr_call Talks to the registry manager, the key-value store the system software uses for its own settings.
Platform services opmc_set_ctr / opmc_get_ctr Performance counters.
Platform services pfs_crypto_open / pfs_crypto_close Deal with the package filesystem’s keys.
Platform services get_random Returns bytes from the platform random source.

Credits

This post & series are built upon open-source knowledge and partially, the works of: PSDevWiki PSX-Place

Thank you for your time.