Skip to content

Commit

Permalink
Cherry-pick fix for CVE-2023-23931 from (pyca#8230)
Browse files Browse the repository at this point in the history
Don't allow update_into to mutate immutable objects pyca#8230
pyca#8230
  • Loading branch information
icanhasmath committed Jan 18, 2024
1 parent 25c123c commit 6b20296
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Changelog
certificates from a PKCS#7 bundle. Credit to **pkuzco** for reporting the
issue. **CVE-2023-49083**

* **SECURITY ISSUE** - Fixed a bug where ``Cipher.update_into`` accepted Python
buffer protocol objects, but allowed immutable buffers. **CVE-2023-23931**

.. _v3-3-2:

3.3.2 - 2021-02-07
Expand Down
2 changes: 1 addition & 1 deletion src/cryptography/hazmat/backends/openssl/ciphers.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def update_into(self, data, buf):
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:
Expand Down
8 changes: 8 additions & 0 deletions tests/hazmat/primitives/test_ciphers.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,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)
Expand Down

0 comments on commit 6b20296

Please sign in to comment.