Skip to content

fix(convert): prevent argv out-of-bounds write and use PID-specific workspace#842

Open
aki1770-del wants to merge 1 commit into
COVESA:masterfrom
aki1770-del:fix/convert-argv-overflow-793
Open

fix(convert): prevent argv out-of-bounds write and use PID-specific workspace#842
aki1770-del wants to merge 1 commit into
COVESA:masterfrom
aki1770-del:fix/convert-argv-overflow-793

Conversation

@aki1770-del
Copy link
Copy Markdown

Problem

dlt-convert -t <tarball> has two security issues:

1. argv out-of-bounds write (CWE-131 / stack corruption)

After extracting files to the workspace directory, the code overwrites argc:

n = scandir(DLT_CONVERT_WS, &files, NULL, alphasort);
argc = optind + (n - 2);   // argc extended based on files in /tmp

A subsequent loop then writes to argv[index] using the inflated argc:

for (index = optind; index < argc; index++) {
    ...
    argv[index] = tmp_filename;   // index may exceed original argc!
}

If a malicious local user pre-populates /tmp/dlt_convert_workspace/ with extra files before execution, n is inflated, argc is set beyond the original argv array bounds, and argv[index] writes corrupt the stack — leading to a stack overflow as demonstrated with AddressSanitizer in #793.

2. Predictable workspace path (CWE-377)

The fixed path /tmp/dlt_convert_workspace/ is world-writable and predictable. Any local user can pre-create it with arbitrary contents before dlt-convert is run, triggering the overflow or injecting unexpected .dlt files.

Fixes #793.

Fix

For (1): Introduce a current_file pointer. In the processing loop, set it to tmp_filename in tarball mode or argv[index] otherwise. Remove argv[index] = tmp_filename entirely — the original argv array is never written to.

For (2): Use a PID-specific workspace path /tmp/dlt_convert_ws_<pid>/ (format string DLT_CONVERT_WS_FMT). The path is unique per invocation and not guessable by other local processes.

Testing

…orkspace

Two security issues in dlt-convert's -t (tarball) mode:

1. ARGV OUT-OF-BOUNDS WRITE (CVE-class: CWE-131)
   After extracting files to the workspace, argc was overwritten:
     argc = optind + (n - 2);   // n from scandir of /tmp workspace
   A subsequent loop then wrote:
     argv[index] = tmp_filename; // index may exceed original argc
   If an attacker pre-populated /tmp/dlt_convert_workspace/ with
   extra files before execution, 'n' would be inflated, argc
   extended beyond the original argv array bounds, and subsequent
   argv[index] writes would corrupt the stack.

   Fix: introduce 'current_file' and set it to tmp_filename (tflag)
   or argv[index] (no tflag) without ever writing back to argv[].

2. PREDICTABLE WORKSPACE PATH (CWE-377)
   The fixed path /tmp/dlt_convert_workspace/ allowed any local user
   to pre-create the directory with arbitrary files before execution,
   triggering the overflow above or injecting unexpected .dlt files.

   Fix: use a PID-specific path /tmp/dlt_convert_ws_<pid>/ which
   is unique per invocation and not guessable by other processes.

Fixes COVESA#793
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] stack-overflow in dlt-convert.c

1 participant