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

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