[PR #218] socket: fix udp_tunnel_sock_release/setup_udp_tunnel_sock ABI mismatch on newer kernels #241

Open
opened 2026-10-13 21:07:54 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/amnezia-vpn/amneziawg-linux-kernel-module/pull/218
Author: @VaisVaisov
Created: 8/17/2026
Status: 🔄 Open

Base: master ← Head: fix/udp-tunnel-newer-kernel-abi


📝 Commits (1)

  • 02789db compat: detect udp_tunnel_sock signature at compile time, not by kernel version

📊 Changes

1 file changed (+29 additions, -4 deletions)

View changed files

📝 src/compat/compat.h (+29 -4)

📄 Description

Root cause

Very recent kernel snapshots (not yet in an official release at the time of writing) changed the signature of udp_tunnel_sock_release() and setup_udp_tunnel_sock() from taking a struct socket * to taking a struct sock *. Some distro kernels (e.g. CachyOS) backport this early, under an unchanged LINUX_VERSION_CODE — so this can't reliably be gated by kernel version, only by the actual declared signature.

Build failure on affected kernels:

socket.c:378:26: error: incompatible pointer types passing 'struct socket *' to parameter of type 'struct sock *' [-Wincompatible-pointer-types]
socket.c:432:29: error: incompatible pointer types passing 'struct socket *' to parameter of type 'struct sock *' [-Wincompatible-pointer-types]
socket.c:439:28: error: incompatible pointer types passing 'struct socket *' to parameter of type 'struct sock *' [-Wincompatible-pointer-types]
socket.c:447:30: error: incompatible pointer types passing 'struct socket *' to parameter of type 'struct sock *' [-Wincompatible-pointer-types]

Fix

Added two small wrappers (wg_udp_tunnel_sock_release, wg_setup_udp_tunnel_sock) that detect the real parameter type at compile time via __builtin_types_compatible_p(typeof(&fn), ...), then call through an explicitly-cast function pointer matching whichever signature is actually declared. This avoids any LINUX_VERSION_CODE guessing and works correctly regardless of which ABI the currently-built-against headers expose.

Testing

Built via DKMS on a CachyOS system (kernel 7.1.8-1-cachyos, where this previously failed to build at all). Build now succeeds and the module loads and passes real traffic. Also confirmed it still builds and works correctly against an older/unaffected kernel (Ubuntu 24.04, 6.17.0-1014-oracle), so both ABI variants are covered.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/amnezia-vpn/amneziawg-linux-kernel-module/pull/218 **Author:** [@VaisVaisov](https://github.com/VaisVaisov) **Created:** 8/17/2026 **Status:** 🔄 Open **Base:** `master` ← **Head:** `fix/udp-tunnel-newer-kernel-abi` --- ### 📝 Commits (1) - [`02789db`](https://github.com/amnezia-vpn/amneziawg-linux-kernel-module/commit/02789db0ba30fa1ed60b9068674530cd98ae4f67) compat: detect udp_tunnel_sock signature at compile time, not by kernel version ### 📊 Changes **1 file changed** (+29 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `src/compat/compat.h` (+29 -4) </details> ### 📄 Description ## Root cause Very recent kernel snapshots (not yet in an official release at the time of writing) changed the signature of `udp_tunnel_sock_release()` and `setup_udp_tunnel_sock()` from taking a `struct socket *` to taking a `struct sock *`. Some distro kernels (e.g. CachyOS) backport this early, under an unchanged `LINUX_VERSION_CODE` — so this can't reliably be gated by kernel version, only by the actual declared signature. Build failure on affected kernels: ``` socket.c:378:26: error: incompatible pointer types passing 'struct socket *' to parameter of type 'struct sock *' [-Wincompatible-pointer-types] socket.c:432:29: error: incompatible pointer types passing 'struct socket *' to parameter of type 'struct sock *' [-Wincompatible-pointer-types] socket.c:439:28: error: incompatible pointer types passing 'struct socket *' to parameter of type 'struct sock *' [-Wincompatible-pointer-types] socket.c:447:30: error: incompatible pointer types passing 'struct socket *' to parameter of type 'struct sock *' [-Wincompatible-pointer-types] ``` ## Fix Added two small wrappers (`wg_udp_tunnel_sock_release`, `wg_setup_udp_tunnel_sock`) that detect the real parameter type at compile time via `__builtin_types_compatible_p(typeof(&fn), ...)`, then call through an explicitly-cast function pointer matching whichever signature is actually declared. This avoids any `LINUX_VERSION_CODE` guessing and works correctly regardless of which ABI the currently-built-against headers expose. ## Testing Built via DKMS on a CachyOS system (kernel `7.1.8-1-cachyos`, where this previously failed to build at all). Build now succeeds and the module loads and passes real traffic. Also confirmed it still builds and works correctly against an older/unaffected kernel (Ubuntu 24.04, `6.17.0-1014-oracle`), so both ABI variants are covered. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
amnezia-vpn/amneziawg-linux-kernel-module#241
No description provided.