From patchwork Thu Jul 5 18:24:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lam, Tiago" X-Patchwork-Id: 940134 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=intel.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41M5qs307hz9s47 for ; Fri, 6 Jul 2018 04:24:57 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id C175AD61; Thu, 5 Jul 2018 18:24:55 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 2B7B9D5E for ; Thu, 5 Jul 2018 18:24:54 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 211EA70B for ; Thu, 5 Jul 2018 18:24:53 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Jul 2018 11:24:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,313,1526367600"; d="scan'208";a="52885752" Received: from silpixa00399125.ir.intel.com ([10.237.223.34]) by fmsmga008.fm.intel.com with ESMTP; 05 Jul 2018 11:24:51 -0700 From: Tiago Lam To: ovs-dev@openvswitch.org Date: Thu, 5 Jul 2018 19:24:47 +0100 Message-Id: <1530815087-164740-1-git-send-email-tiago.lam@intel.com> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] netdev-linux: Fix segfault in update_lag(). X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org A bissect shows that commit d22f892 ("netdev-linux: monitor and offload LAG slaves to TC") introduced netdev_linux_update_lag(), which is now triggering a crash in the "datapath - ping over bond" test in system-userspace-testsuite: (gdb) bt #0 0x00000000009762e7 in netdev_linux_update_lag (change=0x7ffdff013750) at lib/netdev-linux.c:728 728 if (is_netdev_linux_class(master_netdev->netdev_class)) { This fixes the crash by simply returning in case netdev_from_name() returns NULL, as this should indicate the master is not attached to the bridge. Additionally, netdev_linux_update_lag() isn't "clearing" the netdev reference it gets from netdev_from_name(), meaning its ref_cnt is incremented but never decremented. Thus, also call netdev_close() before returning. CC: John Hurley Fixes: d22f8927 ("netdev-linux: monitor and offload LAG slaves to TC") Signed-off-by: Tiago Lam --- lib/netdev-linux.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 8e6c637..0c42268 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -724,11 +724,15 @@ netdev_linux_update_lag(struct rtnetlink_change *change) if_indextoname(change->master_ifindex, master_name); master_netdev = netdev_from_name(master_name); + if (!master_netdev) { + return; + } if (is_netdev_linux_class(master_netdev->netdev_class)) { block_id = netdev_get_block_id(master_netdev); if (!block_id) { - return; + netdev_close(master_netdev); + return; } lag = xmalloc(sizeof *lag); @@ -744,6 +748,8 @@ netdev_linux_update_lag(struct rtnetlink_change *change) free(lag); } } + + netdev_close(master_netdev); } } else if (change->master_ifindex == 0) { /* Check if this was a lag slave that has been freed. */