From nobody Wed Nov 11 19:01:41 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 4jPtD622hfz70cKn for ; Wed, 11 Nov 2026 19:01:42 +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 4jPtD56Thqz3Q8H for ; Wed, 11 Nov 2026 19:01:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794423701; 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=Aaq1WAFQyr3T6KyQWgAveBozg9QQla6F2ZSMyqFh1WY=; b=FaSpptyqteXnnRTtVNDvMi3oYCTSi0OBukgpCGsAVlAQFsGzUcNA1GMM3OTjgQHp07SAkr PK8+PvMiJPQUjpBlpWcDVFFH0clNVNss4uX2DvSbl9uPhyDohejfT/CvKk9m9oRc9fqKsu dGNqVl+TSdcOSadBNcTot3U/LtcvCIMmrkMQtXg0z9Icn5t9Ypy8bJXFB7ym/iJ2xuCAsB AKX7btShuYUEeDbYrPGS32mQA7+MSY5mH1z/comTWmpnCr1HRQN2Uh9+AqkQ2FIQkXH2eW XoMC6dT+V4rX/xwzn9PuK4g4HOR+uSOv5Ur8YYZRiIe+B7yLRMfqVHtnvR7XYQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794423701; b=Kcn9Po0+DJiBWIGpZpfp23fg+Lh+d403HDGlJmfYXkz+AEhvyAyHK6yK+gjYQpvjhO6XDG o1IkoW7nlbA6BWBD7xqILpIlOyDUGaqdvrUJuVOp+aWpxmhBLMwN5IPjWE7vMnh6f6V9eh Bi5UAiMXNB/+i4ueUIhtQWULDz8mF/5ozjsy8Oteh21Q85s9CLl8gkJP2OqI9y9FRgxfbF QUDROyafsyc/CrHG02vVpJkDrpiPiTflemEdvrm5aky1+wWy8M4X5yg5FfkODxXMyCEUpa bURxF6TgM7ybeWLwiHUcRQOaU+z4v2XKvFTsdPqx2jmkWJ2NACZduTIQcdgBnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794423701; 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=Aaq1WAFQyr3T6KyQWgAveBozg9QQla6F2ZSMyqFh1WY=; b=m6PETx7L+chWILhsog4nR0A5DeeVwhv25eMWSQS3olG8CwoWZK8woRScLnILIQ9q91xrlx 3Plv+Wr/G5D/taYMyVkLfEeuwhbQPmK3hr5OcPPF1Kd3yJeeYv1DhQIPnMXbdOA+9VbbLk LwRrP49qWZAOJ7Wrzh5e1wHAJ6HOJaIjlnF2vSIpAtQ/QDa+FnO+R6eGpqhBfW8vM7FIQv VLX3HssbQqISO4XzVKQxSB2q7e5nzjSZThSn4anPdiMlODAKvlz/2Q/yOGe2rVFFwi/M7U 5Ezke/JSvFc0v1l7RfDZU7my6VKtS7jsoGVzl5A1t3WJULBD0Ii/949VQ1pM0A== 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 4jPtD55PT9zRR4 for ; Wed, 11 Nov 2026 19:01:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 480c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 11 Nov 2026 19:01:41 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Hayzam Sherif From: Kyle Evans Subject: git: 4d419a4118ee - stable/15 - 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 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/stable/15 X-Git-Reftype: branch X-Git-Commit: 4d419a4118eecbe178de6b22759dae54895befea Auto-Submitted: auto-generated Date: Wed, 11 Nov 2026 19:01:41 +0000 Message-Id: <6af4bb95.480c.1dab20fa@gitrepo.freebsd.org> The branch stable/15 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=4d419a4118eecbe178de6b22759dae54895befea commit 4d419a4118eecbe178de6b22759dae54895befea Author: Hayzam Sherif AuthorDate: 2026-11-09 03:06:11 +0000 Commit: Kyle Evans CommitDate: 2026-11-11 18:59:06 +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 [...]") Sponsored by: Alchemilla Ventures Private Limited Reviewed by: kevans, markj (cherry picked from commit ec6629628cbed2816f27aed8a6d5f9eb3521c1c1) --- 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,