This repository was archived by the owner on Dec 27, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +41
-7
lines changed Expand file tree Collapse file tree 5 files changed +41
-7
lines changed Original file line number Diff line number Diff line change @@ -112,9 +112,7 @@ static int wg_stop(struct net_device *dev)
112
112
wg_timers_stop (peer );
113
113
wg_noise_handshake_clear (& peer -> handshake );
114
114
wg_noise_keypairs_clear (& peer -> keypairs );
115
- atomic64_set (& peer -> last_sent_handshake ,
116
- ktime_get_coarse_boottime_ns () -
117
- (u64 )(REKEY_TIMEOUT + 1 ) * NSEC_PER_SEC );
115
+ wg_noise_reset_last_sent_handshake (& peer -> last_sent_handshake );
118
116
}
119
117
mutex_unlock (& wg -> device_update_lock );
120
118
skb_queue_purge (& wg -> incoming_handshakes );
Original file line number Diff line number Diff line change 13
13
#include <linux/if.h>
14
14
#include <net/genetlink.h>
15
15
#include <net/sock.h>
16
+ #include <crypto/algapi.h>
16
17
17
18
static struct genl_family genl_family ;
18
19
@@ -546,6 +547,10 @@ static int wg_set_device(struct sk_buff *skb, struct genl_info *info)
546
547
u8 public_key [NOISE_PUBLIC_KEY_LEN ];
547
548
struct wg_peer * peer , * temp ;
548
549
550
+ if (!crypto_memneq (wg -> static_identity .static_private ,
551
+ private_key , NOISE_PUBLIC_KEY_LEN ))
552
+ goto skip_set_private_key ;
553
+
549
554
/* We remove before setting, to prevent race, which means doing
550
555
* two 25519-genpub ops.
551
556
*/
@@ -563,12 +568,15 @@ static int wg_set_device(struct sk_buff *skb, struct genl_info *info)
563
568
private_key );
564
569
list_for_each_entry_safe (peer , temp , & wg -> peer_list ,
565
570
peer_list ) {
566
- if (!wg_noise_precompute_static_static (peer ))
571
+ if (wg_noise_precompute_static_static (peer ))
572
+ wg_noise_expire_current_peer_keypairs (peer );
573
+ else
567
574
wg_peer_remove (peer );
568
575
}
569
576
wg_cookie_checker_precompute_device_keys (& wg -> cookie_checker );
570
577
up_write (& wg -> static_identity .lock );
571
578
}
579
+ skip_set_private_key :
572
580
573
581
if (info -> attrs [WGDEVICE_A_PEERS ]) {
574
582
struct nlattr * attr , * peer [WGPEER_A_MAX + 1 ];
Original file line number Diff line number Diff line change @@ -183,6 +183,29 @@ void wg_noise_keypairs_clear(struct noise_keypairs *keypairs)
183
183
spin_unlock_bh (& keypairs -> keypair_update_lock );
184
184
}
185
185
186
+ static void rekey_sending_keypair (struct noise_keypair * keypair )
187
+ {
188
+ u64 rekey_ns = ktime_get_coarse_boottime_ns () -
189
+ (u64 )(REKEY_AFTER_TIME + 1 ) * NSEC_PER_SEC ;
190
+ if ((s64 )rekey_ns < (s64 )keypair -> sending .birthdate )
191
+ keypair -> sending .birthdate = rekey_ns ;
192
+ }
193
+
194
+ void wg_noise_expire_current_peer_keypairs (struct wg_peer * peer )
195
+ {
196
+ wg_noise_handshake_clear (& peer -> handshake );
197
+ wg_noise_reset_last_sent_handshake (& peer -> last_sent_handshake );
198
+
199
+ spin_lock_bh (& peer -> keypairs .keypair_update_lock );
200
+ rekey_sending_keypair (
201
+ rcu_dereference_protected (peer -> keypairs .next_keypair ,
202
+ lockdep_is_held (& peer -> keypairs .keypair_update_lock )));
203
+ rekey_sending_keypair (
204
+ rcu_dereference_protected (peer -> keypairs .current_keypair ,
205
+ lockdep_is_held (& peer -> keypairs .keypair_update_lock )));
206
+ spin_unlock_bh (& peer -> keypairs .keypair_update_lock );
207
+ }
208
+
186
209
static void add_new_keypair (struct noise_keypairs * keypairs ,
187
210
struct noise_keypair * new_keypair )
188
211
{
Original file line number Diff line number Diff line change @@ -100,11 +100,18 @@ bool wg_noise_handshake_init(struct noise_handshake *handshake,
100
100
const u8 peer_preshared_key [NOISE_SYMMETRIC_KEY_LEN ],
101
101
struct wg_peer * peer );
102
102
void wg_noise_handshake_clear (struct noise_handshake * handshake );
103
+ static inline void wg_noise_reset_last_sent_handshake (atomic64_t * handshake_ns )
104
+ {
105
+ atomic64_set (handshake_ns , ktime_get_coarse_boottime_ns () -
106
+ (u64 )(REKEY_TIMEOUT + 1 ) * NSEC_PER_SEC );
107
+ }
108
+
103
109
void wg_noise_keypair_put (struct noise_keypair * keypair , bool unreference_now );
104
110
struct noise_keypair * wg_noise_keypair_get (struct noise_keypair * keypair );
105
111
void wg_noise_keypairs_clear (struct noise_keypairs * keypairs );
106
112
bool wg_noise_received_with_keypair (struct noise_keypairs * keypairs ,
107
113
struct noise_keypair * received_keypair );
114
+ void wg_noise_expire_current_peer_keypairs (struct wg_peer * peer );
108
115
109
116
void wg_noise_set_static_identity_private_key (
110
117
struct noise_static_identity * static_identity ,
Original file line number Diff line number Diff line change @@ -56,9 +56,7 @@ struct wg_peer *wg_peer_create(struct wg_device *wg,
56
56
rwlock_init (& peer -> endpoint_lock );
57
57
kref_init (& peer -> refcount );
58
58
skb_queue_head_init (& peer -> staged_packet_queue );
59
- atomic64_set (& peer -> last_sent_handshake ,
60
- ktime_get_coarse_boottime_ns () -
61
- (u64 )(REKEY_TIMEOUT + 1 ) * NSEC_PER_SEC );
59
+ wg_noise_reset_last_sent_handshake (& peer -> last_sent_handshake );
62
60
set_bit (NAPI_STATE_NO_BUSY_POLL , & peer -> napi .state );
63
61
netif_napi_add (wg -> dev , & peer -> napi , wg_packet_rx_poll ,
64
62
NAPI_POLL_WEIGHT );
You can’t perform that action at this time.
0 commit comments