Page MenuHomeFreeBSD

krb5: Fix use-after-frees possible with asynchronous crypto providers
Needs ReviewPublic

Authored by markj on Aug 17 2022, 10:08 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Oct 11, 7:51 PM
Unknown Object (File)
Fri, Oct 10, 11:00 PM
Unknown Object (File)
Sun, Oct 5, 6:04 AM
Unknown Object (File)
Sun, Sep 14, 2:32 PM
Unknown Object (File)
Sun, Sep 14, 11:26 AM
Unknown Object (File)
Sep 9 2025, 1:40 AM
Unknown Object (File)
Sep 4 2025, 12:07 PM
Unknown Object (File)
Sep 4 2025, 8:03 AM
Subscribers

Details

Reviewers
jhb
Summary

CRYPTO_F_DONE is set once the opencrypto driver has finished processing
a request, but before the callback is invoked. It cannot be used to
determine whether is safe to free a cryptop.

Modify the krb5 completion callbacks to set crp_opaque to NULL once it
is safe to free the request, instead of relying on CRYPTO_F_DONE.

PR: 265852

Test Plan

Untested so far.

I'm not sure if it is even practical to use async crypto with
krb5 given that there's no way to propagate errors up. Perhaps this should
be handled with a fallback path.

Diff Detail

Repository
rG FreeBSD src repository
Lint
No Lint Coverage
Unit
No Test Coverage
Build Status
Buildable 47111
Build 43998: arc lint + arc unit

Event Timeline

This revision is now accepted and ready to land.Aug 23 2022, 9:36 PM

Panic when an error other than EAGAIN occurs. Currently krb5 has no way to
pass such errors up. In this case we should probably be falling back to
software crypto, but in the meantime it's better to panic rather than silently
ignore the request.

This revision now requires review to proceed.Aug 23 2022, 10:07 PM
sys/kgssapi/krb5/kcrypto_aes.c
182

We should check crp_etype and panic here in case a synchronous session fails.

352

Likewise.

sys/kgssapi/krb5/kcrypto_aes.c
182

Or just move the error checking in aes_crypto_cb() to before the CRYPTO_SESS_SYNC() check. Then it's all done in one place. I'm not sure how a synchronous session can fail, but yeah it's better to simply check.

markj marked 2 inline comments as done.
  • Check for errors from synchronous sessions too.
  • Add a comment explaining why we panic.