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 B5080188A39; Wed, 25 Sep 2024 12:00:07 +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=1727265607; cv=none; b=b97npF+tDmug1ZH6sStLD52ZH8knGu8rl7GBMZ0nJVC6x7pyHtc8Rsqzt7DV5+qIy6yR0ysub349/tKkixb21Yi4zHk0XHn6Efd+lmjn1SdpI7WM2P5GWoabrnqgpBHZsXXnIhfjlmmZCKnUkKd1fvjDMg+/42zFa6L2pUvKYzM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727265607; c=relaxed/simple; bh=lNsX2PUTbrpcPmh4/XGLpB4kD7q++jX5lt21AAe53jE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gtDhzM6dW06+AsqwTUanQ2zS5ihHZ6MMfJgghit7Jxvq97ocn7O39qq6Lue76PPRycP0Y0DK7/yWZx0EH5DvuOSsYPE86+gt9/+X3zYJ07aWMiAj/vVpD5fHa1yfgkT72mm08o+hwaoSCO+JuFmy1ajj6DjpwUjQO6uMWG9sNHE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XQlXw+tF; 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="XQlXw+tF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0E59C4CEC7; Wed, 25 Sep 2024 12:00:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727265607; bh=lNsX2PUTbrpcPmh4/XGLpB4kD7q++jX5lt21AAe53jE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XQlXw+tFPpt35uzSknQ0t+YTdMeO8hLepOju3kavMY0RS2YnD5Yufqg+h+anJIhwy SY1+KvuqjWWMYFgpnFtBa3IXpqwY/XgnWuygZpXutgDlwVX6DSorfofnx2s/Bwwc+B Zzrl/rmiW2XWfcx0cL07+IKGUYUfDC7d6Wj7z5a2OtkLzrmvU/tZXvonVK3oAmJ8qJ QGZBeFulbymP9hkEo/KiWoOK17+b3tf0iU5c1ehATWoxBKkz2gapkGteiHCf6+55EP kBdpoPSMBZnKn2ERRNGhVA0SsDcgI6l/n87USQE84Oia9s8TRMntXOas/jayytm4ct bq1kD9+n7DMpw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Breno Leitao , Paolo Abeni , Jakub Kicinski , Sasha Levin , davem@davemloft.net, edumazet@google.com, horms@kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 6.10 047/197] netpoll: Ensure clean state on setup failures Date: Wed, 25 Sep 2024 07:51:06 -0400 Message-ID: <20240925115823.1303019-47-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240925115823.1303019-1-sashal@kernel.org> References: <20240925115823.1303019-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 6.10.11 Content-Transfer-Encoding: 8bit From: Breno Leitao [ Upstream commit ae5a0456e0b4cfd7e61619e55251ffdf1bc7adfb ] Modify netpoll_setup() and __netpoll_setup() to ensure that the netpoll structure (np) is left in a clean state if setup fails for any reason. This prevents carrying over misconfigured fields in case of partial setup success. Key changes: - np->dev is now set only after successful setup, ensuring it's always NULL if netpoll is not configured or if netpoll_setup() fails. - np->local_ip is zeroed if netpoll setup doesn't complete successfully. - Added DEBUG_NET_WARN_ON_ONCE() checks to catch unexpected states. - Reordered some operations in __netpoll_setup() for better logical flow. These changes improve the reliability of netpoll configuration, since it assures that the structure is fully initialized or totally unset. Suggested-by: Paolo Abeni Signed-off-by: Breno Leitao Link: https://patch.msgid.link/20240822111051.179850-2-leitao@debian.org Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/core/netpoll.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/net/core/netpoll.c b/net/core/netpoll.c index 55bcacf67df3b..e082139004093 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -626,12 +626,9 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev) const struct net_device_ops *ops; int err; - np->dev = ndev; - strscpy(np->dev_name, ndev->name, IFNAMSIZ); - if (ndev->priv_flags & IFF_DISABLE_NETPOLL) { np_err(np, "%s doesn't support polling, aborting\n", - np->dev_name); + ndev->name); err = -ENOTSUPP; goto out; } @@ -649,7 +646,7 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev) refcount_set(&npinfo->refcnt, 1); - ops = np->dev->netdev_ops; + ops = ndev->netdev_ops; if (ops->ndo_netpoll_setup) { err = ops->ndo_netpoll_setup(ndev, npinfo); if (err) @@ -660,6 +657,8 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev) refcount_inc(&npinfo->refcnt); } + np->dev = ndev; + strscpy(np->dev_name, ndev->name, IFNAMSIZ); npinfo->netpoll = np; /* last thing to do is link it to the net device structure */ @@ -677,6 +676,7 @@ EXPORT_SYMBOL_GPL(__netpoll_setup); int netpoll_setup(struct netpoll *np) { struct net_device *ndev = NULL; + bool ip_overwritten = false; struct in_device *in_dev; int err; @@ -741,6 +741,7 @@ int netpoll_setup(struct netpoll *np) } np->local_ip.ip = ifa->ifa_local; + ip_overwritten = true; np_info(np, "local IP %pI4\n", &np->local_ip.ip); } else { #if IS_ENABLED(CONFIG_IPV6) @@ -757,6 +758,7 @@ int netpoll_setup(struct netpoll *np) !!(ipv6_addr_type(&np->remote_ip.in6) & IPV6_ADDR_LINKLOCAL)) continue; np->local_ip.in6 = ifp->addr; + ip_overwritten = true; err = 0; break; } @@ -787,6 +789,9 @@ int netpoll_setup(struct netpoll *np) return 0; put: + DEBUG_NET_WARN_ON_ONCE(np->dev); + if (ip_overwritten) + memset(&np->local_ip, 0, sizeof(np->local_ip)); netdev_put(ndev, &np->dev_tracker); unlock: rtnl_unlock(); -- 2.43.0