Summary
gpsd's gpsprof tool contains a command injection flaw in how it generates gnuplot scripts, allowing attacker-controlled GPS device subtype values to flow into plot titles.
When a victim renders plots via gpsprof and gnuplot, crafted subtype data with backtick shell syntax can lead to arbitrary command execution under the user's account.
Affected context
This vulnerability appears in environments where gpsprof is used to generate performance plots from GPS devices and then rendered via gnuplot.
It is relevant when:
- The GPS device subtype value originates from untrusted or partially trusted sources (e.g., DEVICES JSON logs or NMEA PGRMT sentences).
- gpsprof writes this subtype into gnuplot programs without full shell-safe escaping.
- Users run the generated gnuplot scripts in an interactive analysis or tooling workflow.
Exploit preconditions
- Attack surface: gpsprof-generated gnuplot scripts consumed by local users.
- Required access: Ability to influence the GPS device subtype field via DEVICES JSON logs or NMEA PGRMT sentences (e.g., by operating a malicious or compromised GPS device, or altering log inputs).
- Trigger point: User invokes gpsprof, which generates a gnuplot script containing a
set titlestatement; gnuplot then executes the embedded backtick expressions as shell commands. - Why exploitation is possible: The subtype value is inserted into the gnuplot plot title with only double-quote characters escaped, leaving shell metacharacters like backticks intact, enabling command injection when the script is interpreted.
Why this happens
The underlying bug is a failure to treat externally sourced text as unsafe in the context of a command-capable interpreter.
gpsprof constructs gnuplot scripts by interpolating the GPS device subtype into a set title statement while performing incomplete escaping focused on double quotes.
Because gnuplot supports backtick command substitution that is ultimately executed by the shell, this interpolation pattern fits CWE-78: Improper Neutralization of Special Elements used in an OS Command, where user-controlled data is embedded in a command string without neutralizing shell metacharacters.
Potential impact
- Attackers may execute arbitrary shell commands with the privileges of the user running gnuplot.
- Local user accounts can be compromised, including access to their files and environment.
- Attackers could install persistent malware or backdoors on the victim's system.
- System integrity can be undermined through data tampering or destructive operations initiated via injected commands.
General mitigation guidance
Effective mitigation focuses on eliminating direct interpolation of untrusted data into command-capable script contexts.
Recommended patterns include:
- Treating all external device metadata (such as subtype strings) as untrusted and sanitizing it before use in gnuplot or other interpreters.
- Performing rigorous neutralization of shell metacharacters, or better, avoiding any context where such characters are interpreted as commands.
- Using parameterized or data-only interfaces rather than string-built command scripts when interacting with plotting tools.
- Restricting the privileges under which plotting tools run so that, even if injection occurs, the blast radius is limited.
How teams detect issues like this
Organizations can discover similar issues by:
- Applying static analysis rules that flag string concatenation or templating used to build command-line arguments or script files from untrusted input.
- Conducting code reviews that look for places where device metadata, logs, or protocol fields are written into gnuplot, shell, or scripting environments without contextual escaping.
- Enforcing secure coding policies requiring clear separation between data and commands, and banning direct inclusion of user-controlled text in command-capable templates.
- Using automated security testing tools to fuzz inputs such as subtype fields and detect unexpected shell execution when plotting workflows are exercised.

