mirror of
https://github.com/amnezia-vpn/amneziawg-linux-kernel-module.git
synced 2026-10-13 21:34:34 +00:00
[PR #206] fix: check IS_ERR(wg) before using the device in wg_set_device #235
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
amnezia-vpn/amneziawg-linux-kernel-module#235
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/amnezia-vpn/amneziawg-linux-kernel-module/pull/206
Author: @ExzoTikStyle
Created: 8/1/2026
Status: 🔄 Open
Base:
master← Head:fix/header-protection-null-deref📝 Commits (2)
eef998efix: check IS_ERR(wg) before using the device in wg_set_device1f5690ffix: take the write lock when setting the header protection key📊 Changes
2 files changed (+13 additions, -6 deletions)
View changed files
📝
src/header_protection.c(+9 -4)📝
src/netlink.c(+4 -2)📄 Description
wg_set_device()initialiseshas_protectionfromawg_has_header_protection(wg)in the declaration block, above the
IS_ERR(wg)check. When the request names aninterface that doesn't exist,
lookup_interface()returns anERR_PTRand thehelper dereferences it right away.
The oops lands inside
down_read(), andgenl_rcv_msg()holds the genl familylock across the
doitcallback, so the lock is never released. Everything on theamneziawgfamily blocks in uninterruptible sleep from then on — includingawg setconffor tunnels that were up and working — andgenl_unregister_family()hangs too, so the module can neither be used nor unloaded. Only a reboot clears it.
rmmod -fisn't a way out either, since stock Ubuntu kernels build withoutCONFIG_MODULE_FORCE_UNLOAD.CR2being0x50drather than a near-zero address is theERR_PTRgiveaway:(void *)-19plus the offset ofheader_protection.lockinstruct wg_device.The call is the left operand of the
||, so it runs whether or notWGDEVICE_A_HEADER_PROTECTION_KEYwas passed — a plainawg set doesnotexist listen-port 51820reaches it too. Introduced in #192.The first commit moves the check above the use. It also adds an
IS_ERR_OR_NULL()guard insideawg_has_header_protection(), since it takes adevice pointer from several call sites.
The second commit is unrelated to the crash but in the same file:
awg_header_protection_set_key()writesp->key[]andp->has_protectionwhile holding only
down_read(). Concurrent setters can interleave, andawg_header_protection_init()can read a half-updated key while building thechacha state — silently wrong header protection rather than a reported error.
Happy to split it out if you'd rather keep this PR to the crash.
Verification
Built and run against 6.8.0-136-generic (Ubuntu 22.04.5), on the same host
where the oops was originally hit.
Before, on
3.0.20260731-04fromppa:amnezia/ppa:After, with this branch:
dmesgis clean, and an existing AWG 3 tunnel (withHeaderProtectionKeyset)comes back up on the patched module and passes traffic as before.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.