Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4431942pxb; Mon, 21 Feb 2022 21:25:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjrNRXODwJfIKKL2WIrXX5kLiqqHHFZSx+Pyc36TzB1haXOv5U4N50bA2QcUUghrgAPoQ6 X-Received: by 2002:a62:b517:0:b0:4f1:308f:d256 with SMTP id y23-20020a62b517000000b004f1308fd256mr7293253pfe.53.1645507556852; Mon, 21 Feb 2022 21:25:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645507556; cv=none; d=google.com; s=arc-20160816; b=D4rhAgTDfwGO4c0RC6A6GjkN9+P94usY/VrxRt/TqsDa1ZijAtz6aC5jLi3/bqt6MI I8GUej1IIQ6/1BL7SYbCrBJxio0GFRJBhf4eQr0ncO4zKf5bCibkrzNnJXqaDDkalZSF DDmVIOMgR4gTxfREzYvTXnzcN7hJ8QSg2rtgI/9IQUMrWjEmhDFxj11ZEA2myj/jXdZ1 ZHbna31Bd8lnG6MY6RB94Plj1N3eq7N4oEWjXhpXutFMtCX6ZrPTzCeBUnkRrDR/0P7y 47wqLKkygbVV9RZKWQI/LroWylMDZ3v5q9ljs6cf4UWNBwtU8DNs5zIY3xDfgHz9M4ZD RQgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8zLYSSVZacZQaQ+8NBQFzB5I6Uixd8+hGrLJShi4I7g=; b=YQKCxB6GrUqAbKXyAwq1a92+iQOuA+EUanHplfCcajH/Vi6h55xQAJLdy4eHx9B9Kf rGwzYm8X+pPUwpXvU3v2jJog87tPXaOKV9B0PPTYgPoNBuCXBHl4ujOxsTZ348jpK/rm d5DGqBH8j/Nzdbz1afxGOwFwYWkClzFbeskZV/BR4ZNV9jhxmtaHhz6YOakT0kyfMiB+ Lfu9FfLMnZKKdAYxztijDTlAoRSXVOBCVq0Pyfa1QIDnaVUYAemY97I6rLuOA5JlYs4K w1UJzbQlWckwtmQtawpQTOalChb60XvjFxLYA4Mu9eMEcuO04aKwjYOuXQCkqejnBYcU b04g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=n93dfeMo; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id b20si549674plz.482.2022.02.21.21.25.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 21:25:56 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=n93dfeMo; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8406C1D0E4; Mon, 21 Feb 2022 20:56:19 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348048AbiBUJKl (ORCPT + 99 others); Mon, 21 Feb 2022 04:10:41 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:39578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347642AbiBUJF6 (ORCPT ); Mon, 21 Feb 2022 04:05:58 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04ECC24580; Mon, 21 Feb 2022 00:59:25 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8523BB80E72; Mon, 21 Feb 2022 08:59:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3407C340E9; Mon, 21 Feb 2022 08:59:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645433964; bh=x0JmbkGXGzbdLXAHUbNZKrf4uwxVKCJZZFPAbVvDbrA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n93dfeMoLMW5ZBGKnyMY6s2CR7jj5I4jsi5xDNJGWBrvc7zHaUOH6NKdMxWdnis+5 Ha3yw0W/dsnUjV+Gbr+TfsJ60Zmm0iqeTF8TunYd/pbeRxf7XRAfunld8Fm9uuWoXi O5HtES6vFPqOWh87k7KN1A6J8MCKuhX9Eb57LN6k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , syzbot , Jay Vosburgh , Veaceslav Falico , "David S. Miller" Subject: [PATCH 5.4 44/80] bonding: fix data-races around agg_select_timer Date: Mon, 21 Feb 2022 09:49:24 +0100 Message-Id: <20220221084917.016649641@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084915.554151737@linuxfoundation.org> References: <20220221084915.554151737@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet commit 9ceaf6f76b203682bb6100e14b3d7da4c0bedde8 upstream. syzbot reported that two threads might write over agg_select_timer at the same time. Make agg_select_timer atomic to fix the races. BUG: KCSAN: data-race in bond_3ad_initiate_agg_selection / bond_3ad_state_machine_handler read to 0xffff8881242aea90 of 4 bytes by task 1846 on cpu 1: bond_3ad_state_machine_handler+0x99/0x2810 drivers/net/bonding/bond_3ad.c:2317 process_one_work+0x3f6/0x960 kernel/workqueue.c:2307 worker_thread+0x616/0xa70 kernel/workqueue.c:2454 kthread+0x1bf/0x1e0 kernel/kthread.c:377 ret_from_fork+0x1f/0x30 write to 0xffff8881242aea90 of 4 bytes by task 25910 on cpu 0: bond_3ad_initiate_agg_selection+0x18/0x30 drivers/net/bonding/bond_3ad.c:1998 bond_open+0x658/0x6f0 drivers/net/bonding/bond_main.c:3967 __dev_open+0x274/0x3a0 net/core/dev.c:1407 dev_open+0x54/0x190 net/core/dev.c:1443 bond_enslave+0xcef/0x3000 drivers/net/bonding/bond_main.c:1937 do_set_master net/core/rtnetlink.c:2532 [inline] do_setlink+0x94f/0x2500 net/core/rtnetlink.c:2736 __rtnl_newlink net/core/rtnetlink.c:3414 [inline] rtnl_newlink+0xfeb/0x13e0 net/core/rtnetlink.c:3529 rtnetlink_rcv_msg+0x745/0x7e0 net/core/rtnetlink.c:5594 netlink_rcv_skb+0x14e/0x250 net/netlink/af_netlink.c:2494 rtnetlink_rcv+0x18/0x20 net/core/rtnetlink.c:5612 netlink_unicast_kernel net/netlink/af_netlink.c:1317 [inline] netlink_unicast+0x602/0x6d0 net/netlink/af_netlink.c:1343 netlink_sendmsg+0x728/0x850 net/netlink/af_netlink.c:1919 sock_sendmsg_nosec net/socket.c:705 [inline] sock_sendmsg net/socket.c:725 [inline] ____sys_sendmsg+0x39a/0x510 net/socket.c:2413 ___sys_sendmsg net/socket.c:2467 [inline] __sys_sendmsg+0x195/0x230 net/socket.c:2496 __do_sys_sendmsg net/socket.c:2505 [inline] __se_sys_sendmsg net/socket.c:2503 [inline] __x64_sys_sendmsg+0x42/0x50 net/socket.c:2503 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x44/0xd0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x44/0xae value changed: 0x00000050 -> 0x0000004f Reported by Kernel Concurrency Sanitizer on: CPU: 0 PID: 25910 Comm: syz-executor.1 Tainted: G W 5.17.0-rc4-syzkaller-dirty #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Eric Dumazet Reported-by: syzbot Cc: Jay Vosburgh Cc: Veaceslav Falico Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/bonding/bond_3ad.c | 30 +++++++++++++++++++++++++----- include/net/bond_3ad.h | 2 +- 2 files changed, 26 insertions(+), 6 deletions(-) --- a/drivers/net/bonding/bond_3ad.c +++ b/drivers/net/bonding/bond_3ad.c @@ -233,7 +233,7 @@ static inline int __check_agg_selection_ if (bond == NULL) return 0; - return BOND_AD_INFO(bond).agg_select_timer ? 1 : 0; + return atomic_read(&BOND_AD_INFO(bond).agg_select_timer) ? 1 : 0; } /** @@ -1985,7 +1985,7 @@ static void ad_marker_response_received( */ void bond_3ad_initiate_agg_selection(struct bonding *bond, int timeout) { - BOND_AD_INFO(bond).agg_select_timer = timeout; + atomic_set(&BOND_AD_INFO(bond).agg_select_timer, timeout); } /** @@ -2269,6 +2269,28 @@ void bond_3ad_update_ad_actor_settings(s } /** + * bond_agg_timer_advance - advance agg_select_timer + * @bond: bonding structure + * + * Return true when agg_select_timer reaches 0. + */ +static bool bond_agg_timer_advance(struct bonding *bond) +{ + int val, nval; + + while (1) { + val = atomic_read(&BOND_AD_INFO(bond).agg_select_timer); + if (!val) + return false; + nval = val - 1; + if (atomic_cmpxchg(&BOND_AD_INFO(bond).agg_select_timer, + val, nval) == val) + break; + } + return nval == 0; +} + +/** * bond_3ad_state_machine_handler - handle state machines timeout * @bond: bonding struct to work on * @@ -2303,9 +2325,7 @@ void bond_3ad_state_machine_handler(stru if (!bond_has_slaves(bond)) goto re_arm; - /* check if agg_select_timer timer after initialize is timed out */ - if (BOND_AD_INFO(bond).agg_select_timer && - !(--BOND_AD_INFO(bond).agg_select_timer)) { + if (bond_agg_timer_advance(bond)) { slave = bond_first_slave_rcu(bond); port = slave ? &(SLAVE_AD_INFO(slave)->port) : NULL; --- a/include/net/bond_3ad.h +++ b/include/net/bond_3ad.h @@ -262,7 +262,7 @@ struct ad_system { struct ad_bond_info { struct ad_system system; /* 802.3ad system structure */ struct bond_3ad_stats stats; - u32 agg_select_timer; /* Timer to select aggregator after all adapter's hand shakes */ + atomic_t agg_select_timer; /* Timer to select aggregator after all adapter's hand shakes */ u16 aggregator_identifier; };