Skip to content

Commit d31a543

Browse files
oleavrhsorbo
andcommitted
darwin: Disable advanced features in hardened processes
- pipe: Avoid socket APIs, and accept that child gating won't work. - fdt-padder: Avoid padding file-descriptor table, as the system calls for doing so are often off limits, and because child gating isn't possible there is no point anyway. - exceptor: Disable to avoid deadlocks in case Mach ports are guarded. Co-authored-by: Håvard Sørbø <havard@hsorbo.no>
1 parent 94bef43 commit d31a543

6 files changed

Lines changed: 34 additions & 5 deletions

File tree

lib/agent/agent.vala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ namespace Frida.Agent {
254254
string[] tokens = agent_parameters.split ("|");
255255
unowned string transport_uri = tokens[0];
256256
bool enable_exceptor = true;
257+
#if DARWIN
258+
enable_exceptor = !Gum.Darwin.query_hardened ();
259+
#endif
257260
bool enable_exit_monitor = true;
258261
bool enable_thread_suspend_monitor = true;
259262
foreach (unowned string option in tokens[1:]) {

lib/agent/meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ extra_link_args = []
1414
if host_os_family != 'windows'
1515
extra_vala_args += ['--pkg=posix']
1616
endif
17+
if host_os_family == 'darwin'
18+
extra_vala_args += ['--pkg=frida-gum-darwin-1.0']
19+
endif
1720

1821
if host_os_family == 'darwin'
1922
extra_link_args += ['-Wl,-exported_symbol,_frida_agent_main']

lib/payload/fdt-padder.vala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ namespace Frida {
3030
}
3131

3232
private FileDescriptorTablePadder () {
33+
#if DARWIN
34+
if (Gum.Darwin.query_hardened ())
35+
return;
36+
#endif
37+
3338
open_needed_descriptors ();
3439
}
3540

@@ -44,6 +49,11 @@ namespace Frida {
4449
}
4550

4651
public void move_descriptor_if_needed (ref int fd) {
52+
#if DARWIN
53+
if (Gum.Darwin.query_hardened ())
54+
return;
55+
#endif
56+
4757
if (fd >= MIN_TABLE_SIZE)
4858
return;
4959

lib/payload/meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ extra_vala_args = []
2929
if host_os_family != 'windows'
3030
extra_vala_args += ['--pkg=posix']
3131
endif
32+
if host_os_family == 'darwin'
33+
extra_vala_args += ['--pkg=frida-gum-darwin-1.0']
34+
endif
3235
if host_os_family == 'linux'
3336
extra_vala_args += ['--pkg=linux']
3437
endif

lib/pipe/meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ if host_os_family == 'windows'
1212
]
1313
elif host_os in ['macos', 'ios']
1414
pipe_sources += ['pipe-darwin.c']
15+
16+
system_deps += [gio_unix_dep]
17+
vala_args += ['--pkg=frida-gum-darwin-1.0', '--pkg=posix']
1518
else
1619
pipe_sources += ['pipe-unix.c']
1720

lib/pipe/pipe.vala

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,21 @@ namespace Frida {
118118
}
119119
#elif MACOS || IOS
120120
namespace DarwinPipe {
121-
public static Future<SocketConnection> open (string address, Cancellable? cancellable) {
122-
var promise = new Promise<SocketConnection> ();
121+
public static Future<IOStream> open (string address, Cancellable? cancellable) {
122+
var promise = new Promise<IOStream> ();
123123

124124
try {
125125
var fd = _consume_stashed_file_descriptor (address);
126-
var socket = new Socket.from_fd (fd);
127-
var connection = SocketConnection.factory_create_connection (socket);
128-
promise.resolve (connection);
126+
IOStream stream;
127+
if (Gum.Darwin.query_hardened ()) {
128+
var input = new UnixInputStream (fd, true);
129+
var output = new UnixOutputStream (fd, false);
130+
stream = new SimpleIOStream (input, output);
131+
} else {
132+
var socket = new Socket.from_fd (fd);
133+
stream = SocketConnection.factory_create_connection (socket);
134+
}
135+
promise.resolve (stream);
129136
} catch (GLib.Error e) {
130137
promise.reject (e);
131138
}

0 commit comments

Comments
 (0)