From 7eba8f98bdc3ed9c0ef1c8527aa61e1a3656449c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <thomas@t-8ch.de>
Date: Thu, 18 May 2023 22:37:10 +0200
Subject: [PATCH] libblkid: constify cached disk data
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The data returned from blkid_probe_get_buffer() and friends may or may
not be cached between different calls.
If one copy is modified this may not be visible in other copies.

This issue can be avoided by making any modification illegal.

See also #2165

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
Reference:https://github.com/util-linux/util-linux/commit/7eba8f98bdc3ed9c0ef1c8527aa61e1a3656449c
Conflict:modify raid1_verify_csum
---
 libblkid/src/superblocks/linux_raid.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libblkid/src/superblocks/linux_raid.c b/libblkid/src/superblocks/linux_raid.c
index 360cd4e..ed2dbb2 100644
--- a/libblkid/src/superblocks/linux_raid.c
+++ b/libblkid/src/superblocks/linux_raid.c
@@ -191,11 +191,10 @@ static int raid1_verify_csum(blkid_probe pr, off_t off,
 	if (!csummed)
 		return 1;
 
-	memset(csummed + offsetof(struct mdp1_super_block, sb_csum), 0,
-			sizeof(mdp1->sb_csum));
-
 	uint64_t csum = 0;
 
+	csum -= le32_to_cpu(*(uint32_t *) (csummed + offsetof(struct mdp1_super_block, sb_csum)));
+
 	while (csummed_size >= 4) {
 		csum += le32_to_cpu(*(uint32_t *) csummed);
 		csummed_size -= 4;
-- 
2.33.0

