From nobody Thu Nov 12 23:41:52 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 4jQcNx22mPz6xnNX 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 4jQcNx023Xz4Rht for ; Thu, 12 Nov 2026 23:41:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794526913; 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=yPNy8uLr2WRKrJ7cTSopA+r7LxQZh7Sj0YInbZdZqtbmt4/yLn+N7nM+O5DZJba4L772+O KOGAFx238ywYN3UkSwE/+xPuez2gphnVshB2Wc+yo+yhNXAGX2+hN8wygOgG2hAeCU5YE9 NzzAGjcHuJDys8ffrXXC0mNV3mXBZemZJcdprvObvh5MAmOFm8Pse9Hef7ovUDovSK/8Qh 4FGTBthWk8QEzGRWmpmYuYCtyhwPrMNLluEGlXPReYN5k/3BBuT51813tgeoAue1z/0rm4 j4zaFv4tqpqHJQ9rUjj+TRFDP5sPfuynswKIxD8OhacKKkwHFNAHQvqWgHMVdw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794526913; b=CDa3OB9FGpE6HfS/XQuflpP4BDonqpEGgEo+6tJS5lfEI8C/24mgOu1b4E1n4wT1mXGZ9I qyXaJtA9si7cqdYBYmC7oFeUi7uwBZLsxsVA62qLFksnSww37gHUDvUKUfz+odshF90SS4 fcvL7KuSjenzzXRNKbcwifWPO+KdRhZZ8E3NuJuNi7RLHVAYKY60x9RdGGVguNsuLif9jY iWwJOkpmamoRsIuGdoKbomUhQ3s9AeB1YWOd57t9rHOGjpZa2tHN3OQVs4QntwRg6EdTai WFnyIVEeobF8g0K6LZVwGRrXCrD1K7Q6arayfcaocDqexU6enMTAMeuILn7Z4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794526913; 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=Mp7fz9MsyZvLNzel9HMhxEzLnUJJzuFZigyZH5/7tGdA75JgJViB7/V9Rp+cbsL+F9uIrP BDjbEs/FPQ39O9Dr72V7YikdNJlsnehdhae+AVSLrf/oY0Lo0MuUdCXKk86uDcQGX7nA4b xlwxw5cMiu15fl3zxyLGVAq8J65BHcgeNjftkkUEAnkjdbwZn1t866h4hPPH/JfnnDrBra 2u4ISEsWaVqpefHxtsGFr4qidHEJ3/A9wPd+X8HC9erceeDiqO7CqqMT6hVGzLboMww8Yl PzNY2SUrB1K3HjdQekpagrUS/sgR7OuCU1Fbo2uc/GIQvDnmKfqGUb223OQDuQ== 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 4jQcNw5fPXz1Nb8 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-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: 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,