From patchwork Mon Oct 21 07:12:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li,Rongqing via dev" X-Patchwork-Id: 1180365 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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=none (p=none dis=none) header.from=openvswitch.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=altencalsoftlabs.com header.i=@altencalsoftlabs.com header.b="spdwTwxl"; dkim-atps=neutral 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 46xSjL3sjkz9sP3 for ; Mon, 21 Oct 2019 18:20:53 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 46D6ACDB; Mon, 21 Oct 2019 07:20:51 +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 EF120CC7 for ; Mon, 21 Oct 2019 07:20:49 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.altencalsoftlabs.com (mail.altencalsoftlabs.com [182.73.72.41]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 2B0E689C for ; Mon, 21 Oct 2019 07:20:49 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.altencalsoftlabs.com (Postfix) with ESMTP id 471ED4420189 for ; Mon, 21 Oct 2019 12:50:44 +0530 (IST) Received: from mail.altencalsoftlabs.com ([127.0.0.1]) by localhost (mail.altencalsoftlabs.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id hz7EKk1yMLsY; Mon, 21 Oct 2019 12:50:44 +0530 (IST) Received: from localhost (localhost [127.0.0.1]) by mail.altencalsoftlabs.com (Postfix) with ESMTP id EAFEA442017D; Mon, 21 Oct 2019 12:50:43 +0530 (IST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.altencalsoftlabs.com EAFEA442017D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=altencalsoftlabs.com; s=selector; t=1571642444; bh=FSFvW4C+QE1Bm1YsqZB5ZOnGzkB7ObwWF51VXW9VV4k=; h=From:To:Date:Message-Id; b=spdwTwxlOKnVNSEr7bv8xx3aOVMB3rJV9thuy8eJSuNOY4smVGrm50C/1HnxbjMI+ DATtODNPvnoYU0r+kXga77BKEgVEYG8StT8snQvmQK8VUAufT9FlxNakyeX1dGgvIe JqC/0Komq9wdSP9wbILESK+6Kj7lrgx5mWmdKQe4= X-Virus-Scanned: amavisd-new at altencalsoftlabs.com Received: from mail.altencalsoftlabs.com ([127.0.0.1]) by localhost (mail.altencalsoftlabs.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id jdFw7ORObO9T; Mon, 21 Oct 2019 12:50:43 +0530 (IST) Received: from localhost.localdomain (unknown [10.1.0.4]) by mail.altencalsoftlabs.com (Postfix) with ESMTPSA id 3BE7F4420173; Mon, 21 Oct 2019 12:50:43 +0530 (IST) To: ovs-dev@openvswitch.org Date: Mon, 21 Oct 2019 12:42:02 +0530 Message-Id: <1571641922-23074-1-git-send-email-rudrasurya.r@altencalsoftlabs.com> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Surya Rudra Subject: [ovs-dev] [PATCH] lldp: Fix for OVS crashes when a LLDP-enabled port is deleted 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: , X-Patchwork-Original-From: Surya Rudra via dev From: "Li,Rongqing via dev" Reply-To: Surya Rudra MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Issue: When LLDP is enabled on a port, a structure to hold LLDP related state is created and that structure has a reference to the port. The ofproto monitor thread accesses the LLDP structure to periodically send packets over the associated port. When the port is deleted, the LLDP structure is not cleaned up and it continues to refer to the deleted port. When the monitor thread attempts to access the deleted port OVS crashes. Crash can happen with bridge delete and bond delete also. Fix: Remove all references to the LLDP structure and free it when the port is deleted. Signed-off-by: Surya Rudra --- ofproto/ofproto-dpif.c | 10 +++++----- ofproto/ofproto.c | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 496a16c..ab5f487 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -2374,24 +2374,24 @@ set_lldp(struct ofport *ofport_, const struct smap *cfg) { struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); + struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto); int error = 0; if (cfg) { if (!ofport->lldp) { - struct ofproto_dpif *ofproto; - - ofproto = ofproto_dpif_cast(ofport->up.ofproto); ofproto->backer->need_revalidate = REV_RECONFIGURE; ofport->lldp = lldp_create(ofport->up.netdev, ofport_->mtu, cfg); } if (!lldp_configure(ofport->lldp, cfg)) { + lldp_unref(ofport->lldp); + ofport->lldp = NULL; error = EINVAL; } - } - if (error) { + } else if (ofport->lldp) { lldp_unref(ofport->lldp); ofport->lldp = NULL; + ofproto->backer->need_revalidate = REV_RECONFIGURE; } ofproto_dpif_monitor_port_update(ofport, diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index b4249b0..3aaa45a 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -2556,6 +2556,9 @@ ofproto_port_unregister(struct ofproto *ofproto, ofp_port_t ofp_port) { struct ofport *port = ofproto_get_port(ofproto, ofp_port); if (port) { + if (port->ofproto->ofproto_class->set_lldp) { + port->ofproto->ofproto_class->set_lldp(port, NULL); + } if (port->ofproto->ofproto_class->set_stp_port) { port->ofproto->ofproto_class->set_stp_port(port, NULL); }