From nobody Mon Nov 09 03:08:35 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jNF9H70P3z70RqV for ; Mon, 09 Nov 2026 03:08:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jNF9H67cCz3DZC for ; Mon, 09 Nov 2026 03:08:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794193715; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vdehOxwIXAsls3GIg5X46c2rebT+iVff+A5I5x+mMHI=; b=RrjCSRUu8NfMY7NQ3dQI8B1IMQ0yt3iZNsMuPYauhWljk8tF3sZ7YwP/pq6ozmDGwKMXUX hr8162lQRYQtiao5HlmSxzRMxgfFaLYM9pDxo7aa9yVKD1nn6b++VnKFgGKH45HbyHVeGx myeMKhnSqvYuRydYLtU5aVfDpomalvIKX1/OhJwZ2L0IuV4LL+ZSP/StnTVMMWSVlzosKy cvWERdsR6dv+R6CoEvlQRYM8FbxGgQQ+DW2jo/xYgGoSP8zyMwbfr7MxRjkWrF598mAZCR rnxu/Bx1u6BBx93hitK+o78gr7rdejz3vJH78XfiWhzYqHJuL5dWwbmGVmfhMA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794193715; b=hz3jWI0T8Q2LLQs/b+GYdRHp/jf3edSxgJJzdz1eKwPsTIPQ9JO2jOcn7od+Plu1sb0Mdo xEyUyXFiXYBT+91qm8tAqfxnq4xiPc6ydBWkeF3C6UYofYjRTdjpjFl8YlJjMbItypG1rn UJF2V7GH3ibok4B02Gis8M3EwF+kCggxU8CsekPfxR0TNTYhED+UNkMLFu0R+GnoVNI3U9 JXc1luQnBk6njvGUuIi72Z1jWgCAVXPUVwaKcyNi3VmSpkiwY0Rt18O7Fw6oY1KiCbk5dI R+W/6P3daL17nUcXfBu4WoIJCQFNPu112M/u5ALuXhGi2SgjH4v98bupQhq1qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794193715; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vdehOxwIXAsls3GIg5X46c2rebT+iVff+A5I5x+mMHI=; b=mr7N6d5D9rO/1N3iC0ot2B8/mw0UIVDJCz/21QhKoRIq3yQxE0vJIc9pNHNPJ/hbb1D1Q+ 7rWbFbU4tjGKwGLNIUuRMZYWkpngbPgTB+YCgtRNEFPlOTkhClk8gJUNYrPJ8xemQuhq0x gNudVZk29BaFeb/FvjurYXPQEog/jXo0YBSp9He+9d/1685EybQU4/UVoN/Z7ZMJ2VlCgo P1+WtyHFJAov7k1r3XnemEd9iC40uCUiatHkxAaYBxLNsQO8SQhZCBlKLPsRdlO1NgaFTN Qexd1TNqICaHXZ/2ZysQMSyYGSR5p8D7434v4i0Zm4Yo/3LVL2EhaM2XQpsq3Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jNF9H5nV7zKxB for ; Mon, 09 Nov 2026 03:08:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1027a by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 09 Nov 2026 03:08:35 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Hayzam Sherif From: Kyle Evans Subject: git: ec6629628cbe - main - linux: Bound native getdents and getdents64 batches List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ec6629628cbed2816f27aed8a6d5f9eb3521c1c1 Auto-Submitted: auto-generated Date: Mon, 09 Nov 2026 03:08:35 +0000 Message-Id: <6af13933.1027a.4326ab18@gitrepo.freebsd.org> The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=ec6629628cbed2816f27aed8a6d5f9eb3521c1c1 commit ec6629628cbed2816f27aed8a6d5f9eb3521c1c1 Author: Hayzam Sherif AuthorDate: 2026-11-09 03:06:11 +0000 Commit: Kyle Evans CommitDate: 2026-11-09 03:06:11 +0000 linux: Bound native getdents and getdents64 batches linux_getdents() and linux_getdents64() round their 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, use min(args->count, MAXBSIZE) instead. A 768-byte request, such as rustix's initial directory read, now uses a 768-byte native buffer rather than 1024. The converted Linux dirent and 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 directory position. Keep the existing sizing for counts below DEV_BSIZE. This fixes the oversized-batch case in both getdents interfaces, including legacy getdents for 32-bit and 64-bit callers. The remaining small-buffer, copyout-failure and old single-entry readdir problems are outside the scope of this change. Fixes: 110f2567cb51 ("linux_file.c: Fix handling of NFS [...]") MFC after: 3 days Sponsored by: Alchemilla Ventures Private Limited Reviewed by: kevans, markj Differential Revision: https://reviews.freebsd.org/D60760 --- sys/compat/linux/linux_file.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c index 023da9a24772..851064537b39 100644 --- a/sys/compat/linux/linux_file.c +++ b/sys/compat/linux/linux_file.c @@ -451,7 +451,15 @@ linux_getdents(struct thread *td, struct linux_getdents_args *args) int buflen, error; size_t retval; - buflen = min(roundup2(args->count, DEV_BSIZE), MAXBSIZE); + /* + * Linux dirent records are no larger than native dirents. + * For counts of at least DEV_BSIZE, keep the native batch + * within the caller's buffer size. + */ + if (args->count >= DEV_BSIZE) + buflen = min(args->count, MAXBSIZE); + else + buflen = roundup2(args->count, DEV_BSIZE); bufsav = buf = malloc(buflen, M_LINUX, M_WAITOK); error = linux_getdirentries(td, args->fd, &buf, buflen, @@ -529,7 +537,15 @@ linux_getdents64(struct thread *td, struct linux_getdents64_args *args) int buflen, error; size_t retval; - buflen = min(roundup2(args->count, DEV_BSIZE), MAXBSIZE); + /* + * Linux dirent64 records are no larger than native dirents. + * For counts of at least DEV_BSIZE, keep the native batch + * within the caller's buffer size. + */ + if (args->count >= DEV_BSIZE) + buflen = min(args->count, MAXBSIZE); + else + buflen = roundup2(args->count, DEV_BSIZE); bufsav = buf = malloc(buflen, M_LINUX, M_WAITOK); error = linux_getdirentries(td, args->fd, &buf, buflen,