From d6951dca25de45abd52da51b608055371fbcde4e Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Tue, 7 Feb 2023 12:24:19 -0600 Subject: [PATCH] changelog + security fix backport (#8231) * Don't allow update_into to mutate immutable objects (#8230) * add changelog for 39.0.1 * oops * bump versions * remove circle --------- Co-authored-by: Alex Gaynor --- CHANGELOG.rst | 9 +++++++++ src/cryptography/__about__.py | 2 +- src/cryptography/hazmat/backends/openssl/ciphers.py | 2 +- tests/hazmat/primitives/test_ciphers.py | 8 ++++++++ vectors/cryptography_vectors/__about__.py | 2 +- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index bd70b9bc7b34..3742c6ac945c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,15 @@ Changelog ========= +.. _v39-0-1: + +39.0.1 - 2023-02-07 +~~~~~~~~~~~~~~~~~~~ + +* **SECURITY ISSUE** - Fixed a bug where ``Cipher.update_into`` accepted Python + buffer protocol objects, but allowed immutable buffers. **CVE-2023-23931** +* Updated Windows, macOS, and Linux wheels to be compiled with OpenSSL 3.0.8. + .. _v39-0-0: 39.0.0 - 2023-01-01 diff --git a/src/cryptography/__about__.py b/src/cryptography/__about__.py index 83439a962dd3..bd0b15c14657 100644 --- a/src/cryptography/__about__.py +++ b/src/cryptography/__about__.py @@ -9,7 +9,7 @@ "__copyright__", ] -__version__ = "39.0.0" +__version__ = "39.0.1" __author__ = "The Python Cryptographic Authority and individual contributors" __copyright__ = "Copyright 2013-2022 {}".format(__author__) diff --git a/src/cryptography/hazmat/backends/openssl/ciphers.py b/src/cryptography/hazmat/backends/openssl/ciphers.py index fd2b6612f046..e5c2b6fd8453 100644 --- a/src/cryptography/hazmat/backends/openssl/ciphers.py +++ b/src/cryptography/hazmat/backends/openssl/ciphers.py @@ -156,7 +156,7 @@ def update_into(self, data: bytes, buf: bytes) -> int: data_processed = 0 total_out = 0 outlen = self._backend._ffi.new("int *") - baseoutbuf = self._backend._ffi.from_buffer(buf) + baseoutbuf = self._backend._ffi.from_buffer(buf, require_writable=True) baseinbuf = self._backend._ffi.from_buffer(data) while data_processed != total_data_len: diff --git a/tests/hazmat/primitives/test_ciphers.py b/tests/hazmat/primitives/test_ciphers.py index 02127dd9cab5..bf3b047dec25 100644 --- a/tests/hazmat/primitives/test_ciphers.py +++ b/tests/hazmat/primitives/test_ciphers.py @@ -318,6 +318,14 @@ def test_update_into_buffer_too_small(self, backend): with pytest.raises(ValueError): encryptor.update_into(b"testing", buf) + def test_update_into_immutable(self, backend): + key = b"\x00" * 16 + c = ciphers.Cipher(AES(key), modes.ECB(), backend) + encryptor = c.encryptor() + buf = b"\x00" * 32 + with pytest.raises((TypeError, BufferError)): + encryptor.update_into(b"testing", buf) + @pytest.mark.supported( only_if=lambda backend: backend.cipher_supported( AES(b"\x00" * 16), modes.GCM(b"\x00" * 12) diff --git a/vectors/cryptography_vectors/__about__.py b/vectors/cryptography_vectors/__about__.py index 9b607dd65f03..9452a5c1e801 100644 --- a/vectors/cryptography_vectors/__about__.py +++ b/vectors/cryptography_vectors/__about__.py @@ -6,4 +6,4 @@ "__version__", ] -__version__ = "39.0.0" +__version__ = "39.0.1"