Page MenuHomeFreeBSD

linux: Avoid oversized native getdents64 batches
Needs ReviewPublic

Authored by hayzam_gmail.com on Fri, Oct 16, 2:22 AM.
Tags
None
Referenced Files
F176300337: D60760.diff
Sat, Oct 17, 6:38 PM
F176266680: D60760.id190009.diff
Sat, Oct 17, 12:49 PM
F176217871: D60760.id190009.diff
Sat, Oct 17, 1:26 AM
Unknown Object (File)
Fri, Oct 16, 4:29 PM
Unknown Object (File)
Fri, Oct 16, 7:51 AM
Unknown Object (File)
Fri, Oct 16, 7:30 AM
Unknown Object (File)
Fri, Oct 16, 7:27 AM
Unknown Object (File)
Fri, Oct 16, 6:55 AM
Subscribers

Details

Reviewers
markj
Summary

linux_getdents64() rounds its native read size up to DEV_BSIZE before
converting entries. For an unaligned caller buffer, the native batch
can contain more entries than fit in the Linux buffer. Conversion then
returns EINVAL even after copying complete entries, and the native read
has already advanced the directory position.

For counts of at least DEV_BSIZE, round the native batch down instead.
A 768-byte request, such as rustix's initial directory read, now reads
512 native bytes rather than 1024. The converted Linux dirent64 records
are no larger than their native counterparts, so the whole translated
batch fits. Returning a short batch is allowed, and consuming the whole
native batch avoids needing to rewind the position or change the NFS
client.

Keep the existing sizing for counts below DEV_BSIZE. This fixes the
oversized-batch case, not the remaining small-buffer, copyout-failure,
or legacy getdents/readdir problems.

Fixes: 110f2567cb51 ("linux_file.c: Fix handling of NFS getdents() emulation")

Test Plan

Reproduced the original EINVAL failure with the unmodified Zed 1.24.2 remote server on the stock kernel.
With the patch, Zed scans correctly on UFS, ZFS and NFSv4.2 mounts from FreeBSD and Linux servers.

Directory-read checks also passed over NFSv3, with and without READDIRPLUS,
covering buffer sweeps, shared fds, CAP_READ-only descriptors and 32-bit getdents64.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 78253
Build 75136: arc lint + arc unit