Page MenuHomeFreeBSD

unionfs: rework pathname handling
ClosedPublic

Authored by jah on Aug 30 2021, 3:07 PM.
Tags
None
Referenced Files
Unknown Object (File)
Oct 2 2024, 8:04 PM
Unknown Object (File)
Oct 1 2024, 2:15 PM
Unknown Object (File)
Sep 29 2024, 1:22 AM
Unknown Object (File)
Sep 16 2024, 12:15 PM
Unknown Object (File)
Sep 6 2024, 1:50 AM
Unknown Object (File)
Sep 2 2024, 8:00 AM
Unknown Object (File)
Sep 2 2024, 1:51 AM
Unknown Object (File)
Aug 12 2024, 3:49 AM
Subscribers

Details

Summary

Running stress2 unionfs tests reliably produces a namei_zone corruption
panic due to unionfs_relookup() attempting to NUL-terminate a newly-
allocate pathname buffer without first validating the buffer length.

Instead, avoid allocating new pathname buffers in unionfs entirely,
using already-provided buffers while ensuring the the correct flags
are set in struct componentname to prevent freeing or manipulation
of those buffers at lower layers.

While here, also compute and store the path length once in the unionfs
node instead of constantly invoking strlen() on it.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 41263
Build 38152: arc lint + arc unit

Event Timeline

jah requested review of this revision.Aug 30 2021, 3:07 PM

Based on my reading of namei(9) and the code, it seems like what I'm doing here (directly passing the pathname buffer) should be OK.
During testing I also instrumented the unionfs code to verify that the lower layers weren't altering the contents of cn_pnbuf. But being new to namei, I also wouldn't be surprised if this approach is problematic for reasons that aren't apparent to me. If so, I'll go back to allocating duplicate buffers for the unionfs lookup.

sys/fs/unionfs/union_subr.c
856

Fix style while here?

sys/fs/unionfs/union_vnops.c
1017

Is this a logic change? Before we'd set path = NULL in one case - was that a bug?

sys/fs/unionfs/union_vnops.c
1017

From what I could tell that was just dead logic. Before this change, unionfs_mkwhiteout (which is the only thing that consumes 'path' here) would just use cnp->cn_nameptr if the passed-in path was NULL. But also, we were only setting path to NULL for the case in which the remove operation would target the upper vnode, which doesn't produce a call to unionfs_mkwhiteout() in the first place since a plain VOP_REMOVE() for the upper FS should be fine.

kib added inline comments.
sys/fs/unionfs/union_subr.c
332

I would fix style for this statement, even if as a preliminary commit.
No need to cast, + 1, M_WAITOK | M_ZERO.

604

() != 0

This revision is now accepted and ready to land.Aug 30 2021, 11:26 PM
This revision was automatically updated to reflect the committed changes.