Summary
TDengine allows users with UDF creation privileges to upload shared libraries and register them as user-defined functions.
Before version 3.4.1.15, a crafted library could be installed and invoked via queries, enabling arbitrary C code execution on the TDengine server when those functions are executed.
Affected context
This vulnerability appears in TDengine deployments where user-defined functions (UDFs) are supported and users are granted create-udf or equivalent privileges.
It becomes relevant in environments that allow uploading and registering custom shared libraries as UDFs without strong validation, sandboxing, or segregation of duties between application users and administrators.
Exploit preconditions
- Attack surface: TDengine server exposed through its database interface supporting UDF creation and invocation.
- Required access: Ability to authenticate as a user with the privilege to upload and create UDFs (e.g., "create udf" role).
- Trigger point: Registration of a crafted shared library as a UDF (such as an eval-style function) and subsequent invocation through a database query.
- Why exploitation is possible: The server loads and executes code directly from user-supplied shared libraries without adequate constraints, allowing arbitrary C code within those libraries to run with the server's process privileges.
Why this happens
The root cause aligns with CWE-94: Improper Control of Generation of Code ('Code Injection').
TDengine's UDF mechanism trusts uploaded shared libraries and treats them as executable extensions of the database engine.
Without strict validation, sandboxing, or separation between user-controlled artifacts and server runtime code, attackers with UDF creation rights can generate and deploy arbitrary native code that the database will load and execute during query processing.
Potential impact
- An attacker may execute arbitrary native C code in the context of the TDengine server process.
- An attacker could read, modify, or delete data managed by the database engine.
- An attacker may pivot from the database to the underlying host, accessing local files or services.
- An attacker could disrupt availability through crashes, resource exhaustion, or logic tampering.
- An attacker may implant persistent backdoors or surveillance logic within the server environment.
General mitigation guidance
Effective mitigation focuses on tightening control around UDF capabilities and treating server-side code execution as a high-trust operation.
Common patterns include:
- Restricting or removing UDF creation privileges from non-administrative accounts; assign them only to tightly controlled service or admin roles.
- Introducing rigorous approval workflows for new UDFs, including security review and testing before deployment.
- Applying sandboxing or isolation techniques for UDF execution so that uploaded code runs with reduced privileges and limited access to system resources.
- Enforcing least-privilege on the TDengine process and its host environment, reducing the impact of any executed code.
- Maintaining strong governance over where shared libraries are stored and how they are loaded, avoiding direct reliance on user-controlled paths.
How teams detect issues like this
Organizations can detect and manage this class of risk through multiple layers:
- Static analysis or manual review of UDF source code and build artifacts before they are approved for deployment.
- Auditing configuration and role assignments to identify accounts with UDF creation privileges and verifying that these match policy.
- Monitoring database logs for unusual UDF creation, modification, and invocation patterns, particularly libraries that appear outside standard deployment pipelines.
- Implementing change-control policies that require peer review and security checks for any new shared libraries loaded by the database.
- Leveraging automated code review tools where applicable to scan UDF implementations for unsafe operations and sensitive resource access.

