Skip to content

Commit 55e565c

Browse files
Mikulas PatockaMike Snitzer
authored andcommitted
dm-integrity: fix a memory leak when rechecking the data
Memory for the "checksums" pointer will leak if the data is rechecked after checksum failure (because the associated kfree won't happen due to 'goto skip_io'). Fix this by freeing the checksums memory before recheck, and just use the "checksum_onstack" memory for storing checksum during recheck. Fixes: c88f5e5 ("dm-integrity: recheck the integrity tag after a failure") Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Mike Snitzer <snitzer@kernel.org>
1 parent 277100b commit 55e565c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/md/dm-integrity.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,12 +1848,12 @@ static void integrity_metadata(struct work_struct *w)
18481848
r = dm_integrity_rw_tag(ic, checksums, &dio->metadata_block, &dio->metadata_offset,
18491849
checksums_ptr - checksums, dio->op == REQ_OP_READ ? TAG_CMP : TAG_WRITE);
18501850
if (unlikely(r)) {
1851+
if (likely(checksums != checksums_onstack))
1852+
kfree(checksums);
18511853
if (r > 0) {
1852-
integrity_recheck(dio, checksums);
1854+
integrity_recheck(dio, checksums_onstack);
18531855
goto skip_io;
18541856
}
1855-
if (likely(checksums != checksums_onstack))
1856-
kfree(checksums);
18571857
goto error;
18581858
}
18591859

0 commit comments

Comments
 (0)