arrfab / rpms / abrt

Forked from rpms/abrt 5 years ago
Clone

Blame SOURCES/0114-daemon-harden-against-race-conditions-in-DELETE.patch

8ec399
From 10bea037a2ad82616b3698d07d07d287481e1bed Mon Sep 17 00:00:00 2001
8ec399
From: Jakub Filak <jfilak@redhat.com>
8ec399
Date: Wed, 6 May 2015 14:04:42 +0200
8ec399
Subject: [ABRT PATCH] daemon: harden against race conditions in DELETE
8ec399
8ec399
There is a race between checking dump dir accessibility and deleting it
8ec399
in abrt-server.
8ec399
8ec399
Related: #1214457.
8ec399
8ec399
Signed-off-by: Jakub Filak <jfilak@redhat.com>
8ec399
---
8ec399
 src/daemon/abrt-server.c | 21 +++++++++++++++++++--
8ec399
 1 file changed, 19 insertions(+), 2 deletions(-)
8ec399
8ec399
diff --git a/src/daemon/abrt-server.c b/src/daemon/abrt-server.c
8ec399
index 1030461..130c24a 100644
8ec399
--- a/src/daemon/abrt-server.c
8ec399
+++ b/src/daemon/abrt-server.c
8ec399
@@ -91,8 +91,16 @@ static int delete_path(const char *dump_dir_name)
8ec399
         error_msg("Problem directory '%s' isn't owned by root:abrt or others are not restricted from access", dump_dir_name);
8ec399
         return 400; /*  */
8ec399
     }
8ec399
-    if (!dump_dir_accessible_by_uid(dump_dir_name, client_uid))
8ec399
+
8ec399
+    int dir_fd = dd_openfd(dump_dir_name);
8ec399
+    if (dir_fd < 0)
8ec399
+    {
8ec399
+        perror_msg("Can't open problem directory '%s'", dump_dir_name);
8ec399
+        return 400;
8ec399
+    }
8ec399
+    if (!fdump_dir_accessible_by_uid(dir_fd, client_uid))
8ec399
     {
8ec399
+        close(dir_fd);
8ec399
         if (errno == ENOTDIR)
8ec399
         {
8ec399
             error_msg("Path '%s' isn't problem directory", dump_dir_name);
8ec399
@@ -102,7 +110,16 @@ static int delete_path(const char *dump_dir_name)
8ec399
         return 403; /* Forbidden */
8ec399
     }
8ec399
 
8ec399
-    delete_dump_dir(dump_dir_name);
8ec399
+    struct dump_dir *dd = dd_fdopendir(dir_fd, dump_dir_name, /*flags:*/ 0);
8ec399
+    if (dd)
8ec399
+    {
8ec399
+        if (dd_delete(dd) != 0)
8ec399
+        {
8ec399
+            error_msg("Failed to delete problem directory '%s'", dump_dir_name);
8ec399
+            dd_close(dd);
8ec399
+            return 400;
8ec399
+        }
8ec399
+    }
8ec399
 
8ec399
     return 0; /* success */
8ec399
 }
8ec399
-- 
8ec399
1.8.3.1
8ec399