Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1252199imw; Tue, 5 Jul 2022 06:28:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v+ux6hgp73ZVKXg8iObQtGkV7QnThgD+k5QXfW6SW5Eks39TGxc5vSH2xWaELYNxqKIZur X-Received: by 2002:a17:90a:d581:b0:1ef:a1d5:9904 with SMTP id v1-20020a17090ad58100b001efa1d59904mr1800785pju.93.1657027680170; Tue, 05 Jul 2022 06:28:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657027680; cv=none; d=google.com; s=arc-20160816; b=j537UCPfJlauzXxwR7785nWXhQjdudm+FsvyXR2+4/l9aeeINaSH9zULa888uhLAfO PUaslbfoNGA8TFpwQnsOapxJ9mvZEiSUotOtYPAs/umZ3lnXaUjiblYr/cg6SV4Dh7QE 0jSVgZrz5rR1qMCtPSeR7OgrKysrDHWrBx0cU4SxX4v31Oon8HSr1JVP5+nwsfK+f9Aj ZlnwHieIC+ykGaoPg4Ci90tbeWbEkurGzlKqL9P5V8FQwCbxyR2YZGa2jtO7lky5zhbW QBw+aa0aIfntFvN1tVMXv2u29WI5GUxQe5OdZL97AxRffbXmCYA4JhW8tC75hmjoOB3O MkfA== 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=LhmsKQBpTFoYO12JmcK3Tty9eH1LJMMh1guAzFaOAIo=; b=y2nctPYNC9Up1cBHFA8fgEBXZDbO+BZgRqHyMYddTm2dSIwoxYVDaJVL9CEdU/Q/K4 Om/C6A63z8pLMgwfEWiTCxhRFS2ErNuytcCk8CzxVMqdB8u7er3q9z1/R6fpxY8rdJbk GVs5253Zbv0dPnn0BIC6cFWM0tCpn8TCrvRzlpWmjr/ESwY47mO6lCFFuAVTnO3cWzU5 ob4IfI3QWnAYXflbclUI9iLX7SsqlHjE51ASODbw0QmFxxpZk1nZwrGNKZwM7S7WtL6J fgjXM4iPxccAJ5Q07/yHSuFnuNCF+1GgfFqIkV+lfCrNRZSoYTfdHUClQzmWVdD219dt b5Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kKOEkrSU; 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 g10-20020a056a0023ca00b00528982d0ae2si1830300pfc.197.2022.07.05.06.27.48; Tue, 05 Jul 2022 06:28:00 -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=kKOEkrSU; 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 S230427AbiGEL7f (ORCPT + 99 others); Tue, 5 Jul 2022 07:59:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232108AbiGEL73 (ORCPT ); Tue, 5 Jul 2022 07:59:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 795DB13D4A; Tue, 5 Jul 2022 04:59:28 -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 15E4F61786; Tue, 5 Jul 2022 11:59:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2F9CC341CD; Tue, 5 Jul 2022 11:59:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657022367; bh=FOBNPPodyH/TMIDj76qQ14K5FL2EGD2LPkWSmv5o+DM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kKOEkrSUiFRNQXTKWt7IkWNT1hMMgMjS5ArzkNhTF0meFv65SAEs1vzzctqzbrAd+ GmJtnD7OZTwMMzcxQTyr1vmAq5MF6NpxVnhUxPUY7hHcdGgFnmwSOtCvn8ie73kWUb HFo+UpaC4Eyy7Oh/zuwe7G250Poc6NHncLu0QSNk= 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 4.9 11/29] net: bonding: fix use-after-free after 802.3ad slave unbind Date: Tue, 5 Jul 2022 13:57:52 +0200 Message-Id: <20220705115606.080241374@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220705115605.742248854@linuxfoundation.org> References: <20220705115605.742248854@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 @@ -2163,7 +2163,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) { netdev_info(bond->dev, "Removing an active aggregator\n"); /* select new active aggregator */