[Devel] [PATCH hci-8.2] dm-ploop: fix a double fput of the delta file when ploop_add_delta() fails

Denis V. Lunev den at openvz.org
Thu Nov 19 04:07:58 MSK 2026


From: Denis V. Lunev <den at openvz.org>

ploop_add_delta() stores the file in deltas[level].file before it
allocates mtfile and clones the file for the runners. If kcalloc() or
file_clone_open() fails, the file stays there: ploop_add_deltas_stack()
puts it at err_fput, and ploop_destroy() puts it again from the failed
ctr, because nr_deltas already covers the slot. The second fput() drops
a reference the target does not own, and the last close of the fd then
finds a freed file: "VFS: Close: file count is 0", a BUG with
CONFIG_BUG_ON_DATA_CORRUPTION.

Store the file only after the clones are made. ploop_destroy() still
puts the clones made before the failure.

https://virtuozzo.atlassian.net/browse/VSTOR-155723

Fixes: 762b90ec3324 ("dm-ploop: use filp per thread")
Feature: dm-ploop: ploop target driver
Signed-off-by: Denis V. Lunev <den at openvz.org>
---
 drivers/md/dm-ploop-bat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/dm-ploop-bat.c b/drivers/md/dm-ploop-bat.c
index 5ddb8ffdff07..a2799f4aeb17 100644
--- a/drivers/md/dm-ploop-bat.c
+++ b/drivers/md/dm-ploop-bat.c
@@ -504,7 +504,6 @@ int ploop_add_delta(struct ploop *ploop, u32 level, struct file *file, bool is_r
 
 	ploop_apply_delta_mappings(ploop, deltas, level, &md_root, nr_be);
 
-	deltas[level].file = file;
 	deltas[level].mtfile = kcalloc(ploop->nkt_runners, sizeof(*file),
 					GFP_KERNEL);
 	if (!deltas[level].mtfile) {
@@ -519,6 +518,7 @@ int ploop_add_delta(struct ploop *ploop, u32 level, struct file *file, bool is_r
 		}
 		deltas[level].mtfile[i] = cloned_file;
 	}
+	deltas[level].file = file;
 	deltas[level].file_size = file_size;
 	deltas[level].file_preallocated_area_start = file_size;
 	deltas[level].nr_be = nr_be;
-- 
2.55.0



More information about the Devel mailing list