From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384917; b=QcZ2WY+w+06O+3lNNKd9iMWAoOxOUDPqPhX3BaV60E1P1hqKIgxouf8NURCGeumYJRHW POJR//XrFYl/c03DuoYgIZAPI6dnWQjtZ9tJPbK/VMAipCOs1uhwxdIZq3gjR1Cam7dlG Dcx8Lk6a0hIcWK+Dxnqq2pCU0v8BQccoXE6Ns+6RiqPbQ1LJsPjHAIFHw4ctS0+h3yUP3 dJJcjNLqxv0mnfvY9T6JJ0lNJl5j4T42PDUd13C45gDXoSdRsz4oTslCXcHDQUf+2h2cX vyg3iZFhJMArWMmhpjhFLQGmm9r7Kgsgk+b80Y3CVix+5TgM9da8FsUUlL2NmUXOfcA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384917; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=6+DMAAVhwtF8rM1okFJTZXsWMf3T+Ak/i7IhnI763uo=; b=TufDGAdFke0ugflkxXMDTqcEaA97UJ75deN66BH9l3Kz1zRgNsLi08yJFwia21ATnxlv eNcZkw7wj3Vcauk/oct7ttfwMlpK7d4V79gLI7ZFeG1ovCTpdYGP/2vygphOoEQeS9MwB GOoVPQ0JK3MwKqDrByFnJToTTFH+pxWUmtYLzptXnb2tH9xSWPEFxx5fgNXrcPUNZENBt dpAh3i7Hh4gZe8f8XEa2PGLAXSu7d4SuDkir0ZhBc4hg1sN9HIl5w7ETALxvg9UOiI9D3 xCb6/mx/65lAFpW8RgL8VbZvwsL2Q1vzPpjozojllJUeA4w/3gbCSb3UBGKvuWzqlRg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=LP5BsaWn; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42587606A322; Fri, 4 Dec 2026 11:48:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=LP5BsaWn Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2AA01F000CE; Fri, 4 Dec 2026 11:48:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384917; bh=6+DMAAVhwtF8rM1okFJTZXsWMf3T+Ak/i7IhnI763uo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LP5BsaWnVlsexL4FOMyKcuo/fRCd+CCg4jYqt9oyCJTgk99DDSFR4avB9+qXnSJ66 +fFiawf+Weix9utS7Qx/V7kbHojwaF0Qx/BfNqZm9ki+tPeYhE4LBBaOU/Kmpj1Mu2 pLsIiLdQdGmKfeWjX7PiJzUpLBFLAIzyEiL+3W2k= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Danish Khateeb , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Sasha Levin Subject: [PATCH 6.6 0347/1167] tools/nolibc: fix FD_SET(), FD_CLR() and FD_ISSET() on 64-bit Date: Fri, 4 Dec 2026 18:56:14 +0900 Message-ID: <20261204100711.029341138@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: 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 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Danish Khateeb [ Upstream commit 929ea5b3481fdbbb419f3986703280fb2b819504 ] Since commit feaf75658783 ("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: feaf75658783 ("nolibc: fix fd_set type") Assisted-by: LLM Signed-off-by: Danish Khateeb Link: https://patch.msgid.link/20260925211600.119116-3-danishkhateeb03@gmail.com Signed-off-by: Thomas Weißschuh [ sashal: Applied the three 1UL mask changes to fd_set macros in types.h because the upstream sys/select.h file doesn't exist in this tree. ] Signed-off-by: Sasha Levin --- tools/include/nolibc/types.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/include/nolibc/types.h b/tools/include/nolibc/types.h index ff422a6d3277e..4305c2d1cb08a 100644 --- a/tools/include/nolibc/types.h +++ b/tools/include/nolibc/types.h @@ -128,7 +128,7 @@ typedef struct { int __fd = (fd); \ if (__fd >= 0) \ __set->fds[__fd / FD_SETIDXMASK] &= \ - ~(1U << (__fd & FD_SETBITMASK)); \ + ~(1UL << (__fd & FD_SETBITMASK)); \ } while (0) #define FD_SET(fd, set) do { \ @@ -136,7 +136,7 @@ typedef struct { int __fd = (fd); \ if (__fd >= 0) \ __set->fds[__fd / FD_SETIDXMASK] |= \ - 1 << (__fd & FD_SETBITMASK); \ + 1UL << (__fd & FD_SETBITMASK); \ } while (0) #define FD_ISSET(fd, set) ({ \ @@ -145,7 +145,7 @@ typedef struct { int __r = 0; \ if (__fd >= 0) \ __r = !!(__set->fds[__fd / FD_SETIDXMASK] & \ -1U << (__fd & FD_SETBITMASK)); \ +1UL << (__fd & FD_SETBITMASK)); \ __r; \ }) -- 2.53.0