lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20251025160905.3857885-59-sashal@kernel.org>
Date: Sat, 25 Oct 2025 11:54:50 -0400
From: Sasha Levin <sashal@...nel.org>
To: patches@...ts.linux.dev,
	stable@...r.kernel.org
Cc: Wake Liu <wakel@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>,
	Sasha Levin <sashal@...nel.org>,
	davem@...emloft.net,
	edumazet@...gle.com,
	pabeni@...hat.com,
	nathan@...nel.org,
	netdev@...r.kernel.org,
	llvm@...ts.linux.dev
Subject: [PATCH AUTOSEL 6.17-5.4] selftests/net: Replace non-standard __WORDSIZE with sizeof(long) * 8

From: Wake Liu <wakel@...gle.com>

[ Upstream commit c36748e8733ef9c5f4cd1d7c4327994e5b88b8df ]

The `__WORDSIZE` macro, defined in the non-standard `<bits/wordsize.h>`
header, is a GNU extension and not universally available with all
toolchains, such as Clang when used with musl libc.

This can lead to build failures in environments where this header is
missing.

The intention of the code is to determine the bit width of a C `long`.
Replace the non-portable `__WORDSIZE` with the standard and portable
`sizeof(long) * 8` expression to achieve the same result.

This change also removes the inclusion of the now-unused
`<bits/wordsize.h>` header.

Signed-off-by: Wake Liu <wakel@...gle.com>
Signed-off-by: Jakub Kicinski <kuba@...nel.org>
Signed-off-by: Sasha Levin <sashal@...nel.org>
---

LLM Generated explanations, may be completely bogus:

YES

- What it fixes
  - Fixes selftest build failures on toolchains without GNU
    `<bits/wordsize.h>` (e.g., Clang with musl). The current code
    directly includes a GNU-internal header and uses a GNU extension
    macro.
  - Evidence: direct inclusion at
    `tools/testing/selftests/net/psock_tpacket.c:36` and use of
    `__WORDSIZE` at `tools/testing/selftests/net/psock_tpacket.c:788`.

- Change details
  - Removes non-standard header include: `#include <bits/wordsize.h>`
    (tools/testing/selftests/net/psock_tpacket.c:36).
  - Replaces non-portable `__WORDSIZE` with the portable and standard-
    compliant `sizeof(long) * 8` inside `test_user_bit_width()`
    (tools/testing/selftests/net/psock_tpacket.c:788 → now returns
    `sizeof(long) * 8`).
  - No other functional changes; all behavior, interfaces, and test
    logic remain intact.

- Behavioral impact
  - The intent of `test_user_bit_width()` is to report the userspace
    “word” width as used by the test to decide whether to skip
    TPACKET_V1 when user/kernel bit widths differ (see its use in
    `test_tpacket()` adjacent to
    tools/testing/selftests/net/psock_tpacket.c:811).
  - On Linux ABIs, `__WORDSIZE` effectively matches the bit width of
    `long`. Using `sizeof(long) * 8` is semantically equivalent across
    LP64 and ILP32, including x86_64 ILP32 (x32), where it returns 32
    and properly triggers the intended skip path when comparing to the
    kernel’s 64-bit width parsed from `/proc/kallsyms`.
  - Therefore, no functional change to test behavior, only improved
    portability.

- Scope and risk
  - Selftests-only change (single file), no kernel code touched.
  - Very small and contained: removal of one include and a one-line
    return expression change.
  - No architectural changes; no side effects beyond enabling builds on
    non-glibc toolchains.
  - Aligns with existing tools-side practice:
    `tools/include/linux/bitops.h` already falls back to a portable
    definition of `__WORDSIZE` via `__SIZEOF_LONG__ * 8`, reinforcing
    that using the C type width is the right approach.

- Stable backport criteria
  - Addresses a real user-facing bug: selftests fail to build on
    legitimate toolchains (Clang + musl).
  - Minimal risk and fully contained to a test; no runtime kernel
    impact.
  - Not a new feature; purely a portability/build fix.
  - Touches a non-critical subtree (selftests), commonly accepted for
    stable when it fixes build or test breakages.

Conclusion: This is a low-risk, portability/build fix for selftests with
no kernel runtime impact and should be backported to stable.

 tools/testing/selftests/net/psock_tpacket.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/psock_tpacket.c b/tools/testing/selftests/net/psock_tpacket.c
index 221270cee3eaa..0dd909e325d93 100644
--- a/tools/testing/selftests/net/psock_tpacket.c
+++ b/tools/testing/selftests/net/psock_tpacket.c
@@ -33,7 +33,6 @@
 #include <ctype.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <bits/wordsize.h>
 #include <net/ethernet.h>
 #include <netinet/ip.h>
 #include <arpa/inet.h>
@@ -785,7 +784,7 @@ static int test_kernel_bit_width(void)
 
 static int test_user_bit_width(void)
 {
-	return __WORDSIZE;
+	return sizeof(long) * 8;
 }
 
 static const char *tpacket_str[] = {
-- 
2.51.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ