diff mbox series

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

Message ID 4251f231-3423-b664-645d-33f88ada492@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Mike Snitzer
Headers show
Series dm-integrity: fix a memory leak when rechecking the data | expand

Commit Message

Mikulas Patocka March 18, 2024, 5:35 p.m. UTC
When we recheck the data after checksum failure, and the recheck is
successful, we would leak the "checksums" pointer.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Fixes: c88f5e553fe3 ("dm-integrity: recheck the integrity tag after a failure")
Cc: stable@vger.kernel.org

---
 drivers/md/dm-integrity.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series

Patch

Index: linux-2.6/drivers/md/dm-integrity.c
===================================================================
--- linux-2.6.orig/drivers/md/dm-integrity.c	2024-03-11 12:53:59.000000000 +0100
+++ linux-2.6/drivers/md/dm-integrity.c	2024-03-18 17:40:57.000000000 +0100
@@ -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;
 			}