Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions BaseBin/libjailbreak/src/roothider/blacklist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,12 @@ extern "C" void register_job(pid_t pid)
init_job_cache();

pthread_rwlock_wrlock(&jobLock);
(*jobCache)[pid] = proc_get_uniqueid(pid);
uint64_t uniqueid = proc_get_uniqueid(pid);
if (uniqueid != 0) {
(*jobCache)[pid] = uniqueid;
} else {
jobCache->erase(pid);
}
pthread_rwlock_unlock(&jobLock);
}

Expand All @@ -177,9 +182,10 @@ extern "C" uint64_t get_job_cache(pid_t pid)

uint64_t result = 0;
pthread_rwlock_rdlock(&jobLock);
uint64_t uniqueid = proc_get_uniqueid(pid);
auto it = jobCache->find(pid);
if (it != jobCache->end()) {
result = it->second;
if (uniqueid != 0 && it != jobCache->end() && it->second == uniqueid) {
result = uniqueid;
}
pthread_rwlock_unlock(&jobLock);
return result;
Expand Down
36 changes: 25 additions & 11 deletions BaseBin/libjailbreak/src/roothider/xpc_hook.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
});

NSDictionary* jobInfo = nil;
uint64_t jobCache = get_job_cache(pid);
if (jobCache != 0)
@synchronized (cachedData)
{
@synchronized (cachedData)
uint64_t uniqueid = get_job_cache(pid);
if (uniqueid != 0)
{
jobInfo = cachedData[@(pid)];
if ([jobInfo[@"uniqueid"] unsignedLongLongValue] != uniqueid)
{
jobInfo = nil;
}

if (!jobInfo)
{
char path[PATH_MAX] = {0};
Expand All @@ -39,10 +44,18 @@

jobInfo = @{
@"identifier":@(identifier),
@"path":@(path)
@"path":@(path),
@"uniqueid":@(uniqueid)
};

cachedData[@(pid)] = jobInfo;

if (get_job_cache(pid) == uniqueid)
{
cachedData[@(pid)] = jobInfo;
}
else
{
jobInfo = nil;
}
}
}
}
Expand Down Expand Up @@ -130,7 +143,7 @@ int new_xpc_pipe_routine_reply(xpc_object_t reply)
volatile const char *bundle = bundle_identifier ? bundle_identifier : (name ? name : "");

volatile int clientPid = audit_token_to_pid(clientToken);
volatile char* client_identifier = [getCachedJobInfo(clientPid)[@"identifier"] UTF8String];
volatile char* client_identifier = [getCachedJobInfo(clientPid)[@"identifier"] UTF8String] ?: "";

volatile bool isSafeBundleIdentifier = is_safe_bundle_identifier(bundle);
volatile bool isSelfBundleIdentifier = client_identifier[0] && string_has_prefix(bundle, client_identifier);
Expand Down Expand Up @@ -242,7 +255,7 @@ bool roothide_handle_xpc_msg(xpc_object_t xmsg)

volatile int clientPid = audit_token_to_pid(clientToken);

volatile char* client_identifier = [getCachedJobInfo(clientPid)[@"identifier"] UTF8String];
volatile char* client_identifier = [getCachedJobInfo(clientPid)[@"identifier"] UTF8String] ?: "";

volatile bool isSafeBundleIdentifier = is_safe_bundle_identifier(bundle);
volatile bool isSelfBundleIdentifier = client_identifier[0] && string_has_prefix(bundle, client_identifier);
Expand All @@ -260,11 +273,12 @@ bool roothide_handle_xpc_msg(xpc_object_t xmsg)
volatile int pid = xpc_dictionary_get_int64(xmsg, "pid");
volatile int clientPid = audit_token_to_pid(clientToken);

volatile char* path = [getCachedJobInfo(pid)[@"path"] UTF8String] ?: "";
NSDictionary* jobInfo = getCachedJobInfo(pid);
volatile char* path = [jobInfo[@"path"] UTF8String] ?: "";

volatile char* proc_identifier = [getCachedJobInfo(pid)[@"identifier"] UTF8String] ?: "";
volatile char* proc_identifier = [jobInfo[@"identifier"] UTF8String] ?: "";

volatile char* client_identifier = [getCachedJobInfo(clientPid)[@"identifier"] UTF8String];
volatile char* client_identifier = [getCachedJobInfo(clientPid)[@"identifier"] UTF8String] ?: "";

volatile bool isJailbrokenPath = !path[0] || hasTrollstoreMarker(path) || isSubPathOf(path, JBROOT_PATH("/"));
volatile bool isSafeBundleIdentifier = proc_identifier[0] && is_safe_bundle_identifier(proc_identifier);
Expand Down