Blame SOURCES/CVE-2023-23931.patch

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