There is an update available to handle a vulnerability in the R language that allows for arbitrary code to execute directly after the discovery of deserialization of untrusted data, according to a report for CERT/CC at Carnegie Mellon University.

While R language may not have a large implementation in the manufacturing sector, it does have some significance.

This vulnerability (CVE-2024-27322) can end up exploited through RDS (R Data Serialization) format files and .rdx files. An attacker can create malicious RDS or .rdx formatted files to execute arbitrary commands on the victim’s target device.

R supports data serialization, which is the process of turning R objects and data into a format that can then deserialize in another R session. This will provide a copy of the R objects from the original session.

The RDS format, which mainly comprises .rds files, can save and load serialized R objects. These objects can share states and transfer data sets across programs. They should not run code when loaded by an R implementation unless prompted by the user. R Packages use .rdx files, which contain a list of offsets, lengths, and names, and are accompanied by a .rdb file, which extracts more information about those offsets. .rdx and .rdb files contain RDS formatted data within themselves. A .rds file functions similarly to a .rdx file but only allows for storing a single R object. When loading a .rds or .rdx file, the readRDS function end up utilized. An R implementation using the readRDS function given that information will then read the offsets and load the data.

Schneider Bold

R supports lazy evaluation. It is possible to implement it through a type called Promise, which ends up represented in the RDS format as PROMSXP. This type can manage expressions called and completed in an asynchronous manner when their associated values end up needed by the program. When constructing an unserialized object in this context from the RDS format, the Promise object will require three pieces of data. These are the value of the Promise, the expression, and the environment. This information is loaded by the eval function. The eval function in R takes an expression, in this case the Promise, and evaluates it within the environment specified.

The vulnerability occurs when the eval function evaluates a promise type that has an unevaluated value. The Promise expression will not be properly evaluated and will execute the expression when it is referenced in the program that contains it. A threat actor can include malicious code within a .rds or .rdx file referenced by an unevaluated value. When an R implemention loads a package that contains an .rds or .rdx file and the promise value ends up reached, it will execute the referenced code. This code is arbitrary and end up executed prior to any opportunity for the victim to explore and see what functions or objects are within the file loaded.

As a result of the vulnerability, an attacker could create malicious .rds and .rdx files and use social engineering to distribute those files to execute arbitrary code on the victim’s device. Projects that use readRDS on untrusted files are also vulnerable to the attack. Attackers can also leverage system commands to access resources available to the application and exfiltrate data from any environment available to the application on the target device. The code in the malicious files can also end up used to access adjacent resources such other computers/devices, devices in a cluster and shared documents/folders available to the application.

R project has provided R Core Version 4.4.0, which addresses the vulnerability. R Core version 4.4.0 now restricts promises in the serialization stream so they now see use for implementing lazy evaluation.

Pin It on Pinterest

Share This