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=1796387591; b=1fxd1e757XTorEiNCst6puO2kBhlskkLAyojJpKL41BIwSvGmwx5Tzu4HK9SwviG3lBf o0EMNJykhCveU65HF9s8Q1eWMHQSkMGYH98BhXLlkpHtyzogvyRDaAXViZH1XcZ7Z3sfV nlk+hUQ3I2zVR9XlxUJgVWCvPT8r+C+Jn6rJCqxC9CACpZliCrv2xWm10HERKegEwa8h9 AUzOmcQsXCyXSiC9VE6yU3arJdsriUE1E/dBcy73TrghfCr+H86mzUjulr82MLrdAVw7X 3ioW96u5Mnktd7OupRMIgLkZYacSHvjzdAIVJVfragYZKyDY0JrxkyJPMz7HRQGjmVg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387591; 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=ibJABFnfMouRO+LGv8nzf71jVEllSKJtreFGltP2H5c=; b=ECwT/66dRFFjVXff+JuGtyAFhpJ0YPBOEKuNRaBlPffNttTl3CxBtelPxNAbRceJVQfO ENfEXkUGE6wBvaeyVBj3u9178RIW96O3uurDHsEwapblhDWqfHZjeOJDm8U4ojuE9QJTy id5xgmAL6y9wzasKiBpkWeogf22vky7etfSSuhC7btdlyICcr1WJ9EqTc1gw1Npx40zbV nw8Xckpeol2ukSX1sG19QSNS/QeBL/yA5bxyQkDRj7MkxL/LYhW4pdkFwD03bkIES3IKZ nc9HnS8Aq7lta/25/Tg07m0fAlYa/nctMKoSLTe5qS/g3gYTY8A6NrNyzdgaewxjS0Q== 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=X9fxb7hY; 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 E8BB6606A322; Fri, 4 Dec 2026 12:33:10 +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=X9fxb7hY Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60C841F00897; Fri, 4 Dec 2026 12:33:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387590; bh=ibJABFnfMouRO+LGv8nzf71jVEllSKJtreFGltP2H5c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=X9fxb7hYsW0t9iFizZlJ5T9/vyd9/zAknyxf+a0yb+mJJo5f14vSCEPFESUNZMK8b X1cNcBTfpeWUOwqbGmLKU2Q6vOoz58UX2QU3Un7dEkySua6ePkFNdES+0SkT9cklRM lIn9cW2JAqp2I3RCuJTqAYJ9QTsQTcJSAGcTQCoI= 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.1 0307/1059] tools/nolibc: fix FD_SET(), FD_CLR() and FD_ISSET() on 64-bit Date: Fri, 4 Dec 2026 18:57:18 +0900 Message-ID: <20261204100652.224769534@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org 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.1-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 FD_* mask fixes to tools/include/nolibc/types.h, since the sys/select.h header doesn't exist on this branch. ] 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 a6f3af0509eb7..a7d29ae5df725 100644 --- a/tools/include/nolibc/types.h +++ b/tools/include/nolibc/types.h @@ -102,7 +102,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 { \ @@ -110,7 +110,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) ({ \ @@ -119,7 +119,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