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

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