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 64064C61DA4 for ; Mon, 13 Mar 2023 09:38:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231311AbjCMJiz (ORCPT ); Mon, 13 Mar 2023 05:38:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230422AbjCMJiS (ORCPT ); Mon, 13 Mar 2023 05:38:18 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDBA124120 for ; Mon, 13 Mar 2023 02:35:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678700117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AQpW0MtAAGC9H850DvbSl98IgEUwIqqbc/Y7v5HGv34=; b=JDBz+kIu25R0/tG8uc2n+Yww1v8DzxQDBS/Fyf5lc1ZenUcefzWBVUOCPEU2VRKLezVubD CHULO+zuch6GW+9/dB86UGG7HaBuksP+b3876CU/npdmSgUYI+g9u/ck03NNPR5z2ev/By 3dxDhIACHpNDsv68QRarCaKqXu0SyjY= Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-515-aHvRc4A2PkapPz2Q_VGDEg-1; Mon, 13 Mar 2023 05:35:15 -0400 X-MC-Unique: aHvRc4A2PkapPz2Q_VGDEg-1 Received: by mail-pg1-f200.google.com with SMTP id q15-20020a63d60f000000b00502e1c551aaso2493675pgg.21 for ; Mon, 13 Mar 2023 02:35:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678700114; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=AQpW0MtAAGC9H850DvbSl98IgEUwIqqbc/Y7v5HGv34=; b=PyMOaoLMnlZeFoaG42xwWEP33OjLhky0pULegrTi5tbHdpFFGUmvP3YjPnW4iOzzPA g50m0URBfmxg7NwyaIAvEL828EgxxdWmiP5QiGykAEtvERYisC2WnENtN0Ee4gmVkIZd BEnpnw2WqthDVuAJgY/LIiLw1WYu/0BuoKqseFb0J5ZO/LHCLWshnH0lCPb5k4sD/Zu5 dlx0fpjBwYGV97dBOmOvhGVyw4iuRwwWbNnXE4apKp2wDQiGD/m3kWZ5qmNrXxx3ANXK grVCniOdCSZQ6dG+RyoGuTpdmpt9QJGxDo4eoLA5cMn7EnzCeXtn2ADQ4CN4BIeixTvF Lwpw== X-Gm-Message-State: AO0yUKXvk5nI1PmagHrKB7PXB5Q5fxVwQzx/E0F9P3iiJ1IXFm2VUgB4 BFZYfcksBdlvlbuZWjMiRjcbA0Xsv4J4NLHJNpE3pmDT+6MP1FTjrEvFv5NuYUbm+XBE+3oINMY ji+Qonr6O2NQa0LbXcbpX8ztz X-Received: by 2002:a17:902:c10c:b0:19a:bbd0:c5ca with SMTP id 12-20020a170902c10c00b0019abbd0c5camr30025403pli.48.1678700114256; Mon, 13 Mar 2023 02:35:14 -0700 (PDT) X-Google-Smtp-Source: AK7set8qak99w/AMcIHIkbXFQmu0oB5IulOHjMgE3Cr+/Edugbjr1WBiM99TptRhutLefIoxxEt3Fw== X-Received: by 2002:a17:902:c10c:b0:19a:bbd0:c5ca with SMTP id 12-20020a170902c10c00b0019abbd0c5camr30025390pli.48.1678700113905; Mon, 13 Mar 2023 02:35:13 -0700 (PDT) Received: from kernel-devel ([240d:1a:c0d:9f00:ca6:1aff:fead:cef4]) by smtp.gmail.com with ESMTPSA id w1-20020a170902a70100b0019aeddce6casm4269374plq.205.2023.03.13.02.35.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 02:35:13 -0700 (PDT) Date: Mon, 13 Mar 2023 18:35:08 +0900 From: Shigeru Yoshida To: Nikolay Aleksandrov Cc: j.vosburgh@gmail.com, andy@greyhouse.net, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Nikolay Aleksandrov , syzbot+9dfc3f3348729cc82277@syzkaller.appspotmail.com Subject: Re: [PATCH net] bonding: Fix warning in default_device_exit_batch() Message-ID: References: <20230312152158.995043-1-syoshida@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Nik, On Sun, Mar 12, 2023 at 10:58:18PM +0200, Nikolay Aleksandrov wrote: > On 12/03/2023 17:21, Shigeru Yoshida wrote: > > syzbot reported warning in default_device_exit_batch() like below [1]: > > > > WARNING: CPU: 1 PID: 56 at net/core/dev.c:10867 unregister_netdevice_many_notify+0x14cf/0x19f0 net/core/dev.c:10867 > > ... > > Call Trace: > > > > unregister_netdevice_many net/core/dev.c:10897 [inline] > > default_device_exit_batch+0x451/0x5b0 net/core/dev.c:11350 > > ops_exit_list+0x125/0x170 net/core/net_namespace.c:174 > > cleanup_net+0x4ee/0xb10 net/core/net_namespace.c:613 > > process_one_work+0x9bf/0x1820 kernel/workqueue.c:2390 > > worker_thread+0x669/0x1090 kernel/workqueue.c:2537 > > kthread+0x2e8/0x3a0 kernel/kthread.c:376 > > ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308 > > > > > > For bond devices which also has a master device, IFF_SLAVE flag is > > cleared at err_undo_flags label in bond_enslave() if it is not > > ARPHRD_ETHER type. In this case, __bond_release_one() is not called > > when bond_netdev_event() received NETDEV_UNREGISTER event. This > > causes the above warning. > > > > This patch fixes this issue by setting IFF_SLAVE flag at > > err_undo_flags label in bond_enslave() if the bond device has a master > > device. > > > > The proper way is to check if the bond device had the IFF_SLAVE flag before the > ether_setup() call which clears it, and restore it after. > > > Fixes: 7d5cd2ce5292 ("bonding: correctly handle bonding type change on enslave failure") > > Cc: Nikolay Aleksandrov > > Link: https://syzkaller.appspot.com/bug?id=391c7b1f6522182899efba27d891f1743e8eb3ef [1] > > Reported-by: syzbot+9dfc3f3348729cc82277@syzkaller.appspotmail.com > > Signed-off-by: Shigeru Yoshida > > --- > > drivers/net/bonding/bond_main.c | 2 ++ > > include/net/bonding.h | 5 +++++ > > 2 files changed, 7 insertions(+) > > > > diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c > > index 00646aa315c3..1a8b59e1468d 100644 > > --- a/drivers/net/bonding/bond_main.c > > +++ b/drivers/net/bonding/bond_main.c > > @@ -2291,6 +2291,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev, > > dev_close(bond_dev); > > ether_setup(bond_dev); > > bond_dev->flags |= IFF_MASTER; > > + if (bond_has_master(bond)) > > + bond_dev->flags |= IFF_SLAVE; > > bond_dev->priv_flags &= ~IFF_TX_SKB_SHARING; > > } > > } > > diff --git a/include/net/bonding.h b/include/net/bonding.h > > index ea36ab7f9e72..ed0b49501fad 100644 > > --- a/include/net/bonding.h > > +++ b/include/net/bonding.h > > @@ -57,6 +57,11 @@ > > > > #define bond_has_slaves(bond) !list_empty(bond_slave_list(bond)) > > > > +/* master list primitives */ > > +#define bond_master_list(bond) (&(bond)->dev->adj_list.upper) > > + > > +#define bond_has_master(bond) !list_empty(bond_master_list(bond)) > > + > > This is not the proper way to check for a master device. > > > /* IMPORTANT: bond_first/last_slave can return NULL in case of an empty list */ > > #define bond_first_slave(bond) \ > > (bond_has_slaves(bond) ? \ > > The device flags are wrong because of ether_setup() which clears IFF_SLAVE, we should > just check if it was present before and restore it after the ether_setup() call. Thank you so much for your comment! I understand your point, and agree that your approach must resolve the issue. BTW, do you mean there is a case where a device has IFF_SLAVE flag but the upper list is empty? I thought a device with IFF_SLAVE flag has a master device in the upper list (that is why I took the above way.) Thanks, Shigeru > > I'll send a fix tomorrow after testing it. > > Thanks, > Nik >