Skip to content

Commit 66ad2fb

Browse files
arndbMike Snitzer
authored andcommitted
dm-integrity, dm-verity: reduce stack usage for recheck
The newly added integrity_recheck() function has another larger stack allocation, just like its caller integrity_metadata(). When it gets inlined, the combination of the two exceeds the warning limit for 32-bit architectures and possibly risks an overflow when this is called from a deep call chain through a file system: drivers/md/dm-integrity.c:1767:13: error: stack frame size (1048) exceeds limit (1024) in 'integrity_metadata' [-Werror,-Wframe-larger-than] 1767 | static void integrity_metadata(struct work_struct *w) Since the caller at this point is done using its checksum buffer, just reuse the same buffer in the new function to avoid the double allocation. [Mikulas: add "noinline" to integrity_recheck and verity_recheck. These functions are only called on error, so they shouldn't bloat the stack frame or code size of the caller.] Fixes: c88f5e5 ("dm-integrity: recheck the integrity tag after a failure") Fixes: 9177f3c ("dm-verity: recheck the hash after a failure") Cc: stable@vger.kernel.org Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Mike Snitzer <snitzer@kernel.org>
1 parent 0e0c50e commit 66ad2fb

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

drivers/md/dm-integrity.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,14 +1691,13 @@ static void integrity_sector_checksum(struct dm_integrity_c *ic, sector_t sector
16911691
get_random_bytes(result, ic->tag_size);
16921692
}
16931693

1694-
static void integrity_recheck(struct dm_integrity_io *dio)
1694+
static noinline void integrity_recheck(struct dm_integrity_io *dio, char *checksum)
16951695
{
16961696
struct bio *bio = dm_bio_from_per_bio_data(dio, sizeof(struct dm_integrity_io));
16971697
struct dm_integrity_c *ic = dio->ic;
16981698
struct bvec_iter iter;
16991699
struct bio_vec bv;
17001700
sector_t sector, logical_sector, area, offset;
1701-
char checksum_onstack[max_t(size_t, HASH_MAX_DIGESTSIZE, MAX_TAG_SIZE)];
17021701
struct page *page;
17031702
void *buffer;
17041703

@@ -1734,9 +1733,8 @@ static void integrity_recheck(struct dm_integrity_io *dio)
17341733
goto free_ret;
17351734
}
17361735

1737-
integrity_sector_checksum(ic, logical_sector, buffer,
1738-
checksum_onstack);
1739-
r = dm_integrity_rw_tag(ic, checksum_onstack, &dio->metadata_block,
1736+
integrity_sector_checksum(ic, logical_sector, buffer, checksum);
1737+
r = dm_integrity_rw_tag(ic, checksum, &dio->metadata_block,
17401738
&dio->metadata_offset, ic->tag_size, TAG_CMP);
17411739
if (r) {
17421740
if (r > 0) {
@@ -1851,7 +1849,7 @@ static void integrity_metadata(struct work_struct *w)
18511849
checksums_ptr - checksums, dio->op == REQ_OP_READ ? TAG_CMP : TAG_WRITE);
18521850
if (unlikely(r)) {
18531851
if (r > 0) {
1854-
integrity_recheck(dio);
1852+
integrity_recheck(dio, checksums);
18551853
goto skip_io;
18561854
}
18571855
if (likely(checksums != checksums_onstack))

drivers/md/dm-verity-target.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ static int verity_recheck_copy(struct dm_verity *v, struct dm_verity_io *io,
491491
return 0;
492492
}
493493

494-
static int verity_recheck(struct dm_verity *v, struct dm_verity_io *io,
495-
struct bvec_iter start, sector_t cur_block)
494+
static noinline int verity_recheck(struct dm_verity *v, struct dm_verity_io *io,
495+
struct bvec_iter start, sector_t cur_block)
496496
{
497497
struct page *page;
498498
void *buffer;

0 commit comments

Comments
 (0)