Blame SOURCES/0078-libparted-Fix-udev-cookie-leak-in-_dm_resize_partiti.patch

7fd79c
From e7870afe3c13dcc77845d48409daa35e3e42b5fb Mon Sep 17 00:00:00 2001
7fd79c
From: "Brian C. Lane" <bcl@redhat.com>
7fd79c
Date: Thu, 25 May 2017 09:42:23 -0700
7fd79c
Subject: [PATCH] libparted: Fix udev cookie leak in _dm_resize_partition
7fd79c
7fd79c
The function is setting udev cookies, but not using them when waiting
7fd79c
for the task. This results in leaked cookies, which can eventually
7fd79c
exhaust the available number of semaphores.
7fd79c
7fd79c
'dmsetup udevcookies' will show a cookie remaining afterwards, and 'ipcs -s'
7fd79c
will show the semaphores in use.
7fd79c
7fd79c
Also simplified the exit so that the task is always destroyed and memory
7fd79c
is all freed in the same path.
7fd79c
7fd79c
Resolves: rhbz#1455564
7fd79c
---
7fd79c
 libparted/arch/linux.c | 14 +++++++-------
7fd79c
 1 file changed, 7 insertions(+), 7 deletions(-)
7fd79c
7fd79c
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
7fd79c
index 9886d6e..1a35964 100644
7fd79c
--- a/libparted/arch/linux.c
7fd79c
+++ b/libparted/arch/linux.c
7fd79c
@@ -2943,6 +2943,7 @@ _dm_resize_partition (PedDisk* disk, const PedPartition* part)
7fd79c
         char*           vol_name = NULL;
7fd79c
         const char*     dev_name = NULL;
7fd79c
         uint32_t        cookie = 0;
7fd79c
+        int             rc = 0;
7fd79c
 
7fd79c
         /* Get map name from devicemapper */
7fd79c
         struct dm_task *task = dm_task_create (DM_DEVICE_INFO);
7fd79c
@@ -2983,8 +2984,9 @@ _dm_resize_partition (PedDisk* disk, const PedPartition* part)
7fd79c
         /* device-mapper uses 512b units, not the device's sector size */
7fd79c
         dm_task_add_target (task, 0, part->geom.length * (disk->dev->sector_size / PED_SECTOR_SIZE_DEFAULT),
7fd79c
                 "linear", params);
7fd79c
-        if (!dm_task_set_cookie (task, &cookie, 0))
7fd79c
-                goto err;
7fd79c
+        /* NOTE: DM_DEVICE_RELOAD doesn't generate udev events, so no cookie is needed (it will freeze).
7fd79c
+         *       DM_DEVICE_RESUME does, so get a cookie and synchronize with udev.
7fd79c
+         */
7fd79c
         if (dm_task_run (task)) {
7fd79c
                 dm_task_destroy (task);
7fd79c
                 task = dm_task_create (DM_DEVICE_RESUME);
7fd79c
@@ -2993,10 +2995,8 @@ _dm_resize_partition (PedDisk* disk, const PedPartition* part)
7fd79c
                 dm_task_set_name (task, vol_name);
7fd79c
                 if (!dm_task_set_cookie (task, &cookie, 0))
7fd79c
                         goto err;
7fd79c
-                if (dm_task_run (task)) {
7fd79c
-                        free (params);
7fd79c
-                        free (vol_name);
7fd79c
-                        return 1;
7fd79c
+                if (_dm_task_run_wait (task, cookie)) {
7fd79c
+                        rc = 1;
7fd79c
                 }
7fd79c
         }
7fd79c
 err:
7fd79c
@@ -3005,7 +3005,7 @@ err:
7fd79c
                 dm_task_destroy (task);
7fd79c
         free (params);
7fd79c
         free (vol_name);
7fd79c
-        return 0;
7fd79c
+        return rc;
7fd79c
 }
7fd79c
 
7fd79c
 #endif
7fd79c
-- 
7fd79c
2.9.4
7fd79c