Skip to content

udiskslinuxfilesystem: Fix TOCTOU race in mount point directory creation#1515

Open
ajax-semenko-d wants to merge 1 commit into
storaged-project:masterfrom
ajax-semenko-d:master_mounting-toctou-fix
Open

udiskslinuxfilesystem: Fix TOCTOU race in mount point directory creation#1515
ajax-semenko-d wants to merge 1 commit into
storaged-project:masterfrom
ajax-semenko-d:master_mounting-toctou-fix

Conversation

@ajax-semenko-d
Copy link
Copy Markdown

Rename calculate_mount_point() to create_mount_point() and move the g_mkdir(2) call inside the uniquification loop. Using mkdir(2) as the existence check instead of g_file_test() + a separate mkdir(2) closes the window where two concurrent mount requests could compute the same candidate path and both succeed the test before either creates the directory.

On failure after the directory is already created, callers now call g_rmdir() to release the reserved directory before returning an error.

Fixes: #1513

Rename calculate_mount_point() to create_mount_point() and move the
g_mkdir(2) call inside the uniquification loop.  Using mkdir(2) as the
existence check instead of g_file_test() + a separate mkdir(2) closes
the window where two concurrent mount requests could compute the same
candidate path and both succeed the test before either creates the
directory.

On failure after the directory is already created, callers now call
g_rmdir() to release the reserved directory before returning an error.

Fixes: storaged-project#1513

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

Mounting two filesystems with the same label at the same time fails with "File exists"

1 participant