mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Danish Khateeb <danishkhateeb03@gmail.com>
To: "Willy Tarreau" <w@1wt.eu>, "Thomas Weißschuh" <linux@weissschuh.net>
Cc: Shuah Khan <shuah@kernel.org>,
	Sven Schnelle <svens@linux.ibm.com>,
	Benjamin Berg <benjamin.berg@intel.com>,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	Danish Khateeb <danishkhateeb03@gmail.com>
Subject: [PATCH v2 0/3] tools/nolibc: fix readdir_r() and the FD_* macros on 64-bit
Date: Fri, 25 Sep 2026 16:15:57 -0500	[thread overview]
Message-ID: <20260925211600.119116-1-danishkhateeb03@gmail.com> (raw)

Two bugs that only show up on 64-bit architectures:

- readdir_r() truncates the directory offset to an int. On ext4 it
  fails within the first few entries of almost every directory (since
  v6.19), or returns the next-to-last entry twice and never the last
  one (v6.15 to v6.18). Patch 1.

- FD_SET(), FD_CLR() and FD_ISSET() build their masks from an int, so
  they use the wrong bits for fds 31-63 of each 64-bit word, and
  select() on fd 40 fails with EBADF. Patch 2, with a test in patch 3.

There is no selftest for patch 1: it needs a directory with large
offsets, and nolibc-test only lists /proc/self, whose offsets are
small. I tested it with a small program that lists a directory with
readdir_r() instead.

Changes in v2:
- Dropped Cc: stable from patches 1 and 2, which are otherwise
  unchanged.
- Patch 3: dropped the select() test, and moved the FD_* test to the
  stdlib tests, with its helper in the same order as the test cases
  (Thomas). It is also shorter: FD_CLR() is now checked on a set
  filled with memset().
- Rebased on nolibc/for-next 6f114ae7b600.

v1: https://lore.kernel.org/all/20260924015222.31693-1-danishkhateeb03@gmail.com/

Testing, with GCC 16.2, on x86_64 and i386 natively and on arm, arm64
and sparc64 under qemu-user:

- nolibc-test, all tests: no failures before or after the series. The
  only difference is the new fd_set test, which passes, also with clang
  on x86_64 and against glibc (make libc-test).

- Without patch 2, fd_set fails on the 64-bit architectures: with the
  default UBSan flags the run stops at fd_set on the sanitizer trap,
  and without them the test reports [FAIL] (checked on x86_64 and
  arm64). It passes on i386 and arm, which are not affected.

- The readdir_r() program, on ext4, on x86_64, arm64 and sparc64:
  before, it fails on /etc after 4 of 215 entries, /usr/include after
  1 of 1467 and /usr/lib after 2 of 6229. After, it lists as many
  entries as glibc. A native i386 build was already correct.

- Built for x86_64 against nolibc from before commit 4ada5679f18d, the
  same program lists a directory holding "..", "code" and "." as "..",
  "code", "code".

Danish Khateeb (3):
  tools/nolibc: fix readdir_r() with 64-bit directory offsets
  tools/nolibc: fix FD_SET(), FD_CLR() and FD_ISSET() on 64-bit
  selftests/nolibc: test the FD_* macros

 tools/include/nolibc/dirent.h                |  7 ++++---
 tools/include/nolibc/sys/select.h            |  6 +++---
 tools/testing/selftests/nolibc/nolibc-test.c | 21 ++++++++++++++++++++
 3 files changed, 28 insertions(+), 6 deletions(-)


base-commit: 6f114ae7b6006ca7cf72e3e3348d263bbfec4525
-- 
2.55.0


             reply	other threads:[~2026-09-25 21:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-25 21:15 Danish Khateeb [this message]
2026-09-25 21:15 ` [PATCH v2 1/3] tools/nolibc: fix readdir_r() with 64-bit directory offsets Danish Khateeb
2026-09-25 21:15 ` [PATCH v2 2/3] tools/nolibc: fix FD_SET(), FD_CLR() and FD_ISSET() on 64-bit Danish Khateeb
2026-09-25 21:16 ` [PATCH v2 3/3] selftests/nolibc: test the FD_* macros Danish Khateeb
2026-09-26  7:35 ` [PATCH v2 0/3] tools/nolibc: fix readdir_r() and the FD_* macros on 64-bit Thomas Weißschuh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260925211600.119116-1-danishkhateeb03@gmail.com \
    --to=danishkhateeb03@gmail.com \
    --cc=benjamin.berg@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=shuah@kernel.org \
    --cc=svens@linux.ibm.com \
    --cc=w@1wt.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®