The vulnerability exists in the glances/outdated.py module, which handles checking for new versions of the Glances software. The root cause is the use of Python's pickle module to serialize and deserialize cache data to a file located in a predictable, and often user-writable, directory (~/.cache/glances/).
The function Outdated._load_cache is the primary vulnerable function. It reads the cache file and uses pickle.load() to deserialize its contents. The pickle module is known to be unsafe when used with untrusted data, as a specially crafted pickle object can execute arbitrary code during deserialization. An attacker with write access to the cache file's location could replace the legitimate cache file with a malicious one. The next time Glances is run, the _load_cache function would deserialize the malicious file, resulting in arbitrary code execution with the permissions of the Glances process, which could be root.
The patch addresses this vulnerability by completely removing the usage of pickle. It modifies both Outdated._load_cache and Outdated._save_cache to use the json module instead. JSON is a safe data interchange format and does not have the code execution capabilities of pickle, thus eliminating the remote code execution risk.