From nobody Thu Nov 12 23:41:52 2026 X-Original-To: dev-commits-src-branches@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 4jQcNx1ynxz6xnHX for ; Thu, 12 Nov 2026 23:41:53 +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 4jQcNw6V3Dz4RfR for ; Thu, 12 Nov 2026 23:41:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794526912; 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=xm6tuBOmdikNMtYQP81oTCzmoxNSyKVd4i1f1VPPe+U=; b=HQil0x4YlDpAqgWvW1Wn1Dui0D5e1v8xS0QcZO2d8AuZ+gSqdzfU+2B7NbPIUcxCuTo8dG UxX+mKyVdh3C8vYBxw+Kx/IKfTKhmzac0FG6yh9hoU3p3d6mT8WXsxqGws1vwiM5kW7zrO 925yOeuUK/q9WZcyUxXNmLLmkzT8ZBCpXozNQwI9DRMnduZiTJGpQ9iXHRKErVFcuYYKyp Z5ARBTiI8LCSco2mVmUrKwjXO8eSPe2Yhv7Q8f8Xm5rZQh85miHJ8w+2syuGyQSfEwxU1b bk7kWQH2YpRB4TNuaZCyjhLJhaZ9HCc2uPdeKZVgi1eazP4OlnAwAuWkcLCxSA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794526912; b=UAt4axESTETnaT3iiWCpva8CRqS5xMP7v/2PqD7/MgBC+ujaoWcAVX+2e2wmbYOxJg+dg0 m9iMoKE1+ffMY6Aqtq3tEB0E7DQaGZDvXIU0QVsVd8rGixNBK1A5UTBe9ANcV0Dv5j1oAQ GrKyYvFW8LeR76C+H2M8aUDo9t7JxLpIBQGEGrwGU3WJeOJF4VLHuAAMDC6z4d+BIwa1C3 /yqs2aXk1wgvOQVDzr3wIISoNpVyO2Ryn/YxhBhlGl5UgEMHz4Gn1lr4BVHnBhTY3OUbfW RtWCS/ztfEQrMtITeV81m1oDqvTFABBGRO+Ga3cgX3WCJixUv3nnC7wbtpiGgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794526912; 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=xm6tuBOmdikNMtYQP81oTCzmoxNSyKVd4i1f1VPPe+U=; b=rHmLZfSgO8bZpa8aMwLYBpnoQaOq4uccSy0E1TXCddnPEYQBfnI7mFgbvMK8m/+tJdyWUH +IlO1lx99+EmS+vyFvPZT+V0pT8w2YcB8ReHQefZlB2BpC5DdjMr89jzU53T/5WbnD/0um 2U8f4Uy0FLDySuUxRd2L9sZAoeO0n4lChEOK7xVbM/k6bC56XACWSNogXCgcWnvk+wkt75 5s+QnubjoixC3A1oGrzdfYKG9Kpd3UnNP/R6OIeGMizcBbIRU8li3z4YTR4b9Mi+pidY71 qZhTODBc0sZoQYrjHgsgNnSgEVCKE8P39PTZuEPKUIF9Xx6NKIWVSgK8f87qoA== 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 4jQcNw5bV0z1NMs for ; Thu, 12 Nov 2026 23:41:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id d7fa by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 12 Nov 2026 23:41:52 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Hayzam Sherif From: Colin Percival Subject: git: 4cbde86a6de2 - releng/15.2 - linux: Bound native getdents and getdents64 batches List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches X-BeenThere: dev-commits-src-branches@freebsd.org List-Id: Commits to the stable branches of the FreeBSD 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: cperciva X-Git-Repository: src X-Git-Refname: refs/heads/releng/15.2 X-Git-Reftype: branch X-Git-Commit: 4cbde86a6de284899118b9c4453ddaced9a8b321 Auto-Submitted: auto-generated Date: Thu, 12 Nov 2026 23:41:52 +0000 Message-Id: <6af64ec0.d7fa.6d09315e@gitrepo.freebsd.org> The branch releng/15.2 has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=4cbde86a6de284899118b9c4453ddaced9a8b321 commit 4cbde86a6de284899118b9c4453ddaced9a8b321 Author: Hayzam Sherif AuthorDate: 2026-11-09 03:06:11 +0000 Commit: Colin Percival CommitDate: 2026-11-12 23:41:23 +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. Approved by: re (cperciva) Fixes: 110f2567cb51 ("linux_file.c: Fix handling of NFS [...]") Sponsored by: Alchemilla Ventures Private Limited Reviewed by: kevans, markj (cherry picked from commit ec6629628cbed2816f27aed8a6d5f9eb3521c1c1) (cherry picked from commit 4d419a4118eecbe178de6b22759dae54895befea) --- 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 9a1f21d5feb7..86c96a000366 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,