diff mbox series

Fix ifinfo_link_with_port race condition with newlink

Message ID 1585017827-25417-1-git-send-email-shuche@microsoft.com (mailing list archive)
State New
Headers show
Series Fix ifinfo_link_with_port race condition with newlink | expand

Commit Message

Pavel Shirshov March 24, 2020, 2:43 a.m. UTC
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 <pavel.contrib@gmail.com>
---
 libteam/ifinfo.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Jiri Pirko March 28, 2020, 3:39 p.m. UTC | #1
Tue, Mar 24, 2020 at 03:43:47AM CET, pavel.contrib@gmail.com wrote:
>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>

From is: Shuotian Cheng <pavel.contrib@gmail.com>

Looks messed up. Please fix.


>Signed-off-by: Pavel Shirshov <pavel.contrib@gmail.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
>
diff mbox series

Patch

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)