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

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