summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoss Lagerwall <rosslagerwall@gmail.com>2014-09-01 22:59:09 +0100
committerMartin Pitt <martin.pitt@ubuntu.com>2014-12-18 11:34:15 +0100
commit153c05f7cb4984c5616ca0ead12911479ad61f7b (patch)
tree7f6bcca07cd281a6fe95edecdd55710554a86a9b
parentaf0bf0bb0b8f40b80c6fc8cdc612121dd87fc673 (diff)
Fix TOCTOU race when making directories
If two volumes are mounted at approximately the same time, one of the mount operations can fail with an error something like: Error creating directory /run/media: File exists because of the window between the check of the existence and the creation of the directory. To fix this, drop the g_file_test() check and instead ignore EEXIST errors when making these directories. https://bugs.freedesktop.org/show_bug.cgi?id=83374
-rw-r--r--src/udiskslinuxfilesystem.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/udiskslinuxfilesystem.c b/src/udiskslinuxfilesystem.c
index dd83bc1..d657bc0 100644
--- a/src/udiskslinuxfilesystem.c
+++ b/src/udiskslinuxfilesystem.c
@@ -900,19 +900,16 @@ calculate_mount_point (UDisksDaemon *daemon,
if (!g_file_test (mount_dir, G_FILE_TEST_EXISTS))
{
/* First ensure that /run/media exists */
- if (!g_file_test ("/run/media", G_FILE_TEST_EXISTS))
+ if (g_mkdir ("/run/media", 0755) != 0 && errno != EEXIST)
{
- if (g_mkdir ("/run/media", 0755) != 0)
- {
- g_set_error (error,
- UDISKS_ERROR,
- UDISKS_ERROR_FAILED,
- "Error creating directory /run/media: %m");
- goto out;
- }
+ g_set_error (error,
+ UDISKS_ERROR,
+ UDISKS_ERROR_FAILED,
+ "Error creating directory /run/media: %m");
+ goto out;
}
/* Then create the per-user /run/media/$USER */
- if (g_mkdir (mount_dir, 0700) != 0)
+ if (g_mkdir (mount_dir, 0700) != 0 && errno != EEXIST)
{
g_set_error (error,
UDISKS_ERROR,