Skip to content

Commit

Permalink
linux: Fix inject_library_blob() on modern Android
Browse files Browse the repository at this point in the history
Turns out we weren't setting the file-descriptor's SELinux context in
the memfd code-path.

Kudos to @romainthomas for reporting.

Fixes #480.
  • Loading branch information
oleavr committed May 14, 2024
1 parent 7a02f1c commit fa7696e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/linux/linjector.vala
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace Frida {

if (MemoryFileDescriptor.is_supported ()) {
FileDescriptor fd = MemoryFileDescriptor.from_bytes (name, blob);
adjust_fd_permissions (fd);
UnixInputStream library_so = new UnixInputStream (fd.steal (), true);
return yield inject_library_fd (pid, library_so, entrypoint, data, features, cancellable);
}
Expand Down Expand Up @@ -254,9 +255,7 @@ namespace Frida {
if (!MemoryFileDescriptor.is_supported ())
throw new Error.NOT_SUPPORTED ("Kernel too old for memfd support");
FileDescriptor fd = MemoryFileDescriptor.from_bytes (name, blob);
#if ANDROID
SELinux.fsetfilecon (fd.handle, "u:object_r:frida_memfd:s0");
#endif
adjust_fd_permissions (fd);
_memfd = new UnixInputStream (fd.steal (), true);
}
return _memfd;
Expand All @@ -274,6 +273,12 @@ namespace Frida {
FileUtils.chmod (path, path.has_suffix (".so") ? 0755 : 0644);
#if ANDROID
SELinux.setfilecon (path, "u:object_r:frida_file:s0");
#endif
}

private static void adjust_fd_permissions (FileDescriptor fd) {
#if ANDROID
SELinux.fsetfilecon (fd.handle, "u:object_r:frida_memfd:s0");
#endif
}
}

0 comments on commit fa7696e

Please sign in to comment.