linux/tools/include
Danish Khateeb 929ea5b348 tools/nolibc: fix FD_SET(), FD_CLR() and FD_ISSET() on 64-bit
Since commit feaf756587 ("nolibc: fix fd_set type"), an fd_set is an
array of unsigned long, but the FD_* macros still build their masks as
an int or an unsigned int: 1 << n in FD_SET(), 1U << n in FD_CLR() and
FD_ISSET(), where n is the fd modulo 64 on 64-bit architectures. So:

- FD_SET() of an fd with n == 31 sets the bits for n = 31-63, as
  1 << 31 is negative and gets sign-extended.
- For n >= 32 the shifts are undefined. x86-64, for instance, masks
  the shift count, so FD_SET(40) and FD_ISSET(40) use the bit of fd 8.
- FD_CLR() zero-extends ~(1U << n), so it also clears the bits for
  n = 32-63, whichever fd it is given.

select() on fd 40, for instance, fails with EBADF, or watches fd 8
instead if that one is open.

Build the masks from 1UL.

Fixes: feaf756587 ("nolibc: fix fd_set type")
Assisted-by: LLM
Signed-off-by: Danish Khateeb <danishkhateeb03@gmail.com>
Link: https://patch.msgid.link/20260925211600.119116-3-danishkhateeb03@gmail.com
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-09-26 08:43:26 +02:00
..
asm tools headers: Import x86 MMIO helper overrides 2025-08-27 12:14:06 -06:00
asm-generic tools headers asm: Sync fls headers header with the kernel sources 2025-11-03 13:35:06 -03:00
generated
io_uring selftests/io_uring: support NO_SQARRAY in miniliburing 2026-01-21 07:55:13 -07:00
linux mm.git review status for master..mm-nonmm-stable 2026-08-23 08:07:11 -07:00
nolibc tools/nolibc: fix FD_SET(), FD_CLR() and FD_ISSET() on 64-bit 2026-09-26 08:43:26 +02:00
perf
tools
trace/events
uapi Including fixes from Bluetooth, IPSec and Netfilter. 2026-08-27 13:53:43 -07:00
vdso tools headers: Update the linux/unaligned.h copy with the kernel sources 2026-01-14 08:56:41 +01:00