mirror of
https://github.com/torvalds/linux.git
synced 2026-09-11 20:13:02 +02:00
dm-integrity: fix infinite loop on discard with large tag size
When integrity_metadata handles a discard, it fills a buffer with DISCARD_FILLER and writes it over the tags, max_blocks blocks at a time. If the kmalloc fails, the buffer is the on-stack array checksums_onstack and max_size is set to HASH_MAX_DIGESTSIZE. So if the tag size is larger than HASH_MAX_DIGESTSIZE, max_blocks is zero, bi_size is never decremented and the loop never terminates. Fix this by using sizeof(checksums_onstack) as max_size. The array has MAX_TAG_SIZE bytes since commitb93b6643e9("dm integrity: fix a crash with unusually large tag size"), so max_blocks is at least 1. Fixes:84597a44a9("dm integrity: add optional discard support") Cc: stable@vger.kernel.org Reviewed-by: Jose Fernandez (Anthropic) <jose.fernandez@linux.dev> Signed-off-by: Ben Cressey <ben@cressey.dev> Assisted-by: Claude:unspecified Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
This commit is contained in:
parent
59e6f919d7
commit
18d80c77b4
|
|
@ -1979,7 +1979,7 @@ static void integrity_metadata(struct work_struct *w)
|
|||
|
||||
if (unlikely(dio->op == REQ_OP_DISCARD)) {
|
||||
unsigned int bi_size = dio->bio_details.bi_iter.bi_size;
|
||||
unsigned int max_size = likely(checksums != checksums_onstack) ? PAGE_SIZE : HASH_MAX_DIGESTSIZE;
|
||||
unsigned int max_size = likely(checksums != checksums_onstack) ? PAGE_SIZE : sizeof(checksums_onstack);
|
||||
unsigned int max_blocks = (max_size - extra_space) / ic->tag_size;
|
||||
sector_t sector = dio->range.logical_sector;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user