Skip to content

Missing array size check in _Mtxinit() in the Xtensa port

High
mrybczyn published GHSA-vmp6-qhp9-r66x Mar 26, 2024

Package

Eclipse ThreadX

Affected versions

< 6.4.0

Patched versions

6.4.0

Description

Short Description

In Eclipse ThreadX before version 6.4.0, the _Mtxinit() function in the Xtensa port was missing an array size check causing a memory overwrite. The affected file was ports/xtensa/xcc/src/tx_clib_lock.c

Impact

There's no error handling in case lcnt >= XT_NUM_CLIB_LOCKS. The program will continue and the tx_mutex_create() will eventually corrupt memory by writing outside the bounds of the static xclib_locks array. See the marked line below:

#ifdef TX_THREAD_SAFE_CLIB    /* this file is only needed if using C lib */
...
#if XSHAL_CLIB == XTHAL_CLIB_XCLIB
...
static TX_MUTEX xclib_locks[XT_NUM_CLIB_LOCKS];
static uint32_t lcnt;
...
/**************************************************************************/
/*    _Mtxinit - initialize a lock. Called once for each lock.            */
/**************************************************************************/
void
_Mtxinit (_Rmtx * mtx)
{
    TX_MUTEX * lock;

    if (lcnt >= XT_NUM_CLIB_LOCKS) { // VULN: empty if() body
        /* Fatal error */
    }

    lock = &(xclib_locks[lcnt]);
    lcnt++;

    /* See notes for newlib case below. */
#ifdef THREADX_TESTSUITE
    tx_mutex_create (lock, "Clib lock", 0);
#else
    tx_mutex_create (lock, "Clib lock", TX_INHERIT);
#endif

    *mtx = lock;
}

Patches

Patch available 39f3c86

Workarounds

Assure that the mutex count never reaches the limit.

References

In Progress

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Local
Attack complexity
High
Privileges required
None
User interaction
Required
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:H

CVE ID

CVE-2024-2214

Weaknesses

Improper Validation of Array Index

The product uses untrusted input when calculating or using an array index, but the product does not validate or incorrectly validates the index to ensure the index references a valid position within the array. Learn more on MITRE.

Credits