From bf5075fcdc53c1c73370a0367f82f679cc1fb605 Mon Sep 17 00:00:00 2001 From: David Verbeiren Date: Thu, 13 Jan 2022 16:56:43 +0000 Subject: [PATCH] elf: Apply same kern_version.SUBLEVEL clamping as done by kernel When SUBLEVEL of the kernel version approaches 255, it is clamped to 255 to avoid impacting the PATCHLEVEL. This is introduced in different versions depending on the branch. For example, for 4.19 kernel see the following commit: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=a256aac5b7000 In order to avoid failing the kernel version check in the BPF syscall, the library must apply the same clamping. Signed-off-by: David Verbeiren --- elf/kernel_version.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/elf/kernel_version.go b/elf/kernel_version.go index a6ab9461..842985ea 100644 --- a/elf/kernel_version.go +++ b/elf/kernel_version.go @@ -49,6 +49,15 @@ func KernelVersionFromReleaseString(releaseString string) (uint32, error) { if err != nil { return 0, err } + + // Apply same clamping as done by kernel when SUBLEVEL approaches 255 + // See https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=a256aac5b7000 + if major == 4 && minor == 14 && patch >= 252 { + patch = 255 + } else if major == 4 && minor == 19 && patch >= 222 { + patch = 255 + } + out := major*256*256 + minor*256 + patch return uint32(out), nil }