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