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

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