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

BugLink: https://bugs.launchpad.net/bugs/2060097

[ Upstream commit 55e565c42dce81a4e49c13262d5bc4eb4c2e588a ]

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: c88f5e553f ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 6d35654f03c35c273240d85ec67e3f2c3596c4e0)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
This commit is contained in:
Mikulas Patocka
2024-03-18 18:35:06 +01:00
committed by Roxana Nicolescu
parent 8a9e74fd34
commit 6bf687bac5
+4 -4
View File
@@ -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 (r > 0) {
integrity_recheck(dio, checksums);
goto skip_io;
}
if (likely(checksums != checksums_onstack))
kfree(checksums);
if (r > 0) {
integrity_recheck(dio, checksums_onstack);
goto skip_io;
}
goto error;
}