Skip to content

Unlink bash tool output temp file on job cleanup#540

Open
gigioneggiando wants to merge 1 commit into
antirez:mainfrom
gigioneggiando:fix/bash-tmpfile-leak
Open

Unlink bash tool output temp file on job cleanup#540
gigioneggiando wants to merge 1 commit into
antirez:mainfrom
gigioneggiando:fix/bash-tmpfile-leak

Conversation

@gigioneggiando

Copy link
Copy Markdown

Summary

agent_bash_start() creates a per-job output file with mkstemp() and stores its path in job->path. Only that function's own error paths unlink() it. The normal cleanup path, agent_bash_job_free(), closes the file descriptors and frees memory but never unlinks job->path.

A process that runs many bash-tool jobs therefore leaves one /tmp/ds4_agent_output_* file behind per job, accumulating without bound for the lifetime of the process (a slow resource leak on long-running agent sessions).

Fix

unlink(job->path) in agent_bash_job_free() before freeing the job.

Verification

Ran the real agent_bash_start() + agent_bash_job_free() cleanup path for 3 jobs:

  • before: 3 leftover /tmp/ds4_agent_output_* files after cleanup.
  • after: 0 leftover files.

Found during a coordinated security review of ds4; a standalone offline PoC is available on request.

agent_bash_start() creates a per-job output file with mkstemp() and stores
it in job->path. Only that function's error paths unlink it; the normal
cleanup path agent_bash_job_free() closes the fds and frees memory but
never unlinks job->path. A process that runs many bash-tool jobs therefore
leaves a /tmp/ds4_agent_output_* file behind for each one, accumulating
without bound for the lifetime of the process.

Unlink job->path in agent_bash_job_free() before freeing the job.
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.

1 participant