Fix ifinfo_link_with_port race condition with newlink
diff mbox series

Message ID 1584053201-19150-2-git-send-email-shuche@microsoft.com
State New
Headers show
Series
  • Fix ifinfo_link_with_port race condition with newlink
Related show

Commit Message

Pavel Shirshov March 12, 2020, 10:46 p.m. UTC
From: Pavel Shirshov <pavel.contrib@gmail.com>

When a member port is enslaved into a port channel
immediately after the port channel was created,
it is possible to get member port ifinfo structure
not initialized for the member port because of a race
condition.

The race condition here occurs because order of
following events is not strict:
 - adding the member port to the port channel;
 - creating ifinfo structure for the member port.

The error message "Failed to link port with ifinfo" is
thrown when a member port is tried to be added to the
team handler's port list before ifinfo structure was
initialized.

To fix this situation ifinfo_find_create() is used
to search member ports ifinfo structure in
ifinfo_link_with_port().

Signed-off-by: Shuotian Cheng <shuche@microsoft.com>
Signed-off-by: Pavel Shirshov <pavelsh@microsoft.com>
---
 libteam/ifinfo.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Jiri Pirko March 23, 2020, 11:12 a.m. UTC | #1
Thu, Mar 12, 2020 at 11:46:41PM CET, pavel.contrib@gmail.com wrote:
>From: Pavel Shirshov <pavel.contrib@gmail.com>

From and Signed-off-by should be one email address. Could you please
respin?

Otherwise the patch looks fine to me.

>
>When a member port is enslaved into a port channel
>immediately after the port channel was created,
>it is possible to get member port ifinfo structure
>not initialized for the member port because of a race
>condition.
>
>The race condition here occurs because order of
>following events is not strict:
> - adding the member port to the port channel;
> - creating ifinfo structure for the member port.
>
>The error message "Failed to link port with ifinfo" is
>thrown when a member port is tried to be added to the
>team handler's port list before ifinfo structure was
>initialized.
>
>To fix this situation ifinfo_find_create() is used
>to search member ports ifinfo structure in
>ifinfo_link_with_port().
>
>Signed-off-by: Shuotian Cheng <shuche@microsoft.com>
>Signed-off-by: Pavel Shirshov <pavelsh@microsoft.com>
>---
> libteam/ifinfo.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
>diff --git a/libteam/ifinfo.c b/libteam/ifinfo.c
>index 46d56a2..a15788b 100644
>--- a/libteam/ifinfo.c
>+++ b/libteam/ifinfo.c
>@@ -453,7 +453,10 @@ int ifinfo_link_with_port(struct team_handle *th, uint32_t ifindex,
> {
> 	struct team_ifinfo *ifinfo;
> 
>-	ifinfo = ifinfo_find(th, ifindex);
>+	if (port)
>+		ifinfo = ifinfo_find_create(th, ifindex);
>+	else
>+		ifinfo = ifinfo_find(th, ifindex);
> 	if (!ifinfo)
> 		return -ENOENT;
> 	if (ifinfo->linked)
>-- 
>2.7.4
>

Patch
diff mbox series

diff --git a/libteam/ifinfo.c b/libteam/ifinfo.c
index 46d56a2..a15788b 100644
--- a/libteam/ifinfo.c
+++ b/libteam/ifinfo.c
@@ -453,7 +453,10 @@  int ifinfo_link_with_port(struct team_handle *th, uint32_t ifindex,
 {
 	struct team_ifinfo *ifinfo;
 
-	ifinfo = ifinfo_find(th, ifindex);
+	if (port)
+		ifinfo = ifinfo_find_create(th, ifindex);
+	else
+		ifinfo = ifinfo_find(th, ifindex);
 	if (!ifinfo)
 		return -ENOENT;
 	if (ifinfo->linked)