mirror of
https://github.com/amnezia-vpn/amneziawg-linux-kernel-module.git
synced 2026-10-13 21:34:34 +00:00
[PR #217] [MERGED] fix: initialize header_protection.lock, use down_write in set_key #239
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#239
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/217
Author: @VaisVaisov
Created: 8/17/2026
Status: ✅ Merged
Merged: 8/27/2026
Merged by: @ygurov
Base:
master← Head:fix/header-protection-locking📝 Commits (1)
3a7b8c1fix: initialize header_protection.lock, use down_write in set_key📊 Changes
2 files changed (+4 additions, -3 deletions)
View changed files
📝
src/device.c(+1 -0)📝
src/header_protection.c(+3 -3)📄 Description
Closes #216.
Root cause
Two independent bugs in
header_protection.c:header_protection.lock(anrw_semaphore) is never initialized viainit_rwsem()anywhere in the driver. It's only zero-filled viamemset(wg, 0, sizeof(*wg))inwg_setup(). Every other rwsem in the driver (cookie->lock,wg->static_identity.lock,handshake->lock) does getinit_rwsem()'d — this one was missed. Using an uninitializedrw_semaphoreis undefined behavior.awg_header_protection_set_key()mutatesp->key[]andp->has_protectionwhile holding onlydown_read(), notdown_write(). In fact all three functions in the file (init,set_key,get_key) usedown_read()— there's no writer path at all, so there's effectively no mutual exclusion for the mutation.Together these explain
setconffailing withUnable to modify interface: Invalid argumentwhenHeaderProtectionKeyis set, even with valid S1-S4 values (well aboveHEADER_PROTECTION_NONCE_SIZE) — reproduction details are in #216.Fix
init_rwsem(&wg->header_protection.lock)inwg_newlink(), next to the other lock initializations.awg_header_protection_set_key()to usedown_write()/up_write().Testing
Built via DKMS against a patched local checkout, loaded on a real server (Ubuntu 24.04, arm64, kernel 6.17.0-1014-oracle), confirmed
setconfwithHeaderProtectionKeyset succeeds,header protection keyshows correctly inawg show, and a full handshake + real traffic works end to end.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.