Commit Graph

160 Commits

Author SHA1 Message Date
CuriousTommy
901b29cdb8
Merge pull request #13 from darlinghq/fix_processor_count_out_of_bounds
Fix Out Of Bounds If Count Exceeds MAX_SCHED_CPUS
2024-09-01 07:25:21 -07:00
Thomas A.
36da4da465 If Count Exceeds MAX_SCHED_CPUS, Set Count To MAX_SCHED_CPUS
Fixes out of bounds issues when running Darling on a device/virutal machine that reports more then 64 cores. Fixes #7

Co-Authored-By: Janrupf <business.janrupf@gmail.com>
2024-03-28 22:04:48 -07:00
Ariel Abreu
62a3321e98 Fix darlinghq/darling#1444 2023-10-26 07:49:00 -04:00
Ariel Abreu
99d3c764bf Force duct-tape to be built as static library 2023-10-20 13:42:51 -04:00
Ariel Abreu
f738dde463
A slightly better stub for HOST_VM_INFO
Instead of returning failure, just return success with a zeroed-out struct.
2023-10-16 17:21:36 -04:00
Ariel Abreu
16c10a30fa
Remove debugging from dtape_thread_*_state_*_user 2023-10-07 11:02:18 -04:00
Ariel Abreu
db65a1b009
Add a new tool for debugging darlingserver
This new tool (`dserverdbg`) runs on the host but connects to
darlingserver and makes unmanaged calls to retrieve debugging
information.

The initial set of subcommands available in this tool are `ps`,
`lsport`, `lspset`, and `lsmsg`:
  * `ps` lists processes currently registered with the server and how
    many Mach ports they have
  * `lsport` lists the ports of a given process (via PID) and their
    rights and messages counts (for receive rights)
  * `lspset` lists the members of a given portset (via PID and port
    name) and provides the same information about each port as `lsport`
  * `lsmsg` lists the messages of a given port (via PID and port name),
    providing sender PID (if available) and size

This tool may be expanded later to allow e.g. modifying logging settings
while darlingserver is running or perhaps searching through and
filtering the logs.
2023-10-04 00:23:56 -04:00
Ariel Abreu
5a3e170bf6
Introduce supplementary group tracking
This works very much like our UID/GID tracking.
2023-09-20 21:25:39 -04:00
Ariel Abreu
7dba61bfb8
Implement task_ident functions
These are required for `secd` sessions (i.e. for Security).
2023-07-31 19:30:14 -04:00
CuriousTommy
368a44a217
Merge pull request #11 from darlinghq/reorganize_init
Relocate dtape_init/deinit Code
2023-07-01 18:50:29 -07:00
Thomas A
0506ffb5af Relocate dtape_init/deinit Code Into init.c Source 2023-07-01 18:46:28 -07:00
Ariel Abreu
a88ba44119
[log] Add mode argument and check for success
Make sure to pass a file mode argument to `open` (this is required with `O_CREAT`. Also, make sure to check for success (i.e. non-negative FD) before trying to using the log file.
2023-06-29 09:33:41 -04:00
Ariel Abreu
ce156a461f Consider mach_vm_map_external a safe stub
This is how it was in the LKM and everything was fine, so let's do the
same. This allows `jsc` (JavaScriptCore REPL) to work again.
2023-05-02 16:23:37 -07:00
Ariel Abreu
349e074b10 [dtape] Implement TASK_FLAGS_INFO 2023-05-02 16:23:37 -07:00
Ariel Abreu
3a1c30c03e Allow some log categories to always be logged
This commit does not enable any categories with this new behavior, but
it allows for critical categories to always be logged, regardless of
log level. The main use case for this is for `kprintf` messages.
2023-05-02 16:23:37 -07:00
Thomas A
a4a5319723 Add TASK_AUDIT_TOKEN code from xnu source 2023-05-02 16:23:37 -07:00
Thomas A
afbcdfc14e Add implementation for mach_vm_remap_new_external
Code was copied over from xnu/osfmk/vm/vm_user.c. I'll admit that I'm not sure if this is the right approach, but it seems to allow me to progress with debugging notifyd.
2023-05-02 16:23:37 -07:00
Ariel Abreu
782ebad23c
Merge pull request #10 from zhaofengli/override-xdg-user-dir
Allow overriding xdg-user-dir executable
2023-05-01 14:35:54 -04:00
Zhaofeng Li
21e3c36904 Allow overriding xdg-user-dir executable
This makes it easier to set the path as xdg-user-dir may
not be in PATH.
2023-04-26 16:07:37 -06:00
Ariel Abreu
d570d86c3f
Merge pull request #9 from scamdotnet/clang15-fix
Fix compiling on clang 15+
2023-04-21 18:13:29 -04:00
scam.net
2ce6a5c294 also fix the lack of system_error header in stack-pool.cpp 2023-04-21 17:22:24 -04:00
scam.net
2f7ae9ba81 Include the system_error.h header to fix issues with compiling on clang 15 and 16 (as well as potentially other versions) 2023-04-21 16:49:03 -04:00
Ariel Abreu
b4e67c25a0
[process] Update architecture upon exec 2023-03-14 11:19:17 -04:00
Ariel Abreu
0a58b40d68
[rpc] Don't set the control buffer if we have no FDs to send
If `valid_fd_count` is 0, we can simply not set a control buffer. This
is necessary because empty control buffers with no content are invalid.
It seems that, due to some coincidence with struct sizes, this went
undetected on x86_64. However, the issue is present on i386.
2023-03-13 13:38:57 -04:00
Ariel Abreu
dac0e1333f
[rpc] Ensure consistent definitions across architectures
This commit disallows non-fixed-width types in private types and also
adds explicit alignment for 8-byte-wide types. This ensures that RPC
structure definitions are the same across different architectures.
In particular, this is necessary to fix 32-bit support.
2023-03-13 13:34:18 -04:00
Ariel Abreu
8e57a9213a
[thread] Ingore errors saving state after user-suspend
As the comment I added says, sometimes a process is killed while
user-suspended (e.g. when LLDB sends the kill signal while debugging).
In such cases, trying to save the state back to the process will fail
(since it no longer exists). We can safely ignore such errors, but let's
also log a warning just-in-case.
2023-03-13 13:31:32 -04:00
Thomas A
697fa6e643 [generate-rpc-wrappers.py] Use explict casting when dealing with different types.
FIxes int-conversion error
2022-11-20 15:09:14 -08:00
Thomas A
0acd58b514 Fix int-conversion error 2022-11-20 11:58:22 -08:00
CuriousTommy
417a64c39d
Merge pull request #6 from t0rr3sp3dr0/patch-1
bump cmake minimum required version to 3.13
2022-10-28 21:04:12 -07:00
Pedro Tôrres
e9e0a9f9a4
bump cmake minimum required version to 3.13 2022-10-27 16:17:30 -03:00
Ariel Abreu
1c7134a900
Merge pull request #5 from trungnt2910/dev/trungnt2910/wsl1-support
fix: Some darlingserver workarounds for WSL1
2022-09-01 10:12:33 -04:00
Trung Nguyen
b01df17317
fix: Workaround for WSL1 tmpfs bug
Do not mount /dev/shm with MS_NOEXEC flag on WSL1. A bug on WSL1
(https://github.com/microsoft/WSL/issues/8777) prevents files from
being mapped using mmap if the underlying filesystem is mounted
with MS_NOEXEC.
2022-08-29 22:02:01 +07:00
Trung Nguyen
12aa182f51
fix: Workaround for systems without overlayfs
Darling now be used without overlayfs by enabling
the environment "DARLING_NOOVERLAYFS". Darling also
disables overlayfs when it detects itself running in a WSL1
environment.

Without overlayfs, Darling will have to recursively copy all files
and folders from LIBEXEC_PATH to DPREFIX.
2022-08-25 08:54:24 +07:00
Ariel Abreu
94c375886b
Merge pull request #4 from trungnt2910/dev/trungnt2910/wsl1-support
feat: Initial WSL1 support
2022-08-22 02:17:45 -04:00
Ariel Abreu
d8595a1d92
Merge pull request #3 from sherpya/stub-loadinfo
Use dtape_stub_safe() for HOST_CPU_LOAD_INFO
2022-08-21 13:12:39 -04:00
Trung Nguyen
2ad420c633
feat: Initial WSL1 support
- Implemented an alternative to pidfd_open for kernels older than 5.3.
mldr should send a "lifetime pipe" to darlingserver during process start.
When the process dies, darlingserver should receive a POLLHUP event.
- Set increased_limit.rlim_cur to default_limit.rlim_max on systems without
/proc/sys/fs/nr_open. On WSL1, this greatly increases the number of open file
descriptors available.
- For systems without NSpid in /proc/self/status, implemented a way to manage
thread IDs in darlingserver during checkin. darlingserver should receive a hint
address on the thread's stack, and then compare it with a stack pointer retrieved using
PTRACE_GETREGS
- Avoided sending socket messages when msg_hdr.msg_name->sun_path is an empty string.
A null msg_name is used instead, otherwise, on some systems, this would fail with EINVAL.
2022-08-21 20:59:24 +07:00
Gianluigi Tiesi
f4837bf507 Use dtape_stub_safe() for HOST_CPU_LOAD_INFO
Avoid darlingserver crash when calling host_statistics()
asking for HOST_CPU_LOAD_INFO

`top` makes this call, at least cash top and not the
server
2022-08-19 15:05:14 +02:00
Ariel Abreu
2101f7a5a5
Implement some processor info duct-tape code 2022-07-12 19:03:17 -04:00
Ariel Abreu
13695c79b2
Report correct thread states 2022-07-05 16:42:40 -04:00
Ariel Abreu
d3a51300ea
Significantly reduce default logging output
Debug logging produces *lots* of output *very* quickly, so that's
disabled by default now. The log level can be controlled with the new
`DSERVER_LOG_LEVEL` env var. Just set it to the minimum level
you want to see in the output. It defaults to "error" so that only
error messages are logged.
2022-07-04 18:02:53 -04:00
Ariel Abreu
a6bfe117f7
Use a stack pool to reduce memory usage 2022-06-30 22:50:02 -04:00
Ariel Abreu
26ef1e040f
Use SIGUSR1 to perform leak checking when ASAN is enabled 2022-06-30 22:49:45 -04:00
Ariel Abreu
e7c383758a
Fix some leaks in duct-taped code
One significant change made here is that lck_mtx structures now directly
contain the internals of dtape_mutex structures. This was changed
because the old way of storing in a malloc'ed object led to memory leaks.
The problem is that there's a lot of XNU code that uses simple locks and
does not destroy them (because it doesn't need to in the XNU
implementation). Since the only structure that really cares about the
lock size is the waitq structure, we just patch that up. Besides, we
had modified the waitq structure in the LKM before and nothing blew up,
so this should be fine.
2022-06-30 22:49:17 -04:00
Ariel Abreu
cfd5cb9999
Add additional log info for process kqchannels 2022-06-30 22:44:35 -04:00
Ariel Abreu
4f001e2a34
Add reply-push synchronization
This is used to avoid the server reading incorrect/corrupted reply
contents for pushed replies. This was happening because clients were
sending the push-reply call with the pointer to the message contents,
but they were immediately returning after sending it. This led to a race
condition in which the server would sometimes read the data after the
client had already overwritten/discarded said data.
2022-06-24 01:39:04 -04:00
Ariel Abreu
700d89812c
Don't allowed saved replies to be overwritten 2022-06-24 01:36:56 -04:00
Ariel Abreu
89a7a10d41
Minor fixes for the Message class 2022-06-24 01:36:28 -04:00
Ariel Abreu
d49022a865
Workaround for thread resuming from syscall return 2022-06-24 01:36:06 -04:00
Ariel Abreu
2d5e25be35
Ignore calls from non-existent threads
The thread might have died after sending the message, so
it might not exist by the time the server gets the message.
In that case, just ignore/drop the message.
2022-06-24 01:35:16 -04:00
Ariel Abreu
5bd9a87821
Merge pull request #2 from rdrpenguin04/main
Add mach_vm_msync
2022-06-18 23:01:21 -04:00