Linux payload implementing HV exploits to run a custom bootloader
C
Add support for all 11.xx firmware (#59)
soniciso1150e33182d40
diff --git a/include/config.h b/include/config.hindex 037244a..1e688a3 100644--- a/include/config.h+++ b/include/config.h@@ -3,6 +3,10 @@#define PAGE_SIZE 0x4000ULL+/* Firmwares that use the 11.x Sonic carrier and hypervisor-defeat path. */+#define PS5_FW_IS_11XX(fw) \+ ((fw) == 0x1100 || (fw) == 0x1120 || (fw) == 0x1140 || (fw) == 0x1160)+// This is used to allocate resources for HV shellcode and Linux boot#define cave 0x100000000ULL#define cave_hv_paging cavediff --git a/include/offsets.h b/include/offsets.hindex b378d05..3f945ac 100644--- a/include/offsets.h+++ b/include/offsets.h@@ -99,6 +99,9 @@ extern offset_list off_0720;extern offset_list off_0740;extern offset_list off_0760;extern offset_list off_0761;+extern offset_list off_1100;+extern offset_list off_1120;+extern offset_list off_1140;extern offset_list off_1160;extern offset_list off_1300;extern offset_list off_1320;diff --git a/shellcode_kernel_1160/display_ops_1160.c b/shellcode_kernel_1160/display_ops_1160.cindex 7c7d893..6265d07 100644--- a/shellcode_kernel_1160/display_ops_1160.c+++ b/shellcode_kernel_1160/display_ops_1160.c@@ -44,6 +44,46 @@ const ps5_display_op_1160 ps5_display_ops_1160[29] = {{0x00538D70, 0, 0, 0},};+/* 11.00, 11.20 and 11.40 homologs. */+const ps5_display_op_1160 ps5_display_ops_1100[29] = {+ {0x00362B10, 0, 0, 0}, {0x00362D60, 0, 0, 0}, {0x00362EB0, 0, 0, 0},+ {0x00363070, 0, 0, 0}, {0x00C167C0, 0, 0, 0}, {0x003337F0, 0, 0, 0},+ {0x00751DB0, 0, 0, 0}, {0x00B01070, 0, 0, 0}, {0x00538050, 0, 0, 0},+ {0x00538240, 0, 0, 0}, {0x00362E80, 0, 0, 0}, {0x00B883D0, 0, 0, 0},+ {0x00B88F40, 0, 0, 0}, {0x00B89150, 0, 0, 0}, {0x00B89290, 0, 0, 0},+ {0x00334840, 0, 0, 0}, {0x00334840, 1, 0, 0}, {0x00334840, 2, 0, 0},+ {0x00334840, 3, 0, 0}, {0x003630A0, 0, 0, 0}, {0x00538410, 0, 0, 0},+ {0x00538590, 0, 0, 0}, {0x00B884C0, 0, 0, 0}, {0x00758480, 0, 0, 0},+ {0x009DC2D0, 1, 2, 0x7F0}, {0x0053D880, 0, 0, 0}, {0x005392F0, 1, 0, 0},+ {0x00538D60, 0, 0, 0}, {0x00538C00, 0, 0, 0},+};++const ps5_display_op_1160 ps5_display_ops_1120[29] = {+ {0x00362B10, 0, 0, 0}, {0x00362D60, 0, 0, 0}, {0x00362EB0, 0, 0, 0},+ {0x00363070, 0, 0, 0}, {0x00C167C0, 0, 0, 0}, {0x003337F0, 0, 0, 0},+ {0x00751DB0, 0, 0, 0}, {0x00B01070, 0, 0, 0}, {0x00538050, 0, 0, 0},+ {0x00538240, 0, 0, 0}, {0x00362E80, 0, 0, 0}, {0x00B883D0, 0, 0, 0},+ {0x00B88F40, 0, 0, 0}, {0x00B89150, 0, 0, 0}, {0x00B89290, 0, 0, 0},+ {0x00334840, 0, 0, 0}, {0x00334840, 1, 0, 0}, {0x00334840, 2, 0, 0},+ {0x00334840, 3, 0, 0}, {0x003630A0, 0, 0, 0}, {0x00538410, 0, 0, 0},+ {0x00538590, 0, 0, 0}, {0x00B884C0, 0, 0, 0}, {0x00758480, 0, 0, 0},+ {0x009DC2D0, 1, 2, 0x7F0}, {0x0053D880, 0, 0, 0}, {0x005392F0, 1, 0, 0},+ {0x00538D60, 0, 0, 0}, {0x00538C00, 0, 0, 0},+};++const ps5_display_op_1160 ps5_display_ops_1140[29] = {+ {0x00363510, 0, 0, 0}, {0x00363760, 0, 0, 0}, {0x003638B0, 0, 0, 0},+ {0x00363A70, 0, 0, 0}, {0x00C173B0, 0, 0, 0}, {0x003341F0, 0, 0, 0},+ {0x007527C0, 0, 0, 0}, {0x00B01C60, 0, 0, 0}, {0x00538A60, 0, 0, 0},+ {0x00538C50, 0, 0, 0}, {0x00363880, 0, 0, 0}, {0x00B88FC0, 0, 0, 0},+ {0x00B89B30, 0, 0, 0}, {0x00B89D40, 0, 0, 0}, {0x00B89E80, 0, 0, 0},+ {0x00335240, 0, 0, 0}, {0x00335240, 1, 0, 0}, {0x00335240, 2, 0, 0},+ {0x00335240, 3, 0, 0}, {0x00363AA0, 0, 0, 0}, {0x00538E20, 0, 0, 0},+ {0x00538FA0, 0, 0, 0}, {0x00B890B0, 0, 0, 0}, {0x00758E90, 0, 0, 0},+ {0x009DCE90, 1, 2, 0x7F0}, {0x0053E290, 0, 0, 0}, {0x00539D00, 1, 0, 0},+ {0x00539770, 0, 0, 0}, {0x00539610, 0, 0, 0},+};+typedef uint64_t (*display_op1_fn)(uint32_t);typedef uint64_t (*display_op2_fn)(uint32_t, uint64_t);@@ -53,6 +93,13 @@ dispatch_ps5_display_op_1160(uint32_t index) {if (index >= 29)return 0;+ const ps5_display_op_1160 *op;+ switch (args.fw_version) {+ case 0x1100: op = &ps5_display_ops_1100[index]; break;+ case 0x1120: op = &ps5_display_ops_1120[index]; break;+ case 0x1140: op = &ps5_display_ops_1140[index]; break;+ default: op = &ps5_display_ops_1160[index]; break;+ }const ps5_display_op_1160 *op = &ps5_display_ops_1160[index];const uintptr_t target = args.ktext + op->ktext_offset;diff --git a/shellcode_kernel_1160/display_ops_1160.h b/shellcode_kernel_1160/display_ops_1160.hindex 024ae34..00ad704 100644--- a/shellcode_kernel_1160/display_ops_1160.h+++ b/shellcode_kernel_1160/display_ops_1160.h@@ -10,6 +10,9 @@ typedef struct {uint64_t arg2_rsi;} ps5_display_op_1160;+extern const ps5_display_op_1160 ps5_display_ops_1100[29];+extern const ps5_display_op_1160 ps5_display_ops_1120[29];+extern const ps5_display_op_1160 ps5_display_ops_1140[29];extern const ps5_display_op_1160 ps5_display_ops_1160[29];void run_ps5_display_ops_1160(void);diff --git a/shellcode_kernel_1160/shellcode_kernel_args_validate.h b/shellcode_kernel_1160/shellcode_kernel_args_validate.hindex c8f1b5a..c380ffa 100644--- a/shellcode_kernel_1160/shellcode_kernel_args_validate.h+++ b/shellcode_kernel_1160/shellcode_kernel_args_validate.h@@ -16,6 +16,11 @@ static inline int shellcode_kernel_va_is_canonical(uint64_t va) {*/static inline int validate_shellcode_kernel_args_1160(volatile const shellcode_kernel_args *candidate) {+ if (candidate == NULL ||+ (candidate->fw_version != 0x1100 &&+ candidate->fw_version != 0x1120 &&+ candidate->fw_version != 0x1140 &&+ candidate->fw_version != 0x1160))if (candidate == NULL || candidate->fw_version != 0x1160)return -1;diff --git a/source/hv_defeat_1160.c b/source/hv_defeat_1160.cindex 702ec8b..fef264b 100644--- a/source/hv_defeat_1160.c+++ b/source/hv_defeat_1160.c@@ -23,6 +23,9 @@* wake blob from its prepare_resume() alias into the kernel code cave.*/+#define FW_1100_RAW 0x11000043U+#define FW_1120_RAW 0x11200005U+#define FW_1140_RAW 0x11400005U#define FW_1160_RAW 0x11600005U#define PS5_PRO_SOC_ID 0x840fd0#define NCPU 16@@ -118,6 +121,20 @@ static int offsets_present(void) {env_offset.FUN_MP3_INVOKE,};+ uint32_t expected_raw = 0;++ switch (fw) {+ case 0x1100: expected_raw = FW_1100_RAW; break;+ case 0x1120: expected_raw = FW_1120_RAW; break;+ case 0x1140: expected_raw = FW_1140_RAW; break;+ case 0x1160: expected_raw = FW_1160_RAW; break;+ default: return 0;+ }+ if (kernel_get_fw_version() != expected_raw)+ return 0;+ /* Every 11.x build shares the same hypervisor image and CC cave. */+ if (env_offset.HV_CODE_CAVE_PA != 0x62806F00ULL ||+ env_offset.HV_HANDLE_VMEXIT_PA != 0x62847551ULL)if (kernel_get_fw_version() != FW_1160_RAW || fw != 0x1160)return 0;if (env_offset.KERNEL_CODE_CAVE != 0xD2B000ULL ||diff --git a/source/loader.c b/source/loader.cindex b63e881..480ac83 100644--- a/source/loader.c+++ b/source/loader.c@@ -204,6 +204,7 @@ int fetch_linux(struct linux_info *info) {info->kit_type = (int)get_kit_type();strcpy(info->cmdline, cmdline);+ if (PS5_FW_IS_11XX(fw)) {if (fw == 0x1160) {// 11.60 stages the aliases with a checked, journaled transaction instead// of the install_page_syscore loop below.diff --git a/source/main.c b/source/main.cindex 30fb41b..ab9bff9 100644--- a/source/main.c+++ b/source/main.c@@ -2,6 +2,7 @@#include "hv_defeat_0506.h"#include "hv_defeat_0607.h"#include "hv_defeat_1160.h"+#include "config.h"#include "hv_defeat_13xx.h"#include "loader.h"#include "prepare_resume.h"@@ -11,6 +12,7 @@// 11.60 keeps page tables from this process linked into PID 1 once the Linux// files are staged, so it must not exit after that.static int fail_after_staging(void) {+ if (PS5_FW_IS_11XX(fw)) {if (fw == 0x1160) {notify("Linux files are still staged. Cold reboot before trying again.\n");while (1)@@ -50,6 +52,7 @@ int main(void) {} else if (fw == 0x1300 || fw == 0x1320 || fw == 0x1340 || fw == 0x1342 || fw == 0x1360) {if (hv_defeat_13xx(shellcode_kernel, shellcode_kernel_len))goto err;+ } else if (PS5_FW_IS_11XX(fw)) {} else if (fw == 0x1160) {if (hv_defeat_1160(shellcode_kernel, shellcode_kernel_len))goto err;diff --git a/source/offsets.c b/source/offsets.cindex 434b31a..41e513a 100644--- a/source/offsets.c+++ b/source/offsets.c@@ -766,6 +766,138 @@ offset_list off_0761 = {.PS5_WIFI_FW_SIZE = 497636,};+offset_list off_1100 = {+ .VMSPACE_VM_VMID = 0x1E4,+ .VMSPACE_VM_PMAP = 0x1D8,+ .ACPIGBL_FACS = 0x39CD1F0,+ .IDT = 0x3BA0300,+ .COMMON_TSS = 0x3BA2FE0,+ .FUN_MEMCPY = 0x2E8280,+ .GAD_ADD_RSP_28_POP_RBP_RET = 0xA56D14,+ .GAD_IRETQ = 0x26B627,+ .GAD_POP_RAX_RET = 0x267A90,+ .GAD_POP_RDI_RET = 0x24AE38,+ .GAD_POP_RSI_RET = 0x20B970,+ .GAD_POP_RDX_RET = 0x31B6C2,+ .GAD_POP_RCX_RET = 0x3394AF,+ .GAD_POP_RSP_RET = 0x2AF4D0,+ .HOOK_ACPI_WAKEUP_MACHDEP = 0x4D87D8,+ .KERNEL_CODE_CAVE = 0xD2B000,+ .FUN_PRINTF = 0x5358E0,+ .FUN_SMP_RENDEZVOUS = 0xB73230,+ .FUN_SMP_NO_RENDEVOUS_BARRIER = 0x267A91,+ .HV_CODE_CAVE_PA = 0x62806F00,+ .HV_HANDLE_VMEXIT_PA = 0x62847551,+ .KERNEL_CFI_CHECK = 0x4EBF90,+ .G_VBIOS = 0x3DB7A40,+ .FUN_TRANSMITTER_CONTROL = 0xC7F910,+ .FUN_MP3_INITIALIZE = 0xA87C10,+ .FUN_MP3_INVOKE = 0xA86830,+ .HV_MP_STARTUP_CALL = 0xC87E20,+ .MP_STARTUP_INIT_VECTOR = 0x311518,+ .DATA_CAVE = 0x2D02000,+ .GAD_PIVOT_ADD_RSP28_RET = 0x2A131E,+ .GAD_STORE_RDI8_RCX_RET = 0x3CC88F,+ .GAD_SET_DR7_RET = 0xA7B746,+ .GAD_STORE_RCX_RAX_RET = 0x36249F,+ .GAD_MOV_RAX_RDI_RET = 0x2B2F51,+ .GAD_REP_MOVSB_RET = 0x3047A7,+ .GAD_CLD_RET = 0x4A5D46,+ .GAD_RET_TRAMP = 0x267A91,+ .GAD_DBREG_RESUME = 0x2A5BB8,+ .HV_EFI_MAP_ROOT = 0x3DCD0C8,+ .PS5_WIFI_FW_OFFSET = 0x1586110,+ .PS5_WIFI_FW_SIZE = 0x799BC,+};++offset_list off_1120 = {+ .VMSPACE_VM_VMID = 0x1E4,+ .VMSPACE_VM_PMAP = 0x1D8,+ .ACPIGBL_FACS = 0x39CD1F0,+ .IDT = 0x3BA0300,+ .COMMON_TSS = 0x3BA2FE0,+ .FUN_MEMCPY = 0x2E8280,+ .GAD_ADD_RSP_28_POP_RBP_RET = 0xA56D14,+ .GAD_IRETQ = 0x26B627,+ .GAD_POP_RAX_RET = 0x267A90,+ .GAD_POP_RDI_RET = 0x24AE38,+ .GAD_POP_RSI_RET = 0x20B970,+ .GAD_POP_RDX_RET = 0x347ABB,+ .GAD_POP_RCX_RET = 0x3394AF,+ .GAD_POP_RSP_RET = 0x2AF4D0,+ .HOOK_ACPI_WAKEUP_MACHDEP = 0x4D87D8,+ .KERNEL_CODE_CAVE = 0xD2B000,+ .FUN_PRINTF = 0x5358E0,+ .FUN_SMP_RENDEZVOUS = 0xB73230,+ .FUN_SMP_NO_RENDEVOUS_BARRIER = 0x267A91,+ .HV_CODE_CAVE_PA = 0x62806F00,+ .HV_HANDLE_VMEXIT_PA = 0x62847551,+ .KERNEL_CFI_CHECK = 0x4EBF90,+ .G_VBIOS = 0x3DB7A40,+ .FUN_TRANSMITTER_CONTROL = 0xC7F910,+ .FUN_MP3_INITIALIZE = 0xA87C10,+ .FUN_MP3_INVOKE = 0xA86830,+ .HV_MP_STARTUP_CALL = 0xC87E20,+ .MP_STARTUP_INIT_VECTOR = 0x311518,+ .DATA_CAVE = 0x2D02000,+ .GAD_PIVOT_ADD_RSP28_RET = 0x2A131E,+ .GAD_STORE_RDI8_RCX_RET = 0x3CC88F,+ .GAD_SET_DR7_RET = 0xA7B746,+ .GAD_STORE_RCX_RAX_RET = 0x36249F,+ .GAD_MOV_RAX_RDI_RET = 0x2B2F51,+ .GAD_REP_MOVSB_RET = 0x3047A7,+ .GAD_CLD_RET = 0x4930E6,+ .GAD_RET_TRAMP = 0x267A91,+ .GAD_DBREG_RESUME = 0x2A5BB8,+ .HV_EFI_MAP_ROOT = 0x3DCD0C8,+ .PS5_WIFI_FW_OFFSET = 0x1586110,+ .PS5_WIFI_FW_SIZE = 0x799BC,+};++offset_list off_1140 = {+ .VMSPACE_VM_VMID = 0x1E4,+ .VMSPACE_VM_PMAP = 0x1D8,+ .ACPIGBL_FACS = 0x39CD1F0,+ .IDT = 0x3BA0300,+ .COMMON_TSS = 0x3BA2FE0,+ .FUN_MEMCPY = 0x2E8C00,+ .GAD_ADD_RSP_28_POP_RBP_RET = 0xA578D4,+ .GAD_IRETQ = 0x26BFA7,+ .GAD_POP_RAX_RET = 0x268410,+ .GAD_POP_RDI_RET = 0x24B7B8,+ .GAD_POP_RSI_RET = 0x20C2F0,+ .GAD_POP_RDX_RET = 0x3484BB,+ .GAD_POP_RCX_RET = 0x339EAF,+ .GAD_POP_RSP_RET = 0x2AFE50,+ .HOOK_ACPI_WAKEUP_MACHDEP = 0x0,+ .KERNEL_CODE_CAVE = 0xD2B000,+ .FUN_PRINTF = 0x5362F0,+ .FUN_SMP_RENDEZVOUS = 0xB73E20,+ .FUN_SMP_NO_RENDEVOUS_BARRIER = 0x268411,+ .HV_CODE_CAVE_PA = 0x62806F00,+ .HV_HANDLE_VMEXIT_PA = 0x62847551,+ .KERNEL_CFI_CHECK = 0x4EC9A0,+ .G_VBIOS = 0x3DB7A40,+ .FUN_TRANSMITTER_CONTROL = 0xC80500,+ .FUN_MP3_INITIALIZE = 0xA887D0,+ .FUN_MP3_INVOKE = 0xA873F0,+ .HV_MP_STARTUP_CALL = 0xC88A10,+ .MP_STARTUP_INIT_VECTOR = 0x311E98,+ .DATA_CAVE = 0x2D02000,+ .GAD_PIVOT_ADD_RSP28_RET = 0x2A1C9E,+ .GAD_STORE_RDI8_RCX_RET = 0x3CD28F,+ .GAD_SET_DR7_RET = 0xA7C306,+ .GAD_STORE_RCX_RAX_RET = 0x362E9F,+ .GAD_MOV_RAX_RDI_RET = 0x2B38D1,+ .GAD_REP_MOVSB_RET = 0x305127,+ .GAD_CLD_RET = 0x3ED2D7,+ .GAD_RET_TRAMP = 0x268411,+ .GAD_DBREG_RESUME = 0x2A6538,+ .HV_EFI_MAP_ROOT = 0x3DCD0C8,+ .PS5_WIFI_FW_OFFSET = 0x15860D0,+ .PS5_WIFI_FW_SIZE = 0x799BC,+};+offset_list off_1160 = {.VMSPACE_VM_VMID = 0x1E4,.VMSPACE_VM_PMAP = 0x1D8,@@ -809,6 +941,8 @@ offset_list off_1160 = {.GAD_CLD_RET = 0x462C1A,.GAD_RET_TRAMP = 0x338D2B,.GAD_DBREG_RESUME = 0x2A5778,+ .NVS_SIGNATURE = 0x1A73930,+ .HV_EFI_MAP_ROOT = 0x3DCD0C8,};offset_list off_1300 = {diff --git a/source/prepare_resume.c b/source/prepare_resume.cindex b22bdc9..bb090f8 100644--- a/source/prepare_resume.c+++ b/source/prepare_resume.c@@ -164,6 +164,7 @@ int prepare_resume(void **shellcode_kernel, size_t *shellcode_kernel_len) {} else if (fw == 0x1360 && linux_i.kit_type != KIT_RETAIL_PRO) {shellcode_src = stock_shellcode_kernel_1360;shellcode_len = stock_shellcode_kernel_1360_len;+ } else if (PS5_FW_IS_11XX(fw)) {} else if (fw == 0x1160) {shellcode_src = shellcode_kernel_1160_bin;shellcode_len = shellcode_kernel_1160_bin_len;@@ -171,6 +172,7 @@ int prepare_resume(void **shellcode_kernel, size_t *shellcode_kernel_len) {if ((fw == 0x1300 || fw == 0x1320) && shellcode_len > 0x3910)return -1;+ if (PS5_FW_IS_11XX(fw) && shellcode_len > 0x5000)if (fw == 0x1160 && shellcode_len > 0x5000)return -1;@@ -198,6 +200,7 @@ int prepare_resume(void **shellcode_kernel, size_t *shellcode_kernel_len) {vtophys_user((uintptr_t)*shellcode_kernel + i), 0);}+ if (PS5_FW_IS_11XX(fw) ? remove_xotext_1160(shellcode_len) : remove_xotext()) {if (fw == 0x1160 ? remove_xotext_1160(shellcode_len) : remove_xotext()) {printf("Error: could not remove xo from text\n");return -1;@@ -256,6 +259,7 @@ uint64_t prepare_sck_args(void) {args.kernel_cfi_check = ktext + env_offset.KERNEL_CFI_CHECK;args.hv_handle_vmexit_pa = env_offset.HV_HANDLE_VMEXIT_PA;args.hv_code_cave_pa = env_offset.HV_CODE_CAVE_PA;+ if ((PS5_FW_IS_11XX(fw) || fw == 0x1320 || fw == 0x1360) &&if ((fw == 0x1320 || fw == 0x1340 || fw == 0x1342 || fw == 0x1360) &&linux_i.kit_type == KIT_RETAIL_PRO) {uint64_t pro_base = derive_h() + HV_CODE_OFFSET_PRO;@@ -266,12 +270,14 @@ uint64_t prepare_sck_args(void) {args.linux_info_va = linux_i.linux_info;+ if (PS5_FW_IS_11XX(fw) && validate_shellcode_kernel_args_1160(&args))if (fw == 0x1160 && validate_shellcode_kernel_args_1160(&args))return 0;uint64_t args_pa = alloc_page();// Keep the args page off the page under the #SX stack, which the wake stack// reaches past 0x1040 bytes. Pages taken here stay allocated.+ while (PS5_FW_IS_11XX(fw) && args_pa && pa_under_sx_stack_1160(args_pa))while (fw == 0x1160 && args_pa && pa_under_sx_stack_1160(args_pa))args_pa = alloc_page();if (!args_pa)@@ -283,6 +289,7 @@ uint64_t prepare_sck_args(void) {kernel_copyout((intptr_t)args_cave, &readback, sizeof(readback)) ||memcmp(&args, &readback, sizeof(args)))return 0;+ if (PS5_FW_IS_11XX(fw) && validate_shellcode_kernel_args_1160(&readback))if (fw == 0x1160 && validate_shellcode_kernel_args_1160(&readback))return 0;diff --git a/source/utils.c b/source/utils.cindex d2c89fe..46a07b6 100644--- a/source/utils.c+++ b/source/utils.c@@ -97,6 +97,28 @@ int set_offsets(void) {case 0x0761:env_offset = off_0761;break;+ case 0x1100:+ if (kernel_get_fw_version() != 0x11000043U) {+ notify("Only the retail 11.00 build (0x11000043) is supported\n");+ return -1;+ }+ env_offset = off_1100;+ break;+ case 0x1120:+ if (kernel_get_fw_version() != 0x11200005U) {+ notify("Only the retail 11.20 build (0x11200005) is supported\n");+ return -1;+ }+ env_offset = off_1120;+ break;+ case 0x1140:+ if (kernel_get_fw_version() != 0x11400005U) {+ notify("Only the retail 11.40 build (0x11400005) is supported\n");+ return -1;+ }+ env_offset = off_1140;+ break;+ case 0x1160:case 0x1160:// Only the retail 11.60 build on a regular PS5 has been tested.if (kernel_get_fw_version() != 0x11600005U) {