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 50FDBC6FD19 for ; Mon, 13 Mar 2023 10:52:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230243AbjCMKwv (ORCPT ); Mon, 13 Mar 2023 06:52:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjCMKwt (ORCPT ); Mon, 13 Mar 2023 06:52:49 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3A1F36098 for ; Mon, 13 Mar 2023 03:52:47 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id x3so46794375edb.10 for ; Mon, 13 Mar 2023 03:52:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; t=1678704766; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=a9L5C11Sw9bIHqmk7RYsTOno8/sluS1+0CyCq3POQ0M=; b=0AglgEMexqm6E156DEN4Qa4jyoykz5XuhUZ0ytMDX68sH+rnJY7hHcqw4t5bB3vNKj yJPg6Pgzoc84GKqNWsSRgiScNOuy2c5mub+ZMoS7P4scoRyMFsPGcx+2csMkwaYB5dzt ZzqnFdLqNTmxJ/5BR/Weh/WmMlkTLi62zX6T4YwmQGr46yvOtxtkWM9vEqvZh1hdPn2t P5ABDuu2w9KZcXOiysFdCrYi5Tcpg/QAy1KThLSZ+kwCoDTnd8irRIjEQyQPfpLRiUxa zF16bot6S5Vy4TYeg2twu/mJ778QFeOpQ2M4Eau6/lmRZjYHLTxgH5TFu/c3NdWDKF9b qX6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678704766; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=a9L5C11Sw9bIHqmk7RYsTOno8/sluS1+0CyCq3POQ0M=; b=a3Y0Qa4ridrylppipRAxMDVn2UT+WWnCDIcVqz/bsQDABWQeg8sw9+T7pAPZLN8xq6 eErewy4uhhOE59iT3ASyT6MoJXRUuExp/9m0lxGB6k7/lRDQt3E3HH/8qPzV1Y71lgCM 7osgMl1sNMo2HWJbLj0h7P99F+r4r3Hxl2/uz0hXff5PmWr7F6/wYxQKb79QzXkauWGw K+6aD1SscTL0YOsEgULsS4aIKdX6gvAPlsZXgtxFrep17NKcGx0VRYB02F0AqFaA9OaQ yhVLplLxAtrjGw99H6uPz9saD0+BUJaABcSlq4COt+ptl9kS3u8xOp/Q9hXt/PPIqPuX Yt/w== X-Gm-Message-State: AO0yUKWti6AhJWr6eU2HxQQ0v9KmQ5ALNXHOQt9TkxhBfwVTkp2ibLs6 G9eRNM5mbHGg/iE81YXrnM2BcA== X-Google-Smtp-Source: AK7set/8dDJjJEqZ2S0YFmzS1sFgfPoHjF+MbyrAUp81PZ0trhB3npHFUidCia72yC4qkIoUTax2WA== X-Received: by 2002:a17:906:bcc2:b0:923:5f10:affa with SMTP id lw2-20020a170906bcc200b009235f10affamr5327319ejb.69.1678704766105; Mon, 13 Mar 2023 03:52:46 -0700 (PDT) Received: from [192.168.0.161] (62-73-72-43.ip.btc-net.bg. [62.73.72.43]) by smtp.gmail.com with ESMTPSA id hj20-20020a170906875400b0091fdc2b4fa2sm3131405ejb.145.2023.03.13.03.52.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Mar 2023 03:52:45 -0700 (PDT) Message-ID: <45fc873b-9b71-adf2-8f2f-17134344e490@blackwall.org> Date: Mon, 13 Mar 2023 12:52:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH net] bonding: Fix warning in default_device_exit_batch() Content-Language: en-US To: Shigeru Yoshida 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 References: <20230312152158.995043-1-syoshida@redhat.com> From: Nikolay Aleksandrov In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13/03/2023 11:35, Shigeru Yoshida wrote: > 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.) > Hi Shigeru, No, that's not what I meant. It's the opposite actually, you may have an upper list but you don't have a "master" device or slave flag set. Yes, you can say that if a device has IFF_SLAVE set, then it must have a master upper device but that's not what you're checking for, you've reversed that logic to check for an upper device instead and assume there's a IFF_SLAVE flag set (which may not be true). For an upper device to be considered a "master" device, it must have the master bool set to true in its netdev_adjacent structure. We already have helpers to check for master devices and to retrieve them, e.g. check netdev_master_upper_dev_get* in net/core/dev.c The most robust way to fix it is to check if the flag was there prior to the ether_setup() call and restore it after, also to leave a nice comment about all of this. :) > Thanks, > Shigeru > Cheers, Nik