Skip to contentSkip to conversation

kpartx: hold device open until partitions have been created

PATCH In review Benjamin Marzinski 2 participants 2 messages Oct 19, 2022 – Oct 20, 2022 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

PATCH 1/1 kpartx: hold device open until partitions have been created

kpartx was closing the whole device after it read the partition information off it. This allowed a race, where the device could be removed and another one created with the same major:minor, after kpartx read the partition information but before it created the partition devices.

---
 kpartx/kpartx.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
kpartx/kpartx.c +3 -8
index 3c499995..1d568c9e 100644
@@ -441,12 +441,7 @@ main(int argc, char **argv){
 		if (n >= 0)
 			printf("%s: %d slices\n", ptp->type, n);
 #endif
-
-		if (n > 0) {
-			close(fd);
-			fd = -1;
-		}
-		else
+		if (n <= 0)
 			continue;
 
 		switch(what) {
@@ -666,9 +661,9 @@ main(int argc, char **argv){
 		if (n > 0)
 			break;
 	}
+	if (fd != -1)
+		close(fd);
 	if (what == LIST && loopcreated) {
-		if (fd != -1)
-			close(fd);
 		if (del_loop(device)) {
 			if (verbose)
 				fprintf(stderr, "can't del loop : %s\n",
Signature · 6 lines
2.17.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Benjamin Marzinski

kpartx was closing the whole device after it read the partition information off it.  This allowed a race, where the device could be removed and another one created with the same major:minor, after kpartx
read the partition information but before it created the partition devices.

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel