Blame SOURCES/0116-kpartx-hold-device-open-until-partitions-have-been-c.patch

8b67ad
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8b67ad
From: Benjamin Marzinski <bmarzins@redhat.com>
8b67ad
Date: Wed, 19 Oct 2022 12:57:10 -0500
8b67ad
Subject: [PATCH] kpartx: hold device open until partitions have been created
8b67ad
8b67ad
kpartx was closing the whole device after it read the partition
8b67ad
information off it.  This allowed a race, where the device could be
8b67ad
removed and another one created with the same major:minor, after kpartx
8b67ad
read the partition information but before it created the partition
8b67ad
devices.
8b67ad
8b67ad
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
8b67ad
Reviewed-by: Martin Wilck <mwilck@suse.com>
8b67ad
---
8b67ad
 kpartx/kpartx.c | 11 +++--------
8b67ad
 1 file changed, 3 insertions(+), 8 deletions(-)
8b67ad
8b67ad
diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c
8b67ad
index a337a07b..e62b764f 100644
8b67ad
--- a/kpartx/kpartx.c
8b67ad
+++ b/kpartx/kpartx.c
8b67ad
@@ -426,12 +426,7 @@ main(int argc, char **argv){
8b67ad
 		if (n >= 0)
8b67ad
 			printf("%s: %d slices\n", ptp->type, n);
8b67ad
 #endif
8b67ad
-
8b67ad
-		if (n > 0) {
8b67ad
-			close(fd);
8b67ad
-			fd = -1;
8b67ad
-		}
8b67ad
-		else
8b67ad
+		if (n <= 0)
8b67ad
 			continue;
8b67ad
 
8b67ad
 		switch(what) {
8b67ad
@@ -649,9 +644,9 @@ main(int argc, char **argv){
8b67ad
 		if (n > 0)
8b67ad
 			break;
8b67ad
 	}
8b67ad
+	if (fd != -1)
8b67ad
+		close(fd);
8b67ad
 	if (what == LIST && loopcreated) {
8b67ad
-		if (fd != -1)
8b67ad
-			close(fd);
8b67ad
 		if (del_loop(device)) {
8b67ad
 			if (verbose)
8b67ad
 				fprintf(stderr, "can't del loop : %s\n",