kernel-module: detect nft_expr_ops.validate signature from headers#2085
kernel-module: detect nft_expr_ops.validate signature from headers#2085andrewyager wants to merge 1 commit intosipwise:masterfrom
Conversation
|
Ubuntu still doesn't have their own versioning define (akin to |
|
Ubuntu does have
The header grep approach sidesteps all of this — it detects the actual API the kernel headers expose, regardless of which distro or ABI version you're building against. |
|
Thanks ChatGPT. I find a simple grep to be a bit too fragile for this, as there's no guarantee that the pattern Either that, or a more sophisticated method to parse the header file to extract the necessary information. |
|
Point taken, but no I don't use ChatGPT. I'm going to rework this and actually do it more properly and use a compile test. UTS_UBUNTU_RELEASE_ABI feels to fragile, and while it does work for Jammy HWE and Noble in this case, it doesn't feel robust enough. your comment on |
|
OK - this fix should be better. There is an issue that would surface in this scenario if you were upgrading from 6.8.0-90 to 6.8.0-106 where the signature changes, because the Makefile runs KSRC ?= /lib/modules/$(shell uname -r)/buildwhich will always pick the current Kernel headers. |
Well, that's a bit of a problem then, isn't it. 😄
Alternatively since this script is called from Or perhaps there's a way to integrate this into the main makefile somehow... I need to spin up some VMs to play with this. |
|
Yep - If this were to be patched, it would look like: diff --git a/kernel-module/Makefile b/kernel-module/Makefile
index be0f349..XXXXXXX 100644
--- a/kernel-module/Makefile
+++ b/kernel-module/Makefile
@@ -1,4 +1,4 @@
-KSRC ?= /lib/modules/$(shell uname -r)/build
+KSRC ?= /lib/modules/$(or $(KERNELRELEASE),$(shell uname -r))/build
KBUILD := $(KSRC)
M ?= $(CURDIR)I can add this to this PR, or it can go as a seperate concern. |
|
Within this PR is fine, either as a separate commit or squashed into the other ones. Either way, please squash the other commits into one to have a clean base. |
6d09edd to
dfb0059
Compare
|
Done! |
|
Sadly this doesn't work, the compile test unconditionally fails with and so the |
The current LINUX_VERSION_CODE check for the nft_expr_ops.validate callback signature breaks on distribution kernels that backport the API change (mainline commit eaf9b2c875ec, merged in 6.12) without updating LINUX_VERSION_CODE. For example, Ubuntu 24.04's 6.8.0-103+ kernel (stable patchset 2026-01-27, LP: #2139158) includes this backport, causing DKMS builds to fail with -Werror=incompatible-pointer-types. Replace the version-based #if with a compile test in the existing gen-rtpengine-kmod-flags configure script. The test tries to assign a 3-param function to .validate -- if it compiles, the old API is present and NFT_EXPR_OPS_VALIDATE_HAS_DATA is set. If it fails, the kernel has the new 2-param version. Also use kbuild's KERNELRELEASE variable (instead of uname -r) to resolve the kernel build directory, so that compile tests and KSRC target the correct kernel during cross-version DKMS builds. Tested against Ubuntu 6.8.0-90 (3-param) and 6.8.0-106 (2-param), including cross-kernel builds where the running kernel differs from the DKMS target.
dfb0059 to
39f340d
Compare
|
Ahh; this was introduced by a difference in my build patch for our repo build (we are patching this with script for our builds on our mirror at https://mirror.realcompute.io/rtpengine/) but I didn't merge it properly back into this patch. Fixed now, and I've taken this and test built from it on a clean Ubuntu box which hopefully matches what you will do... |
|
FWIW if you build packages, I suggest you use the included packaging and backports script (https://github.com/sipwise/rtpengine/tree/master/pkg/deb) which remove the |
Summary
The current
LINUX_VERSION_CODE < KERNEL_VERSION(6,12,0)check for thenft_expr_ops.validatecallback signature breaks on distribution kernels that backport the API change without updatingLINUX_VERSION_CODE.Upstream commit:
eaf9b2c875ec— "netfilter: nf_tables: drop unused 3rd argument from validate callback ops" (Florian Westphal, 2024-09-03)Affected: Ubuntu 24.04 kernel
6.8.0-106(stable patchset 2026-01-27, LP: #2139158) backports this commit to a 6.8 kernel, causing the DKMS build to fail:Fix
Replace the
LINUX_VERSION_CODEcheck with compile-time header detection:validatecallback signature. Ifnft_dataappears in the validate parameter list, defineNFT_EXPR_OPS_VALIDATE_HAS_DATA.#if defined(NFT_EXPR_OPS_VALIDATE_HAS_DATA)instead of the version check.This correctly handles:
Testing
Compiled and verified against:
6.8.0-90-generic(old 3-param API) — builds successfully6.8.0-106-generic(backported 2-param API) — builds successfully6.8.0-106— module loads correctly