additional recv record hardening#18725
Conversation
Signed-off-by: Alek Pinchuk <Alek.Pinchuk@connectwise.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors receive-side replay record validation in dmu_recv.c, centralizing checks into per-record validators and adding additional hardening (notably overflow checks) before payload reads and before applying records to the DMU.
Changes:
- Introduces shared helper routines for validating DRR_* record fields and enforcing pool/on-wire limits consistently.
- Moves/expands validation so malformed records are rejected earlier (before reading payloads and before applying changes).
- Adds overflow checks in write batching and raw maxblkid range handling to prevent unsafe arithmetic.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (object == 0 || object > DN_MAX_OBJECT) | ||
| return (SET_ERROR(EINVAL)); |
| if (raw && drrs->drr_compressed_size == 0) | ||
| return (SET_ERROR(EINVAL)); |
| /* multi-slot dnode must not extend past DN_MAX_OBJECT */ | ||
| if (drro->drr_object + dn_slots > DN_MAX_OBJECT) | ||
| return (SET_ERROR(EINVAL)); |
| * Record validators return ERANGE when a size field exceeds a pool or | ||
| * on-wire limit, EINVAL when below a minimum or malformed, and EINVAL | ||
| * for other inconsistent records. |
behlendorf
left a comment
There was a problem hiding this comment.
Yeah, the additional validation is welcome.
Thinking about this more broadly, it would be nice if we could structure things such that zstream could leverage these same checks without duplicating code. zstream is already linked against libzpool.so so if the new recv_check_* functions weren't declared static and added to sys/dmu_recv.h you should be able to just call them.
Better yet, if these new checks returned a descriptive error message in addition to EINVAL that would be quite helpful. I see there's already an errors nvlist plumbed through to zfs_ioc_recv_impl() we could easily leverage to report the details back to user space. So this might not be that big of a lift actually.
That said, I'm fine with making the hardening changes in this stand alone PR and then either investigating the above improvements in a follow up PR, or as additional commits in this PR.
Motivation and Context
This extends the recv checking done in #18623
Description
This patch refactors and enhances how we do recv record validation. I've made sure to keep all existing check and added a few new ones.
How Has This Been Tested?
zfs-tests
Types of changes
Checklist:
Signed-off-by.