OpenCloudOS-Kernel/tools
Tony Ambardar 33ef0b25b0 selftests/bpf: Fix error compiling tc_redirect.c with musl libc
[ Upstream commit 21c5f4f55da759c7444a1ef13e90b6e6f674eeeb ]

Linux 5.1 implemented 64-bit time types and related syscalls to address the
Y2038 problem generally across archs. Userspace handling of Y2038 varies
with the libc however. While musl libc uses 64-bit time across all 32-bit
and 64-bit platforms, GNU glibc uses 64-bit time on 64-bit platforms but
defaults to 32-bit time on 32-bit platforms unless they "opt-in" to 64-bit
time or explicitly use 64-bit syscalls and time structures.

One specific area is the standard setsockopt() call, SO_TIMESTAMPNS option
used for timestamping, and the related output 'struct timespec'. GNU glibc
defaults as above, also exposing the SO_TIMESTAMPNS_NEW flag to explicitly
use a 64-bit call and 'struct __kernel_timespec'. Since these are not
exposed or needed with musl libc, their use in tc_redirect.c leads to
compile errors building for mips64el/musl:

  tc_redirect.c: In function 'rcv_tstamp':
  tc_redirect.c:425:32: error: 'SO_TIMESTAMPNS_NEW' undeclared (first use in this function); did you mean 'SO_TIMESTAMPNS'?
    425 |             cmsg->cmsg_type == SO_TIMESTAMPNS_NEW)
        |                                ^~~~~~~~~~~~~~~~~~
        |                                SO_TIMESTAMPNS
  tc_redirect.c:425:32: note: each undeclared identifier is reported only once for each function it appears in
  tc_redirect.c: In function 'test_inet_dtime':
  tc_redirect.c:491:49: error: 'SO_TIMESTAMPNS_NEW' undeclared (first use in this function); did you mean 'SO_TIMESTAMPNS'?
    491 |         err = setsockopt(listen_fd, SOL_SOCKET, SO_TIMESTAMPNS_NEW,
        |                                                 ^~~~~~~~~~~~~~~~~~
        |                                                 SO_TIMESTAMPNS

However, using SO_TIMESTAMPNS_NEW isn't strictly needed, nor is Y2038 being
explicitly tested. The timestamp checks in tc_redirect.c are simple: the
packet receive timestamp is non-zero and processed/handled in less than 5
seconds.

Switch to using the standard setsockopt() call and SO_TIMESTAMPNS option to
ensure compatibility across glibc and musl libc. In the worst-case, there
is a 5-second window 14 years from now where tc_redirect tests may fail on
32-bit systems. However, we should reasonably expect glibc to adopt a
64-bit mandate rather than the current "opt-in" policy before the Y2038
roll-over.

Fixes: ce6f6cffaeaa ("selftests/bpf: Wait for the netstamp_needed_key static key to be turned on")
Fixes: c803475fd8 ("bpf: selftests: test skb->tstamp in redirect_neigh")
Signed-off-by: Tony Ambardar <tony.ambardar@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/031d656c058b4e55ceae56ef49c4e1729b5090f3.1722244708.git.tony.ambardar@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-10-04 16:29:19 +02:00
..
accounting
arch tools headers arm64: Sync arm64's cputype.h with the kernel sources 2024-08-14 13:59:03 +02:00
bootconfig
bpf tools/runqslower: Fix LDFLAGS and add LDLIBS support 2024-10-04 16:29:15 +02:00
build perf cs-etm: Bump minimum OpenCSD version to ensure a bugfix is present 2024-02-05 20:14:31 +00:00
certs
cgroup iocost_monitor: improve it by adding iocg wait_ms 2023-08-08 15:43:03 -06:00
counter
crypto/ccp crypto: ccp - Fix some unfused tests 2023-11-20 11:59:18 +01:00
debugging
edid
firewire
firmware
gpio
hv tools: hv: rm .*.cmd when make clean 2024-09-30 16:25:12 +02:00
iio tools: iio: replace seekdir() in iio_generic_buffer 2024-04-13 13:07:38 +02:00
include tools: move alignment-related macros to new <linux/align.h> 2024-08-29 17:33:59 +02:00
kvm/kvm_stat
laptop
leds
lib libbpf: Add NULL checks to bpf_object__{prev_map,next_map} 2024-09-12 11:11:36 +02:00
memory-model tools/memory-model: Fix bug in lock.cat 2024-08-03 08:54:21 +02:00
mm tools/mm: fix undefined reference to pthread_once 2023-09-05 10:13:45 -07:00
net/ynl tools: ynl: don't ignore errors in NLMSG_DONE messages 2024-05-02 16:32:36 +02:00
objtool objtool: Fix UNWIND_HINT_{SAVE,RESTORE} across basic blocks 2024-03-26 18:19:35 -04:00
pci
pcmcia
perf perf tool: fix dereferencing NULL al->maps 2024-08-11 12:47:18 +02:00
power pm:cpupower: Add missing powercap_set_enabled() stub function 2024-10-04 16:28:55 +02:00
rcu
scripts
spi
testing selftests/bpf: Fix error compiling tc_redirect.c with musl libc 2024-10-04 16:29:19 +02:00
thermal
time
tracing rtla/osnoise: Prevent NULL dereference in error handling 2024-08-29 17:33:14 +02:00
usb
verification tools/rv: Fix Makefile compiler options for clang 2024-02-23 09:25:14 +01:00
virtio tools/virtio: Add dma sync api for virtio test 2023-10-16 05:32:23 -04:00
wmi
workqueue workqueue: Implement non-strict affinity scope for unbound workqueues 2023-08-07 15:57:25 -10:00
Makefile