Skip to contentSkip to conversation

dm-integrity: fix a memory leak when rechecking the data

PATCH New Mikulas Patocka 1 participant 1 message Mar 18, 2024 Device mapper

lore
Share & tools
lore

Mikulas Patocka

author maintainer
#0 lore raw

PATCH 1/1 dm-integrity: fix a memory leak when rechecking the data

When we recheck the data after checksum failure, and the recheck is successful, we would leak the "checksums" pointer.

Fixes c88f5e553fe3 ("dm-integrity: recheck the integrity tag after a failure")
---
 drivers/md/dm-integrity.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/dm-integrity.c +3 -3
Index: linux-2.6/drivers/md/dm-integrity.c
===================================================================
@@ -1848,12 +1848,12 @@ again:
 			r = dm_integrity_rw_tag(ic, checksums, &dio->metadata_block, &dio->metadata_offset,
 						checksums_ptr - checksums, dio->op == REQ_OP_READ ? TAG_CMP : TAG_WRITE);
 			if (unlikely(r)) {
+				if (likely(checksums != checksums_onstack))
+					kfree(checksums);
 				if (r > 0) {
-					integrity_recheck(dio, checksums);
+					integrity_recheck(dio, checksums_onstack);
 					goto skip_io;
 				}
-				if (likely(checksums != checksums_onstack))
-					kfree(checksums);
 				goto error;
 			}