Skip to content

Potential buffer overflow due to not null terminated output of readlink in scap_proc_file_root

Moderate
LucaGuerra published GHSA-5mmx-qqvj-vvwg Feb 9, 2023

Package

falcosecurity/libs

Affected versions

< 0.10.3

Patched versions

0.10.3

Description

Impact

An issue was spotted in the function that is called to retrieve the root folder path of a process that could allow an attacker with high privileges (at least CAP_SYS_CHROOT) to achieve partial memory corruption. Given the details below this does not appear likely to be exploitable ("Exploitability: None").

if ( readlink(root_path, tinfo->root, sizeof(tinfo->root)) > 0)

The issue is that readlink does not null-terminate the string that will read and copied into tinfo->root and the size of the buffer is sizeof(tinfo->root) instead of sizeof(tinfo->root) - 1 to let space for inserting a zero at the last index. Thus it’s possible to create a path exceeding SCAP_MAX_PATH_SIZE and chroot a program into it in order for this part of the code to write a not null-terminated string into the structure of the size. See the following listing for the structure in which the root buffer appears.

char root[SCAP_MAX_PATH_SIZE+1];

In theory, because the static size buffer is inserted directly in the structure, the situation could potentially mean that future reads of this string, supposed to be null-terminated, could overflow and read the data of the next structure’s fields values. However, the size of the buffer is SCAP_MAX_PATH_SIZE + 1, which translates to 1025, so the compiler will align the next fields, resulting in the next integer to be shifted by some blocks. And because this structure is allocated using calloc, the bytes hole will be filled with zeros. The result will be a string with a size equal to the expected length plus one, which could potentially be an issue with copies trusting that the string is well formed.

Patches

Upgrade to libs 0.10.3

Workarounds

None

References

Falco Security Audit report, 23-01-1097-LIV by Victor Houal, Laurent Laubin and Mahé Tardy

Severity

Moderate

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
High
User interaction
None
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:H/UI:N/S:U/C:H/I:H/A:H

CVE ID

No known CVE

Weaknesses