[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20230823173839.43938-1-n.zhandarovich@fintech.ru>
Date: Wed, 23 Aug 2023 10:38:39 -0700
From: Nikita Zhandarovich <n.zhandarovich@...tech.ru>
To: "Jason A. Donenfeld" <Jason@...c4.com>, "David S. Miller"
<davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>
CC: Nikita Zhandarovich <n.zhandarovich@...tech.ru>, Jakub Kicinski
<kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
<wireguard@...ts.zx2c4.com>, <netdev@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, syzbot <syzkaller@...glegroups.com>,
<lvc-project@...uxtesting.org>,
<syzbot+d1de830e4ecdaac83d89@...kaller.appspotmail.com>
Subject: [PATCH net] wireguard: receive: fix data-race around receiving_counter.counter
Syzkaller with KCSAN identified a data-race issue when accessing
keypair->receiving_counter.counter.
This patch uses READ_ONCE() and WRITE_ONCE() annotations to fix the
problem.
Fixes: a9e90d9931f3 ("wireguard: noise: separate receive counter from send counter")
Reported-by: syzbot+d1de830e4ecdaac83d89@...kaller.appspotmail.com
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@...tech.ru>
---
drivers/net/wireguard/receive.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/wireguard/receive.c b/drivers/net/wireguard/receive.c
index 0b3f0c843550..b5232ffa8bc7 100644
--- a/drivers/net/wireguard/receive.c
+++ b/drivers/net/wireguard/receive.c
@@ -251,7 +251,7 @@ static bool decrypt_packet(struct sk_buff *skb, struct noise_keypair *keypair)
if (unlikely(!READ_ONCE(keypair->receiving.is_valid) ||
wg_birthdate_has_expired(keypair->receiving.birthdate, REJECT_AFTER_TIME) ||
- keypair->receiving_counter.counter >= REJECT_AFTER_MESSAGES)) {
+ READ_ONCE(keypair->receiving_counter.counter) >= REJECT_AFTER_MESSAGES)) {
WRITE_ONCE(keypair->receiving.is_valid, false);
return false;
}
@@ -318,7 +318,7 @@ static bool counter_validate(struct noise_replay_counter *counter, u64 their_cou
for (i = 1; i <= top; ++i)
counter->backtrack[(i + index_current) &
((COUNTER_BITS_TOTAL / BITS_PER_LONG) - 1)] = 0;
- counter->counter = their_counter;
+ WRITE_ONCE(counter->counter, their_counter);
}
index &= (COUNTER_BITS_TOTAL / BITS_PER_LONG) - 1;
--
2.25.1
Powered by blists - more mailing lists