Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ascon-aead: zeroize buffer during decryption on failed tag check #659

Merged
merged 6 commits into from
Mar 3, 2025

Conversation

newpavlov
Copy link
Member

No description provided.

@newpavlov newpavlov requested a review from tarcieri March 3, 2025 14:17
@newpavlov newpavlov force-pushed the ascon-aead/fix_decrypt branch from e5e6fa5 to 5bd3538 Compare March 3, 2025 14:22
@tarcieri
Copy link
Member

tarcieri commented Mar 3, 2025

I would suggest fixing it the same way as GHSA-423w-p2w9-r7vq by returning an unmodified buffer, as opposed to a zeroed one

@newpavlov
Copy link
Member Author

IIUC the current implementation performs one-pass decryption. To return "unmodified buffer" we would need to encrypt the message back.

@tarcieri
Copy link
Member

tarcieri commented Mar 3, 2025

Yes, that was how it was solved in GHSA-423w-p2w9-r7vq as well

@newpavlov
Copy link
Member Author

Zeroizing the buffer looks like a good, simple, and straightforward solution to me. Personally, I don't see the point in encrypting the data back, so I don't plan to work on it myself. I created the backport branch, so you could create an alternative PR.

@tarcieri
Copy link
Member

tarcieri commented Mar 3, 2025

If nothing else the solution we should choose should be consistent across crates.

You didn't make a similar argument with aes-gcm FWIW when we were choosing between zeroizing and re-encrypting (just a thumbs up).

I guess we could change both crates if you really want to use zeroing.

A zeroed message may be semantically meaningful in the context where an attacker is using it. If the risk is the caller ignoring the error somehow, I think a zeroed message has a higher chance of causing problems.

Keeping the original ciphertext is closer to a pseudorandom rejection symbol, which IMO is less useful to the attacker.

@tarcieri
Copy link
Member

tarcieri commented Mar 3, 2025

This could also use a regression test

@newpavlov
Copy link
Member Author

newpavlov commented Mar 3, 2025

In the aes-gcm case it did not matter to me, so I left it for you to decide (it was the intended meaning of the thumbs-up). As we discussed in other places, I am not sure about one-pass decryption in the first place. Ideally, we should not touch ciphertext until its integrity was verified. But I understand that from the performance perspective one-pass is important.

Encrypting the buffer back could also be weird together with the planned inout support.

If the risk is the caller ignoring the error somehow, I think a zeroed message has a higher chance of causing problems.

We can not protect users from all potential stupidity on the Earth.

This could also use a regression test

Yes, but I got stuck a bit with the "smart" spectral tests.

@tarcieri
Copy link
Member

tarcieri commented Mar 3, 2025

Ideally, we should not touch ciphertext until its integrity was verified. But I understand that from the performance perspective one-pass is important.

Returning the original ciphertext on verification failure is closer to this ideal than mutating it with zeros, even if it's being decrypted and re-encrypted behind the scenes.

@newpavlov
Copy link
Member Author

What is done in other cryptographic libraries?

@newpavlov newpavlov force-pushed the ascon-aead/fix_decrypt branch from 9b4944f to 27e4444 Compare March 3, 2025 15:13
@tarcieri
Copy link
Member

tarcieri commented Mar 3, 2025

ring does not specify:

When open_in_place() returns Err(..), in_out may have been overwritten in an unspecified way.

The other crates in this repo beyond aes-gcm do not modify the buffer if the tag verification fails.

@newpavlov
Copy link
Member Author

I meant other libraries outside of the Rust ecosystem.

Copy link
Member

@tarcieri tarcieri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have time to do a thorough investigation. This is a security fix so I guess let's just get it out.

It seems easy enough to be have consistent behavior with the other crates I thought I'd point it out along with the past precedent and wasn't expecting this to become some kind of protracted debate, but in the interest of getting the fix out I'll give up for now and perhaps we can change it as a followup.

@newpavlov newpavlov added the security Security-critical issues label Mar 3, 2025
@newpavlov newpavlov merged commit 0eaa918 into backports/ascon-aead-v0.4 Mar 3, 2025
85 checks passed
@newpavlov newpavlov deleted the ascon-aead/fix_decrypt branch March 3, 2025 15:59
newpavlov added a commit that referenced this pull request Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
security Security-critical issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants