CVE-2022-23951 (Python, published 2022-09-21T19:15Z)
Description: value: In Keylime before 6.3.0, quote responses from the agent can contain possibly untrusted ZIP data which can lead to zip bombs.
Severity: nan (CVSS v3 base score: 5.5)
Weakness: NVD-CWE-noinfo \u2014 Insufficient Information
There is insufficient information about the issue to classify it; details are unkown or unspecified.
Repository: https://github.com/keylime/keylime
Files changed:
keylime/cloud_verifier_common.py
keylime/tenant.py
keylime/tpm/tpm_abstract.py
keylime/tpm/tpm_main.py
Commit message: tpm: do not compress quote with zlib by default

Pythons zlib decompression has no mitigations against zip bombs or similar
attacks, so we remove the compression for the quote data.

The data itself is rather small compared to the IMA or UEFI event log.

Signed-off-by: Thore Sommer <mail@thson.de>


Vulnerable code:
        agent['mb_refstate'])
        failure = self.tpm_instance.check_quote(AgentAttestState(self.agent_uuid), self.nonce, public_key, quote, self.registrar_data['aik_tpm'], hash_alg=hash_alg)
    def create_quote(self, nonce, data=None, pcrmask=EMPTYMASK, hash_alg=None):
    def check_quote(self, agentAttestState, nonce, data, quote, aikTpmFromRegistrar, tpm_policy={}, ima_measurement_list=None, allowlist={}, hash_alg=None, ima_keyrings=None, mb_measurement_list=None, mb_refstate=None):
    def create_quote(self, nonce, data=None, pcrmask=tpm_abstract.AbstractTPM.EMPTYMASK, hash_alg=None):
                quote_b64encode = base64.b64encode(zlib.compress(quoteraw))
                sigraw_b64encode = base64.b64encode(zlib.compress(sigraw))
                pcrraw_b64encode = base64.b64encode(zlib.compress(pcrraw))
    def _tpm2_checkquote(self, aikTpmFromRegistrar, quote, nonce, hash_alg):
        quoteblob = zlib.decompress(base64.b64decode(quote_tokens[0]))
        sigblob = zlib.decompress(base64.b64decode(quote_tokens[1]))
        pcrblob = zlib.decompress(base64.b64decode(quote_tokens[2]))
                    mb_measurement_list=None, mb_refstate=None) -> Failure:
        retout, success = self._tpm2_checkquote(aikTpmFromRegistrar, quote, nonce, hash_alg)

Fixed code:
        agent['mb_refstate'],
        compressed=(agent['supported_version'] == "1.0"))  # TODO: change this to always False after initial update
        failure = self.tpm_instance.check_quote(AgentAttestState(self.agent_uuid), self.nonce, public_key, quote,
                                                self.registrar_data['aik_tpm'], hash_alg=hash_alg,
                                                compressed=(self.supported_version == "1.0"))
    def create_quote(self, nonce, data=None, pcrmask=EMPTYMASK, hash_alg=None, compress=False):
    def check_quote(self, agentAttestState, nonce, data, quote, aikTpmFromRegistrar, tpm_policy={}, ima_measurement_list=None, allowlist={}, hash_alg=None, ima_keyrings=None, mb_measurement_list=None, mb_refstate=None, compressed=False):
    def create_quote(self, nonce, data=None, pcrmask=tpm_abstract.AbstractTPM.EMPTYMASK, hash_alg=None, compress=False):
                if compress:
                    quoteraw = zlib.compress(quoteraw)
                    sigraw = zlib.compress(sigraw)
                    pcrraw = zlib.compress(pcrraw)
                quote_b64encode = base64.b64encode(quoteraw)
                sigraw_b64encode = base64.b64encode(sigraw)
                pcrraw_b64encode = base64.b64encode(pcrraw)
    def _tpm2_checkquote(self, aikTpmFromRegistrar, quote, nonce, hash_alg, compressed):
        :param compressed: if the quote data is compressed with zlib or not
        quoteblob = base64.b64decode(quote_tokens[0])
        sigblob = base64.b64decode(quote_tokens[1])
        pcrblob = base64.b64decode(quote_tokens[2])

        if compressed:
            logger.warning("Decompressing quote data which is unsafe!")
            quoteblob = zlib.decompress(quoteblob)
            sigblob = zlib.decompress(sigblob)
            pcrblob = zlib.decompress(pcrblob)

                    mb_measurement_list=None, mb_refstate=None, compressed=False) -> Failure:
        retout, success = self._tpm2_checkquote(aikTpmFromRegistrar, quote, nonce, hash_alg, compressed)