Blame SOURCES/CVE-2023-23931.patch

34e3b9
From 3914106b613ad4f5f27a2d1b3fc8fc2efb41dec6 Mon Sep 17 00:00:00 2001
34e3b9
From: Alex Gaynor <alex.gaynor@gmail.com>
34e3b9
Date: Tue, 31 Jan 2023 08:33:54 -0500
34e3b9
Subject: [PATCH] Don't allow update_into to mutate immutable objects
34e3b9
34e3b9
---
34e3b9
 src/cryptography/hazmat/backends/openssl/ciphers.py | 2 +-
34e3b9
 tests/hazmat/primitives/test_ciphers.py             | 8 ++++++++
34e3b9
 2 files changed, 9 insertions(+), 1 deletion(-)
34e3b9
34e3b9
diff --git a/src/cryptography/hazmat/backends/openssl/ciphers.py b/src/cryptography/hazmat/backends/openssl/ciphers.py
34e3b9
index 1058de9..17abd3a 100644
34e3b9
--- a/src/cryptography/hazmat/backends/openssl/ciphers.py
34e3b9
+++ b/src/cryptography/hazmat/backends/openssl/ciphers.py
34e3b9
@@ -157,7 +157,7 @@ class _CipherContext:
34e3b9
         data_processed = 0
34e3b9
         total_out = 0
34e3b9
         outlen = self._backend._ffi.new("int *")
34e3b9
-        baseoutbuf = self._backend._ffi.from_buffer(buf)
34e3b9
+        baseoutbuf = self._backend._ffi.from_buffer(buf, require_writable=True)
34e3b9
         baseinbuf = self._backend._ffi.from_buffer(data)
34e3b9
 
34e3b9
         while data_processed != total_data_len:
34e3b9
diff --git a/tests/hazmat/primitives/test_ciphers.py b/tests/hazmat/primitives/test_ciphers.py
34e3b9
index 02127dd..bf3b047 100644
34e3b9
--- a/tests/hazmat/primitives/test_ciphers.py
34e3b9
+++ b/tests/hazmat/primitives/test_ciphers.py
34e3b9
@@ -318,6 +318,14 @@ class TestCipherUpdateInto:
34e3b9
         with pytest.raises(ValueError):
34e3b9
             encryptor.update_into(b"testing", buf)
34e3b9
 
34e3b9
+    def test_update_into_immutable(self, backend):
34e3b9
+        key = b"\x00" * 16
34e3b9
+        c = ciphers.Cipher(AES(key), modes.ECB(), backend)
34e3b9
+        encryptor = c.encryptor()
34e3b9
+        buf = b"\x00" * 32
34e3b9
+        with pytest.raises((TypeError, BufferError)):
34e3b9
+            encryptor.update_into(b"testing", buf)
34e3b9
+
34e3b9
     @pytest.mark.supported(
34e3b9
         only_if=lambda backend: backend.cipher_supported(
34e3b9
             AES(b"\x00" * 16), modes.GCM(b"\x00" * 12)
34e3b9
-- 
34e3b9
2.39.1
34e3b9