Skip to content
Memory corruption Advisory Advanced CVE-2023-27958

Apple DCERPC fixed array use after free vulnerability

A use-after-free flaw in Apple's DCERPC fixed-size array marshalling code allows a crafted RPC request to free a buffer while leaving a stale pointer and length, so a later memcpy writes to freed memory. An authenticated remote attacker could send such a request to the netlogon RPC service to trigger memory corruption, potentially leading to arbitrary code execution.

Aleksandar Nikolic Follow

Originally disclosed on Cisco Talos

High 7.5 View original

There exists a vulnerability in the fixed size array marshaling code of DCERPC library as used in Apple macOS 12.6.1 that can result in arbitrary code execution. A specially-crafted network packet can cause reuse of previously freed memory, which can lead to further memory corruption.

Aleksandar Nikolic, on Cisco Talos

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the unmarshalling code frees the buffer pointed to by IDL_mp without updating IDL_left_in_buff or invalidating IDL_mp, so a later marshalling step sees a positive remaining length and skips buffer reinitialisation, then memcpy writes to freed memory.

Impact

An authenticated remote attacker could send a crafted request to trigger memory corruption, potentially leading to arbitrary code execution; a local attacker could also trigger it via a local socket.

What the attacker needed

Authenticated remote access to netlogon RPC; or local access to the RPC socket; crafted RPC request to function 0x04

The fix

Apple fixed the vulnerability on 2023-03-27, with patch information available in a security advisory.

How it was found

  1. Send an invalid or overly long RPC request targeting function 0x04 of the netlogon service, either directly to the local endpoint or over SMB.
  2. During unmarshalling, the buffer pointed to by IDL_mp is freed but IDL_left_in_buff remains positive.
  3. During marshalling of the reply, the positive IDL_left_in_buff causes the buffer check to skip reinitialisation.
  4. The memcpy in rpc_ss_ndr_marsh_by_copying then writes to the freed memory, triggering the use-after-free.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a program handles a network request, it often allocates a temporary buffer to hold the data. A use-after-free bug happens when the program frees that buffer but keeps using a pointer to it, so later writes go into memory that may already belong to something else. Here, a specially crafted request makes the program free the buffer but forget to reset the pointer and the remaining length, so when it builds the reply it writes into the freed memory.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by Aleksandar Nikolic

View all

147 more disclosed reports, best first.

More from Cisco Talos

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.