Page MenuHomeFreeBSD

opencrypto: Handle end-of-cursor conditions in crypto_cursor_segment()
ClosedPublic

Authored by markj on Jun 5 2023, 10:33 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 17 2024, 2:49 AM
Unknown Object (File)
Mar 17 2024, 2:48 AM
Unknown Object (File)
Mar 17 2024, 2:48 AM
Unknown Object (File)
Mar 17 2024, 2:48 AM
Unknown Object (File)
Mar 17 2024, 2:48 AM
Unknown Object (File)
Mar 14 2024, 10:19 AM
Unknown Object (File)
Mar 2 2024, 4:40 PM
Unknown Object (File)
Feb 19 2024, 10:11 PM

Details

Summary

Some consumers, e.g., swcr_encdec(), may call crypto_cursor_segment()
after having advanced the cursor to the end of the buffer. In this case
I believe the right behaviour is to return NULL and a length of 0.

When this occurs with a CRYPTO_BUF_VMPAGE buffer, the cc_vmpage pointer
will point past the end of the page pointer array, so
crypto_cursor_segment() ends up dereferencing a random pointer before
the function returns a length of 0. I believe the uio-backed cursor has
a similar problem.

Fix the problem by checking cc_buf_len before doing anything else.

PR: 271766

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj requested review of this revision.Jun 5 2023, 10:33 PM
markj planned changes to this revision.Jun 6 2023, 1:43 AM

This isn't quite right, some cursor types don't maintain cc_buf_len.

Maintain cc_buf_len for uio cursors; keep the existing check for mbuf cursors.

olce added inline comments.
sys/opencrypto/criov.c
525

Typo?

markj marked an inline comment as done.

Fix a typo.

sys/opencrypto/criov.c
525

Indeed, thank you.

Humm, I had originally considered this a break of the API contract FWIW that callers shouldn't try to use a cursor after advancing past the end (though perhaps I broke that contract myself). Hmm, reading swcr_encdec, it might indeed be a bit annoying to avoid calling crypto_cursor_segment for this case.

This revision is now accepted and ready to land.Jun 7 2023, 6:52 PM