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 0/3] tools/nolibc: fix readdir_r() and the FD_* macros on 64-bit
Date: Wed, 23 Sep 2026 20:52:19 -0500	[thread overview]
Message-ID: <20260924015222.31693-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 tests 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.

The series applies to nolibc/for-next f2212892b6a0 and is independent
of my WIFSIGNALED() series [1]; the two merge cleanly.

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 two new tests, which pass. They also pass
  against glibc (make libc-test).

- On x86_64 without patch 2, fd_set and select_high_fd fail (select()
  returns EBADF). With the default UBSan flags the run stops with
  SIGILL at fd_set instead.

- The readdir_r() program, on ext4, on x86_64, arm64 and sparc64:
  before, it fails on /etc after 4 of 213 entries, /usr/include after
  1 of 1454 and /usr/lib after 2 of 6186. After, it lists as many
  entries as glibc, and on x86_64 the same names. A native i386 build
  was already correct. The arm build failed too, but only because
  under qemu-user the kernel sees a 64-bit process and hands it
  64-bit offsets.

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

[1] https://lore.kernel.org/all/20260923205622.1123270-1-danishkhateeb03@gmail.com/

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 and select() on a high fd

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


base-commit: f2212892b6a0c2adab438783e9fa8093c90786d7
-- 
2.55.0


             reply	other threads:[~2026-09-24  1:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24  1:52 Danish Khateeb [this message]
2026-09-24  1:52 ` [PATCH 1/3] tools/nolibc: fix readdir_r() with 64-bit directory offsets Danish Khateeb
2026-09-24  1:52 ` [PATCH 2/3] tools/nolibc: fix FD_SET(), FD_CLR() and FD_ISSET() on 64-bit Danish Khateeb
2026-09-24  1:52 ` [PATCH 3/3] selftests/nolibc: test the FD_* macros and select() on a high fd Danish Khateeb

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=20260924015222.31693-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®