diff --git a/kernel/linux/src/generated/netlink.c b/kernel/linux/src/generated/netlink.c index ab62a37e3..8379ea7bf 100644 --- a/kernel/linux/src/generated/netlink.c +++ b/kernel/linux/src/generated/netlink.c @@ -27,6 +27,7 @@ const struct nla_policy wireguard_wgallowedip_nl_policy[WGALLOWEDIP_A_FLAGS + 1] */ const struct nla_policy tswg_peer_nl_policy[TSWGPEER_A_MAX + 1] = { [TSWGPEER_A_FLAGS] = NLA_POLICY_MASK(NLA_U32, TSWGPEER_F_NO_ROAM), + [TSWGPEER_A_CLEAR_SESSION] = { .type = NLA_FLAG, }, }; const struct nla_policy wireguard_wgpeer_nl_policy[WGPEER_A_TSWG + 1] = { /* TSWG */ diff --git a/kernel/linux/src/include/uapi/linux/tswg.h b/kernel/linux/src/include/uapi/linux/tswg.h index 01ae78820..d6114cbaa 100644 --- a/kernel/linux/src/include/uapi/linux/tswg.h +++ b/kernel/linux/src/include/uapi/linux/tswg.h @@ -107,6 +107,14 @@ enum tswgpeer_flag { enum tswgpeer_attribute { TSWGPEER_A_UNSPEC, TSWGPEER_A_FLAGS, /* NLA_U32 of enum tswgpeer_flag; set replaces all */ + /* + * NLA_FLAG, set only: forget the peer's session keys and any + * handshake in progress, as on suspend, so that the next packet to the + * peer starts a new handshake right away. For when userspace learns + * that the peer restarted (and so lost its keys), such as from a new + * disco key. + */ + TSWGPEER_A_CLEAR_SESSION, __TSWGPEER_A_LAST }; diff --git a/kernel/linux/src/netlink.c b/kernel/linux/src/netlink.c index 79b2cb1ed..3fb65b1e7 100644 --- a/kernel/linux/src/netlink.c +++ b/kernel/linux/src/netlink.c @@ -655,6 +655,14 @@ int tswg_set_peer(struct wg_peer *peer, struct nlattr *attr) WRITE_ONCE(peer->tswg_no_roam, !!(flags & TSWGPEER_F_NO_ROAM)); } + if (tb[TSWGPEER_A_CLEAR_SESSION]) { + /* As wg_pm_notification does for every peer before suspend. */ + timer_delete(&peer->timer_zero_key_material); + wg_noise_handshake_clear(&peer->handshake); + wg_noise_keypairs_clear(&peer->keypairs); + /* Don't make the next handshake wait for REKEY_TIMEOUT. */ + wg_noise_reset_last_sent_handshake(&peer->last_sent_handshake); + } return 0; }