From ca418d6cc684057bcead18b3dd68d64cb3e156af Mon Sep 17 00:00:00 2001
From: Stephan Mueller <smueller@chronox.de>
Date: Thu, 30 Jul 2026 08:39:37 +0200
Subject: [PATCH] Add safety measure to prevent IV reuse

Signed-off-by: Zoltan Fridrich <zfridric@redhat.com>
Signed-off-by: Stephan Mueller <smueller@chronox.de>

CVE: CVE-2026-71225
Upstream-Status: Backport [https://github.com/smuellerDD/libkcapi/commit/017adba8f54f36f92e1919687fb67a89c4d299c6]

Dropped changes to the CHANGES.md file.

Signed-off-by: Ankur Tyagi <ankur.tyagi85@gmail.com>
---
 lib/kcapi-kernel-if.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/kcapi-kernel-if.c b/lib/kcapi-kernel-if.c
index a54cdaa..859ecdf 100644
--- a/lib/kcapi-kernel-if.c
+++ b/lib/kcapi-kernel-if.c
@@ -1387,6 +1387,15 @@ ssize_t _kcapi_cipher_crypt_chunk(struct kcapi_handle *handle,
 		inlen -= inprocess;
 		out += ret;
 		outlen -= (size_t)ret;
+
+		/*
+		 * Clear the IV so subsequent chunks do not override the
+		 * kernel's chained IV via ALG_SET_IV.  The kernel updates
+		 * its internal IV after each operation; by not sending
+		 * ALG_SET_IV for later chunks, the next chunk continues
+		 * where the previous one left off.
+		 */
+		handle->cipher.iv = NULL;
 	}
 
 	return totallen;
