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

!11181 block: initialize integrity buffer to zero before writing it to media

parents 9c002e22 5494fb2d
Loading
Loading
Loading
Loading
+10 −1
Original line number Original line Diff line number Diff line
@@ -216,6 +216,7 @@ bool bio_integrity_prep(struct bio *bio)
	unsigned int bytes, offset, i;
	unsigned int bytes, offset, i;
	unsigned int intervals;
	unsigned int intervals;
	blk_status_t status;
	blk_status_t status;
	gfp_t gfp = GFP_NOIO;


	if (!bi)
	if (!bi)
		return true;
		return true;
@@ -238,12 +239,20 @@ bool bio_integrity_prep(struct bio *bio)
		if (!bi->profile->generate_fn ||
		if (!bi->profile->generate_fn ||
		    !(bi->flags & BLK_INTEGRITY_GENERATE))
		    !(bi->flags & BLK_INTEGRITY_GENERATE))
			return true;
			return true;

		/*
		 * Zero the memory allocated to not leak uninitialized kernel
		 * memory to disk.  For PI this only affects the app tag, but
		 * for non-integrity metadata it affects the entire metadata
		 * buffer.
		 */
		gfp |= __GFP_ZERO;
	}
	}
	intervals = bio_integrity_intervals(bi, bio_sectors(bio));
	intervals = bio_integrity_intervals(bi, bio_sectors(bio));


	/* Allocate kernel buffer for protection data */
	/* Allocate kernel buffer for protection data */
	len = intervals * bi->tuple_size;
	len = intervals * bi->tuple_size;
	buf = kmalloc(len, GFP_NOIO | q->bounce_gfp);
	buf = kmalloc(len, gfp | q->bounce_gfp);
	status = BLK_STS_RESOURCE;
	status = BLK_STS_RESOURCE;
	if (unlikely(buf == NULL)) {
	if (unlikely(buf == NULL)) {
		printk(KERN_ERR "could not allocate integrity buffer\n");
		printk(KERN_ERR "could not allocate integrity buffer\n");