From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CAB015A493; Tue, 16 Jan 2024 20:01:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705435260; cv=none; b=GZZ13/0hWycSgpaiByGubue20K2bpsmYNgJbmLXvAb/gXBzjPqpRnR2HokfxmSKsywMl7H4JlrUAVrHxZjHPzFzWlGW/a79gZ5VcOPCk5f2HrNi0GBMWAhMKkNXzun2xk1qFdXnQmKewLoY8rUQ8v1kncKQNsm/UOOprgB6KIWM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705435260; c=relaxed/simple; bh=Qls9ZxlTaEFzdflbK4KVew4CfKTH7ZKTxFOXjhHdDe0=; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version:X-stable: X-Patchwork-Hint:X-stable-base:Content-Transfer-Encoding; b=iZCF5jqqEgH5Ap+SHy/uEvPhqstOoWBb+75lJMJ7RQcr/4dRHh1dMKFZ65JcP5D0GI2IxrV1uU1+V+rV4TswxxQWwY69ptiGpyiOaRb3mhjhXpX6ujXiEenFrlpZVm4zaybo8FgSmHmDLWEAKDVI5SpUntNcg5TT8rjaCxVN3o0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NKXMuW0S; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NKXMuW0S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8DA3C433C7; Tue, 16 Jan 2024 20:00:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705435260; bh=Qls9ZxlTaEFzdflbK4KVew4CfKTH7ZKTxFOXjhHdDe0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NKXMuW0SOvHq6ElgrMBtQNOKdVhRfGmhbxeyjwWR/8WqPP3mRm8OLROLnSbcIglI5 i/56u60yplcGj5lyvHh2Flluz1NhRwj2OrpPc+TyozEj2nrfuFyabaMb/36LZuwvkS JJYwq6IPOC0Rvr8jlNu8DEzuNjsVVEAri9oMajnSRsNfTiIn5w+bSCCk1HPeJDTZ+t vG9Rv6wG71ah0sEislLCf30HZ0G25hWJRHzG+XCu886PW2tJMhkH0fqNjJLLUsTqmR O1/NifIHurANsrZakMeNj8DSRMz5iIPO0sY6c42Pi+e4Rrc95R004VGbC2Qnmi9eQN xAyp6yRZitEYA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zhengchao Shao , Jay Vosburgh , Paolo Abeni , Sasha Levin , j.vosburgh@gmail.com, andy@greyhouse.net, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.10 06/44] bonding: return -ENOMEM instead of BUG in alb_upper_dev_walk Date: Tue, 16 Jan 2024 14:59:35 -0500 Message-ID: <20240116200044.258335-6-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240116200044.258335-1-sashal@kernel.org> References: <20240116200044.258335-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.10.208 Content-Transfer-Encoding: 8bit From: Zhengchao Shao [ Upstream commit d6b83f1e3707c4d60acfa58afd3515e17e5d5384 ] If failed to allocate "tags" or could not find the final upper device from start_dev's upper list in bond_verify_device_path(), only the loopback detection of the current upper device should be affected, and the system is no need to be panic. So return -ENOMEM in alb_upper_dev_walk to stop walking, print some warn information when failed to allocate memory for vlan tags in bond_verify_device_path. I also think that the following function calls netdev_walk_all_upper_dev_rcu ---->>>alb_upper_dev_walk ---------->>>bond_verify_device_path >From this way, "end device" can eventually be obtained from "start device" in bond_verify_device_path, IS_ERR(tags) could be instead of IS_ERR_OR_NULL(tags) in alb_upper_dev_walk. Signed-off-by: Zhengchao Shao Acked-by: Jay Vosburgh Link: https://lore.kernel.org/r/20231118081653.1481260-1-shaozhengchao@huawei.com Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- drivers/net/bonding/bond_alb.c | 3 ++- drivers/net/bonding/bond_main.c | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c index 64ba465741a7..81a5e7622ea7 100644 --- a/drivers/net/bonding/bond_alb.c +++ b/drivers/net/bonding/bond_alb.c @@ -971,7 +971,8 @@ static int alb_upper_dev_walk(struct net_device *upper, if (netif_is_macvlan(upper) && !strict_match) { tags = bond_verify_device_path(bond->dev, upper, 0); if (IS_ERR_OR_NULL(tags)) - BUG(); + return -ENOMEM; + alb_send_lp_vid(slave, upper->dev_addr, tags[0].vlan_proto, tags[0].vlan_id); kfree(tags); diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 50fabba04248..506d6fdbfacc 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -2777,8 +2777,11 @@ struct bond_vlan_tag *bond_verify_device_path(struct net_device *start_dev, if (start_dev == end_dev) { tags = kcalloc(level + 1, sizeof(*tags), GFP_ATOMIC); - if (!tags) + if (!tags) { + net_err_ratelimited("%s: %s: Failed to allocate tags\n", + __func__, start_dev->name); return ERR_PTR(-ENOMEM); + } tags[level].vlan_proto = VLAN_N_VID; return tags; } -- 2.43.0