From patchwork Fri Apr 27 10:02:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tiainen, Antti" X-Patchwork-Id: 10368011 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 47D5F602DC for ; Fri, 27 Apr 2018 10:02:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 379032930E for ; Fri, 27 Apr 2018 10:02:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BF2329359; Fri, 27 Apr 2018 10:02:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from bastion.fedoraproject.org (bastion01.fedoraproject.org [209.132.181.2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 63BA22930E for ; Fri, 27 Apr 2018 10:02:29 +0000 (UTC) Received: from mailman01.phx2.fedoraproject.org (mailman01.phx2.fedoraproject.org [10.5.126.36]) by bastion01.phx2.fedoraproject.org (Postfix) with ESMTP id 3E72561127B3; Fri, 27 Apr 2018 10:02:29 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 bastion01.phx2.fedoraproject.org 3E72561127B3 Received: from mailman01.phx2.fedoraproject.org (localhost [IPv6:::1]) by mailman01.phx2.fedoraproject.org (Postfix) with ESMTP id 2D3B2256F4F4F; Fri, 27 Apr 2018 10:02:29 +0000 (UTC) Received: by mailman01.phx2.fedoraproject.org (Postfix, from userid 991) id 3B709256F4F4F; Fri, 27 Apr 2018 10:02:26 +0000 (UTC) Received: from smtp-mm-osuosl01.fedoraproject.org (smtp-mm-osuosl01.vpn.fedoraproject.org [192.168.1.23]) by mailman01.phx2.fedoraproject.org (Postfix) with ESMTP id ACFD5256F4F4E for ; Fri, 27 Apr 2018 10:02:24 +0000 (UTC) Received: from mail.niksula.hut.fi (mail.niksula.hut.fi [130.233.40.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by smtp-mm-osuosl01.fedoraproject.org (Postfix) with ESMTPS id 1E5E8980D1 for ; Fri, 27 Apr 2018 10:02:24 +0000 (UTC) Received: from kekkonen.niksula.hut.fi (kekkonen.niksula.hut.fi [130.233.41.50]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.niksula.hut.fi (Postfix) with ESMTPS id 878A44A574; Fri, 27 Apr 2018 13:02:21 +0300 (EEST) Received: by kekkonen.niksula.hut.fi (Postfix, from userid 25383) id 6B18576250; Fri, 27 Apr 2018 13:02:21 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by kekkonen.niksula.hut.fi (Postfix) with ESMTP id 678937624F; Fri, 27 Apr 2018 13:02:21 +0300 (EEST) Date: Fri, 27 Apr 2018 13:02:21 +0300 (EEST) From: Antti Tiainen X-X-Sender: atiainen@kekkonen.niksula.hut.fi To: libteam@lists.fedorahosted.org Subject: [PATCH] libteam: don't crash when trying to print unregistered device name Message-ID: User-Agent: Alpine 2.20 (GSO 67 2015-01-07) MIME-Version: 1.0 Message-ID-Hash: UJQ2XHZST2IM25LX6G7Q37FLNXS4M2ZJ X-Message-ID-Hash: UJQ2XHZST2IM25LX6G7Q37FLNXS4M2ZJ X-MailFrom: atiainen@forcepoint.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: jiri@resnulli.us X-Mailman-Version: 3.1.1 Precedence: list List-Id: Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-Virus-Scanned: ClamAV using ClamSMTP team_port_str() will crash when trying to print port name that was just unregistered, if dellink event is handled before port removal event. This is regression from Commit 046fb6ba0aec ("libteam: resynchronize ifinfo after lost RTNLGRP_LINK notifications"), which made it free all removed interfaces after ifinfo handlers are called. Put the ifinfo_destroy_removed() back to dellink/newlink handlers as it was before that commit. Clean up the ifinfo list after change handlers only if it refreshed the entire ifinfo list after lost events. There's still a rare possibility that dellink event is missed due to full socket receive buffer, which would cause ifinfo refresh and clearing removed interfaces. For this, add NULL check to team_port_str() so it doesn't try to print port device name in this situation. Signed-off-by: Antti Tiainen --- include/team.h | 1 + libteam/ifinfo.c | 7 ++++++- libteam/libteam.c | 2 +- libteam/stringify.c | 3 ++- 4 files changed, 10 insertions(+), 3 deletions(-) -- 2.16.1 diff --git a/include/team.h b/include/team.h index 9ae517d..b31c8d8 100644 --- a/include/team.h +++ b/include/team.h @@ -223,6 +223,7 @@ enum { TEAM_PORT_CHANGE = 0x1, TEAM_OPTION_CHANGE = 0x2, TEAM_IFINFO_CHANGE = 0x4, + TEAM_IFINFO_REFRESH = 0x8, TEAM_ANY_CHANGE = TEAM_PORT_CHANGE | TEAM_OPTION_CHANGE | TEAM_IFINFO_CHANGE, diff --git a/libteam/ifinfo.c b/libteam/ifinfo.c index 5c32a9c..46d56a2 100644 --- a/libteam/ifinfo.c +++ b/libteam/ifinfo.c @@ -258,6 +258,8 @@ static void obj_input_newlink(struct nl_object *obj, void *arg, bool event) uint32_t ifindex; int err; + ifinfo_destroy_removed(th); + link = (struct rtnl_link *) obj; ifindex = rtnl_link_get_ifindex(link); @@ -294,6 +296,8 @@ static void event_handler_obj_input_dellink(struct nl_object *obj, void *arg) uint32_t ifindex; int err; + ifinfo_destroy_removed(th); + link = (struct rtnl_link *) obj; ifindex = rtnl_link_get_ifindex(link); @@ -412,7 +416,8 @@ int get_ifinfo_list(struct team_handle *th) } } - ret = check_call_change_handlers(th, TEAM_IFINFO_CHANGE); + ret = check_call_change_handlers(th, TEAM_IFINFO_CHANGE | + TEAM_IFINFO_REFRESH); if (ret < 0) err(th, "get_ifinfo_list: check_call_change_handers failed"); return ret; diff --git a/libteam/libteam.c b/libteam/libteam.c index 77a06dd..ce0467e 100644 --- a/libteam/libteam.c +++ b/libteam/libteam.c @@ -236,7 +236,7 @@ int check_call_change_handlers(struct team_handle *th, break; } } - if (call_type_mask & TEAM_IFINFO_CHANGE) { + if (call_type_mask & TEAM_IFINFO_REFRESH) { ifinfo_destroy_removed(th); ifinfo_clear_changed(th); } diff --git a/libteam/stringify.c b/libteam/stringify.c index 38f4788..f1faf90 100644 --- a/libteam/stringify.c +++ b/libteam/stringify.c @@ -344,7 +344,8 @@ static bool __team_port_str(struct team_port *port, team_is_port_removed(port) ? "-" : team_is_port_changed(port) ? "*" : " ", ifindex, - team_get_ifinfo_ifname(ifinfo), + ifinfo ? team_get_ifinfo_ifname(ifinfo) : + "(removed)", team_is_port_link_up(port) ? "up": "down", team_get_port_speed(port), team_get_port_duplex(port) ? "FD" : "HD");