Skip to content
GoogleGHSA-475q-v6j3-mjr4

Python: Code Execution Vulnerability

LowPublished Mar 26, 2024

### Summary The asv_benchmarks/benchmarks/[common.py](http://common.py/) script is a common utility class containing a parent class from which specific benchmarks for different model types are derived. The vulnerable function loads configuration options from a configuration file but allows for overriding values in the configuration file with values set by environment variable. The SKLBENCH_JOBS variable is an integer specifying the number of concurrent jobs to execute. The script checks if the environment variable SKLBENCH_NJOBS is set, if so, it passes the variable to eval() since the values from environment variables are strings by default in Python. Since the script uses eval() over int(), we can set the environment variable to arbitrary python code and gain execution whenever the script is run. In the example shown below, I invoke the common.py script itself, however, invoking any of the model files within that same directory (linear_models.py, svm.py, manifold.py, etc. -- anything that imports the Benchmark class) will similarly lead to execution as class variables within Benchmark invoke the vulnerable code. Accordingly, the fix is just to change to using the int() function ...

GitHub advisory

Affected versions

PackageAffectedFixed in
Scikit-learn
Product
< https://github.com/scikit-learn/scikit-learn/pull/28504https://github.com/scikit-learn/scikit-learn/pull/28504
Details and references

### Summary The asv_benchmarks/benchmarks/[common.py](http://common.py/) script is a common utility class containing a parent class from which specific benchmarks for different model types are derived. The vulnerable function loads configuration options from a configuration file but allows for overriding values in the configuration file with values set by environment variable. The SKLBENCH_JOBS variable is an integer specifying the number of concurrent jobs to execute. The script checks if the environment variable SKLBENCH_NJOBS is set, if so, it passes the variable to eval() since the values from environment variables are strings by default in Python. Since the script uses eval() over int(), we can set the environment variable to arbitrary python code and gain execution whenever the script is run. In the example shown below, I invoke the common.py script itself, however, invoking any of the model files within that same directory (linear_models.py, svm.py, manifold.py, etc. -- anything that imports the Benchmark class) will similarly lead to execution as class variables within Benchmark invoke the vulnerable code. Accordingly, the fix is just to change to using the int() function to cast the value without additional dangerous side effects. ### Severity Low - In order for an adversary to exploit this vulnerability, they must have control over the contents of an environment variable and the script that is used for benchmarking. ### Proof of Concept ```python ~$ pwd ~$ export SKLBENCH_NJOBS='print("Code execution!")' ~$ python3 common.py ``` ### Timeline **Date reported**: 02/12/2024 **Date fixed**: 02/22/2024 **Date disclosed**:03/26/2024

Severity from
GitHub (reviewed advisory)

More Google advisories

All Google
Advisory
Python: Heap buffer overflow in a Pillow (PIL fork) interface to the littleCMS ICC Color Management System
Medium6.7May 1, 2024
UTM: Remote Code Execution Via Unsafe VM Handling
MediumApr 5, 2024
UTM: Unsafe URL Handling
LowApr 5, 2024
Microsoft Edge: Bypass of fix for CVE-2023-36880
LowApr 4, 2024
PostgreSQL: Concurrent Refresh Privilege Escalation
MediumMar 19, 2024
PostgreSQL: Plv8 Deferred Trigger Privilege Escalation
HighFeb 21, 2024

Critical advisories by email

Wednesdays: the week’s critical and high advisories in the AI and data stack, with the fixed versions. Only in weeks that have some.

Double opt-in. Unsubscribe any time.