Skip to content

additional recv record hardening#18725

Open
alek-p wants to merge 1 commit into
openzfs:masterfrom
alek-p:write_recv_size
Open

additional recv record hardening#18725
alek-p wants to merge 1 commit into
openzfs:masterfrom
alek-p:write_recv_size

Conversation

@alek-p

@alek-p alek-p commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Quality assurance (non-breaking change which makes the code more robust against bugs)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

Signed-off-by: Alek Pinchuk <Alek.Pinchuk@connectwise.com>
Copilot AI review requested due to automatic review settings July 1, 2026 17:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread module/zfs/dmu_recv.c
Comment on lines +1722 to +1723
if (object == 0 || object > DN_MAX_OBJECT)
return (SET_ERROR(EINVAL));
Comment thread module/zfs/dmu_recv.c
Comment on lines +1982 to +1983
if (raw && drrs->drr_compressed_size == 0)
return (SET_ERROR(EINVAL));
Comment thread module/zfs/dmu_recv.c
Comment on lines +1822 to +1824
/* multi-slot dnode must not extend past DN_MAX_OBJECT */
if (drro->drr_object + dn_slots > DN_MAX_OBJECT)
return (SET_ERROR(EINVAL));
Comment thread module/zfs/dmu_recv.c
Comment on lines +1711 to +1713
* 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 behlendorf added the Status: Code Review Needed Ready for review and testing label Jul 1, 2026

@behlendorf behlendorf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Code Review Needed Ready for review and testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants