Vector35 / Vector35/binaryninja-api

Darwin syscalls calling convention doesn't clobber CF as it should

Open
#8,106 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Arch: ARM64 Core: Calling Convention File Format: Mach-O File Format: SharedCache
Dominant language
C++
Stars
1.3k
Forks
298
Avg merge
5d 5h
Merged PRs (30d)
19

Description

Version and Platform (required):

  • Binary Ninja Version: 5.4.9459-dev Personal (b2c37a6b)
  • Edition: Non-Commercial

Bug Description:
Actually it's a semi-feature request semi-bug.

Currently when lifting syscalls on Darwin platforms, BN doesn't use CF as one of the return values of a syscall (on darwin platforms system calls return success status in CarryFlag, CF = 0 - success, fail otherwise), which leads to incorrect IL code being generated when the original code takes CF into account.

Here is example of such case:
Image
Image

IL uses cond:0 from earlier comparison instead of using syscalls result.

Steps To Reproduce:
Please provide all steps required to reproduce the behavior:

  1. Open sharedcache
  2. Navigate to some syscall wrapper (for example getpid)

Expected Behavior:
BN should clobber the CF and count it.

Binary:
I won't upload whole ios sharedcache, but you can check yourself with any of syscall wrappers there

Additional Information:
As @ glenns suggested me in slack, it can be workarounded via tweaking lifting of syscall instruction, but it is still a workaround and not as clean as it desired to be.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Darwin syscall instruction lifting used by wrappers such as getpid, reproducing the issue by opening an iOS sharedcache and inspecting its IL. Trace how the syscall's return values are represented, especially CarryFlag, and compare the generated IL with the wrapper's use of CF. Done means Darwin syscall lifting correctly accounts for CF so subsequent conditions use the syscall result.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, macos
Domain
operating-systems, reverse-engineering
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.