Unverified Commit fcb4c240 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!15351 dm integrity: fix memory corruption when tag_size is less than digest size

parents 9422902c 2f341b97
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -3509,6 +3509,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
	}

	if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)) {
		size_t recalc_tags_size;
		if (!ic->internal_hash) {
			r = -EINVAL;
			ti->error = "Recalculate is only valid with internal hash";
@@ -3527,8 +3528,10 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
			r = -ENOMEM;
			goto bad;
		}
		ic->recalc_tags = kvmalloc_array(RECALC_SECTORS >> ic->sb->log2_sectors_per_block,
						 ic->tag_size, GFP_KERNEL);
		recalc_tags_size = (RECALC_SECTORS >> ic->sb->log2_sectors_per_block) * ic->tag_size;
		if (crypto_shash_digestsize(ic->internal_hash) > ic->tag_size)
			recalc_tags_size += crypto_shash_digestsize(ic->internal_hash) - ic->tag_size;
		ic->recalc_tags = kvmalloc(recalc_tags_size, GFP_KERNEL);
		if (!ic->recalc_tags) {
			ti->error = "Cannot allocate tags for recalculating";
			r = -ENOMEM;