Skip to content

Commit fa48856

Browse files
committed
[common] Always spawn login command as the super user
This allows the app to work in a jailed state (after the user has signed the app and the linked libraries with TrollStore's method). The technique is borrowed from TrollStore's documentation: - <https://github.com/opa334/TrollStore/blob/264a9402abe30be7156c7caf51b4361ca95b7b2f/README.md#root-helpers>
1 parent 0582f39 commit fa48856

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

App/entitlements.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<true/>
99
<key>com.apple.private.security.no-container</key>
1010
<true/>
11+
<key>com.apple.private.persona-mgmt</key>
12+
<true/>
1113
<key>com.apple.security.iokit-user-client-class</key>
1214
<array>
1315
<string>IOUserClient</string>

Common/Controllers/SubProcess.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ class SubProcess {
170170
posix_spawn_file_actions_adddup2(&actions, fds.replica, STDERR_FILENO)
171171
defer { posix_spawn_file_actions_destroy(&actions) }
172172

173+
#if targetEnvironment(simulator) || targetEnvironment(macCatalyst)
174+
let attrp = nil
175+
#else
176+
// Spawn as the super user even in a jailed state, where the rootfs has the nosuid option set.
177+
var attr: posix_spawnattr_t!
178+
posix_spawnattr_init(&attr)
179+
posix_spawnattr_set_persona_np(&attr, 99, POSIX_SPAWN_PERSONA_FLAGS_OVERRIDE)
180+
posix_spawnattr_set_persona_uid_np(&attr, 0)
181+
posix_spawnattr_set_persona_gid_np(&attr, 0)
182+
defer { posix_spawnattr_destroy(&attr) }
183+
let attrp = UnsafeMutablePointer(&attr)
184+
#endif
185+
173186
// TODO: At some point, come up with some way to keep track of working directory changes.
174187
// When opening a new tab, we can switch straight to the previous tab’s working directory.
175188
let argv: [UnsafeMutablePointer<CChar>?]
@@ -189,7 +202,7 @@ class SubProcess {
189202
}
190203

191204
var pid = pid_t()
192-
let result = ie_posix_spawn(&pid, Self.login, &actions, nil, argv, envp)
205+
let result = ie_posix_spawn(&pid, Self.login, &actions, attrp, argv, envp)
193206
close(fds.replica)
194207
if result != 0 {
195208
// Fork failed.

Common/Supporting Files/NewTermCommon.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,11 @@ static inline int ie_posix_spawn(pid_t *pid, const char *path, const posix_spawn
2020
#else
2121
extern int ie_getpwuid_r(uid_t uid, struct passwd *pw, char *buf, size_t buflen, struct passwd **pwretp);
2222
extern int ie_posix_spawn(pid_t *pid, const char *path, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, char *const argv[], char *const envp[]);
23+
24+
#define POSIX_SPAWN_PERSONA_FLAGS_OVERRIDE ((uint32_t) 1)
25+
26+
// https://github.com/apple-oss-distributions/xnu/blob/1031c584a5e37aff177559b9f69dbd3c8c3fd30a/libsyscall/wrappers/spawn/spawn_private.h#L87-L89
27+
extern int posix_spawnattr_set_persona_np(const posix_spawnattr_t *attr, uid_t persona_id, uint32_t flags);
28+
extern int posix_spawnattr_set_persona_uid_np(const posix_spawnattr_t *attr, uid_t uid);
29+
extern int posix_spawnattr_set_persona_gid_np(const posix_spawnattr_t *attr, gid_t gid);
2330
#endif

0 commit comments

Comments
 (0)