From nobody Tue Dec 16 12:22:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79F50C27C40 for ; Wed, 23 Aug 2023 17:39:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237860AbjHWRjB (ORCPT ); Wed, 23 Aug 2023 13:39:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236177AbjHWRjA (ORCPT ); Wed, 23 Aug 2023 13:39:00 -0400 Received: from exchange.fintech.ru (exchange.fintech.ru [195.54.195.159]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50547E5A for ; Wed, 23 Aug 2023 10:38:56 -0700 (PDT) Received: from Ex16-01.fintech.ru (10.0.10.18) by exchange.fintech.ru (195.54.195.159) with Microsoft SMTP Server (TLS) id 14.3.498.0; Wed, 23 Aug 2023 20:38:53 +0300 Received: from localhost (10.0.253.138) by Ex16-01.fintech.ru (10.0.10.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Wed, 23 Aug 2023 20:38:52 +0300 From: Nikita Zhandarovich To: "Jason A. Donenfeld" , "David S. Miller" , Eric Dumazet CC: Nikita Zhandarovich , Jakub Kicinski , Paolo Abeni , , , , syzbot , , Subject: [PATCH net] wireguard: receive: fix data-race around receiving_counter.counter Date: Wed, 23 Aug 2023 10:38:39 -0700 Message-ID: <20230823173839.43938-1-n.zhandarovich@fintech.ru> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.0.253.138] X-ClientProxiedBy: Ex16-02.fintech.ru (10.0.10.19) To Ex16-01.fintech.ru (10.0.10.18) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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@syzkaller.appspotmail.com Signed-off-by: Nikita Zhandarovich --- 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/receiv= e.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) =20 if (unlikely(!READ_ONCE(keypair->receiving.is_valid) || wg_birthdate_has_expired(keypair->receiving.birthdate, REJECT_AFTER_TI= ME) || - keypair->receiving_counter.counter >=3D REJECT_AFTER_MESSAGES)) { + READ_ONCE(keypair->receiving_counter.counter) >=3D REJECT_AFTER_MESSAG= ES)) { WRITE_ONCE(keypair->receiving.is_valid, false); return false; } @@ -318,7 +318,7 @@ static bool counter_validate(struct noise_replay_counte= r *counter, u64 their_cou for (i =3D 1; i <=3D top; ++i) counter->backtrack[(i + index_current) & ((COUNTER_BITS_TOTAL / BITS_PER_LONG) - 1)] =3D 0; - counter->counter =3D their_counter; + WRITE_ONCE(counter->counter, their_counter); } =20 index &=3D (COUNTER_BITS_TOTAL / BITS_PER_LONG) - 1; --=20 2.25.1