Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1249976imw; Tue, 5 Jul 2022 06:25:50 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t92jlrl/SaehKAvwxYOs7fAt/rTJQBy4fxdct2ooEI4NelTmeKY750Kx7RJIO54rlk0NAL X-Received: by 2002:a17:907:6d1f:b0:726:abaf:1765 with SMTP id sa31-20020a1709076d1f00b00726abaf1765mr33642254ejc.126.1657027549714; Tue, 05 Jul 2022 06:25:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657027549; cv=none; d=google.com; s=arc-20160816; b=bV1mrYxPgkIrwxM6N9XVZ4k/WQIf/z87rs2rGkF1GeFv1rL+AihNMW1ygYG7R4+Obj bHaNNI4g6bTIZFIrMXEKqr9iE0ZZ+fzYLc57D8vmuchksqgstv7UuhSTbL0yS1Et2KNk x4A85/nB6o+kD64gztG1lVX9ypN/afOCKH0saEWyRxeKmh3VrHOihID00+rROfvCb2+H qltXEW0KpQ8HF/lzKM9TMONTo9AEbp8lR8hsYcyOs6NUfx4osXYKtRPqcg5mCogrRW75 K+LNITA5bLmaSVSB8pPevDeylw/nPKBjZRPLqkjntMxY7qvK7dyfJ/tDQP3+BG6XR0/0 gfiA== 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=E0gmIMB1zLxNnPfxptUd+9N1C3WTAklcJpIz+Y0QRHk=; b=rfCThZ6Jjo9Zgxcik9LDATSXJdQwX4IsFLwIp2apXqiNxajaXM6W7c41Aa1fhb9Q/6 kosJpJB5cH19CQzZxdwZ1zXjzll37NfiFmonAa1s1vLr4bHT7BdnjpSBMCpGkUZurBIM JGRNs0QgTOPAIpZWEVLxEuxxnHB7qOH4T5kH+++Nsuiy6N7Y/a8bgVIVYguzbPCN/qEI W2kF6lKCZZ4l6Nx4ElVPwEAYMqIN0FrpxwUA1VgOBP4SNqLCHMYV4DLt7B3XVHPZi/HN bgsJoHUm6ZJziSH1wHO8YVjfr5tQWgvUYVsT23MRxrM/xdmId4mNHCiHo8x1Uvdy7+P2 dZBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DeQyBKxn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp7-20020a1709073e0700b007262a4865e0si17012872ejc.931.2022.07.05.06.25.24; Tue, 05 Jul 2022 06:25:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DeQyBKxn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236015AbiGEMQA (ORCPT + 99 others); Tue, 5 Jul 2022 08:16:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235245AbiGEMIo (ORCPT ); Tue, 5 Jul 2022 08:08:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C5262AA; Tue, 5 Jul 2022 05:08:20 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id C227061876; Tue, 5 Jul 2022 12:08:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D61E7C341CB; Tue, 5 Jul 2022 12:08:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657022899; bh=pfMuOW8Pwusuy24tjcGzgjQJszv8oTwikZnbkn9t2qQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DeQyBKxn9Gjf2Lo+lcyn5GZbSw3L5eT3X0GMesT+P+HUprnZFCInwan5fqYEdJaOx LE2ogW9UUYM7Szp/x1ItEO/nE5IWaXwtBibwJQ0oNokLrYw51hCXMMQMSBAt95tG2/ T6GYpItKFGQRh1L0yi+874qSX4VwKFDAnHARQMsk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maksym Glubokiy , Yevhen Orlov , Jay Vosburgh , Jakub Kicinski Subject: [PATCH 5.10 33/84] net: bonding: fix use-after-free after 802.3ad slave unbind Date: Tue, 5 Jul 2022 13:57:56 +0200 Message-Id: <20220705115616.290033643@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220705115615.323395630@linuxfoundation.org> References: <20220705115615.323395630@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=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: Yevhen Orlov commit 050133e1aa2cb49bb17be847d48a4431598ef562 upstream. commit 0622cab0341c ("bonding: fix 802.3ad aggregator reselection"), resolve case, when there is several aggregation groups in the same bond. bond_3ad_unbind_slave will invalidate (clear) aggregator when __agg_active_ports return zero. So, ad_clear_agg can be executed even, when num_of_ports!=0. Than bond_3ad_unbind_slave can be executed again for, previously cleared aggregator. NOTE: at this time bond_3ad_unbind_slave will not update slave ports list, because lag_ports==NULL. So, here we got slave ports, pointing to freed aggregator memory. Fix with checking actual number of ports in group (as was before commit 0622cab0341c ("bonding: fix 802.3ad aggregator reselection") ), before ad_clear_agg(). The KASAN logs are as follows: [ 767.617392] ================================================================== [ 767.630776] BUG: KASAN: use-after-free in bond_3ad_state_machine_handler+0x13dc/0x1470 [ 767.638764] Read of size 2 at addr ffff00011ba9d430 by task kworker/u8:7/767 [ 767.647361] CPU: 3 PID: 767 Comm: kworker/u8:7 Tainted: G O 5.15.11 #15 [ 767.655329] Hardware name: DNI AmazonGo1 A7040 board (DT) [ 767.660760] Workqueue: lacp_1 bond_3ad_state_machine_handler [ 767.666468] Call trace: [ 767.668930] dump_backtrace+0x0/0x2d0 [ 767.672625] show_stack+0x24/0x30 [ 767.675965] dump_stack_lvl+0x68/0x84 [ 767.679659] print_address_description.constprop.0+0x74/0x2b8 [ 767.685451] kasan_report+0x1f0/0x260 [ 767.689148] __asan_load2+0x94/0xd0 [ 767.692667] bond_3ad_state_machine_handler+0x13dc/0x1470 Fixes: 0622cab0341c ("bonding: fix 802.3ad aggregator reselection") Co-developed-by: Maksym Glubokiy Signed-off-by: Maksym Glubokiy Signed-off-by: Yevhen Orlov Acked-by: Jay Vosburgh Link: https://lore.kernel.org/r/20220629012914.361-1-yevhen.orlov@plvision.eu Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/bonding/bond_3ad.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/net/bonding/bond_3ad.c +++ b/drivers/net/bonding/bond_3ad.c @@ -2209,7 +2209,8 @@ void bond_3ad_unbind_slave(struct slave temp_aggregator->num_of_ports--; if (__agg_active_ports(temp_aggregator) == 0) { select_new_active_agg = temp_aggregator->is_active; - ad_clear_agg(temp_aggregator); + if (temp_aggregator->num_of_ports == 0) + ad_clear_agg(temp_aggregator); if (select_new_active_agg) { slave_info(bond->dev, slave->dev, "Removing an active aggregator\n"); /* select new active aggregator */