Skip to content

Commit de94f85

Browse files
andrewyagerrfuchs
authored andcommitted
MT#55283 kernel-module: detect nft_expr_ops.validate signature via compile test
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. Closes #2085 Change-Id: I4c8e55b94fb98c3fcda9dccb091d0d1c0c67f9aa (cherry picked from commit b1aec46) (cherry picked from commit 4ea947f)
1 parent b2aa424 commit de94f85

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

kernel-module/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KSRC ?= /lib/modules/$(shell uname -r)/build
1+
KSRC ?= /lib/modules/$(or $(KERNELRELEASE),$(shell uname -r))/build
22
KBUILD := $(KSRC)
33
M ?= $(CURDIR)
44

kernel-module/gen-rtpengine-kmod-flags

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,39 @@ fi
4444
if [ -n "${RTPENGINE_VERSION}" ]; then
4545
echo "RTPENGINE_VERSION := ${RTPENGINE_VERSION}"
4646
fi
47+
48+
# Compile test: detect nft_expr_ops.validate callback signature.
49+
# Distribution kernels (e.g. Ubuntu) may backport the 2-param validate
50+
# callback (mainline commit eaf9b2c875ec, merged in 6.12) to earlier
51+
# kernel versions without changing LINUX_VERSION_CODE. A compile test
52+
# is the only reliable way to detect the actual API.
53+
#
54+
# The test tries to assign a 3-param function to .validate. If it
55+
# compiles, the old API is present and we set the flag. If it fails
56+
# (incompatible pointer types), the kernel has the new 2-param version.
57+
58+
# KERNELRELEASE is set by kbuild to the target kernel version, which
59+
# may differ from the running kernel during DKMS cross-kernel builds.
60+
KSRC="${KSRC:-/lib/modules/${KERNELRELEASE:-$(uname -r)}/build}"
61+
62+
if [ -d "${KSRC}" ]; then
63+
nft_test_dir=$(mktemp -d)
64+
cat > "${nft_test_dir}/nft_test.c" <<'TESTEOF'
65+
#include <linux/module.h>
66+
#include <net/netfilter/nf_tables.h>
67+
static int test_validate(const struct nft_ctx *ctx, const struct nft_expr *expr,
68+
const struct nft_data **data) { return 0; }
69+
static struct nft_expr_ops __attribute__((unused)) test_ops = {
70+
.validate = test_validate };
71+
MODULE_LICENSE("GPL");
72+
TESTEOF
73+
echo "obj-m := nft_test.o" > "${nft_test_dir}/Makefile"
74+
75+
# Use env -i to prevent kbuild state (KBUILD_EXTMOD, M, MAKEFLAGS, etc.)
76+
# leaking from an outer kbuild invocation into the compile test.
77+
if env -i PATH="$PATH" make -j1 -C "${KSRC}" M="${nft_test_dir}" modules >/dev/null 2>&1; then
78+
echo "ccflags-y += -DNFT_EXPR_OPS_VALIDATE_HAS_DATA"
79+
fi
80+
81+
rm -rf "${nft_test_dir}"
82+
fi

kernel-module/nft_rtpengine.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6870,7 +6870,7 @@ static int rtpengine_expr_dump(struct sk_buff *skb, const struct nft_expr *expr
68706870
}
68716871

68726872
static int rtpengine_expr_validate(const struct nft_ctx *ctx, const struct nft_expr *expr
6873-
#if LINUX_VERSION_CODE < KERNEL_VERSION(6,12,0)
6873+
#if defined(NFT_EXPR_OPS_VALIDATE_HAS_DATA)
68746874
, const struct nft_data **data
68756875
#endif
68766876
)

0 commit comments

Comments
 (0)