-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbootstrap.c
92 lines (76 loc) · 2.26 KB
/
bootstrap.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* Copyright (C) 2024 John Törnblom
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>. */
#include <signal.h>
#include <stdio.h>
#include <ps5/kernel.h>
#include <ps5/klog.h>
#include "elfldr.h"
#include "notify.h"
#include "pt.h"
#include "socksrv_elf.c"
/**
* We are running inside SceRedisServer, spawn socksrv.elf.
**/
int
main() {
pid_t mypid = getpid();
uint8_t caps[16];
uint64_t authid;
intptr_t vnode;
int ret;
notify("Spawning elfldr.elf...");
klog_puts("Spawning elfldr.elf...");
if(elfldr_sanity_check(socksrv_elf, socksrv_elf_len)) {
klog_puts("socksrv.elf is corrupted");
return -1;
}
// backup my privileges
if(!(vnode=kernel_get_proc_rootdir(mypid))) {
klog_puts("kernel_get_proc_rootdir failed");
return -1;
}
if(kernel_get_ucred_caps(mypid, caps)) {
klog_puts("kernel_get_ucred_caps failed");
return -1;
}
if(!(authid=kernel_get_ucred_authid(mypid))) {
klog_puts("kernel_get_ucred_authid failed");
return -1;
}
// launch socksrv.elf in a new processes
if(elfldr_raise_privileges(mypid)) {
klog_puts("Unable to raise privileges");
ret = -1;
} else {
signal(SIGCHLD, SIG_IGN);
ret = elfldr_spawn("elfldr.elf", -1, socksrv_elf);
}
// restore my privileges
if(kernel_set_proc_jaildir(mypid, vnode)) {
klog_puts("kernel_set_proc_jaildir failed");
ret = -1;
}
if(kernel_set_proc_rootdir(mypid, vnode)) {
klog_puts("kernel_set_proc_rootdir failed");
ret = -1;
}
if(kernel_set_ucred_caps(mypid, caps)) {
klog_puts("kernel_set_ucred_caps failed");
ret = -1;
}
if(kernel_set_ucred_authid(mypid, authid)) {
klog_puts("kernel_set_ucred_authid failed");
ret = -1;
}
return ret;
}