From patchwork Tue Jun 13 18:34:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Raphael Tiovalen X-Patchwork-Id: 1794626 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=P5SEiX21; dkim-atps=neutral Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Qgcg34DF7z20Wq for ; Wed, 14 Jun 2023 04:35:11 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 8EE4D611C8; Tue, 13 Jun 2023 18:35:09 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 8EE4D611C8 Authentication-Results: smtp3.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=P5SEiX21 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id erfYEOiZvz3l; Tue, 13 Jun 2023 18:35:08 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 5BC99611A1; Tue, 13 Jun 2023 18:35:04 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 5BC99611A1 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 196D1C008D; Tue, 13 Jun 2023 18:35:01 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2C211C008E for ; Tue, 13 Jun 2023 18:35:00 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 03A3561142 for ; Tue, 13 Jun 2023 18:35:00 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 03A3561142 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6JkdPsdx5fpF for ; Tue, 13 Jun 2023 18:34:58 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org D6B8A60F18 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by smtp3.osuosl.org (Postfix) with ESMTPS id D6B8A60F18 for ; Tue, 13 Jun 2023 18:34:57 +0000 (UTC) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1b3b3f67ad6so29254145ad.3 for ; Tue, 13 Jun 2023 11:34:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686681297; x=1689273297; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=90+H2Fj8tbaOnY9UyUQZKaWVzjBOTUXw143dC3sCxPg=; b=P5SEiX21U+kOMQY2abnVchT/W12pR/s8yYmfYkaxMG20fZBra9gufyvimjdcGwqQrB J3jcol1/cPG+7sPy+IC9ob4NzhgmoWJI36u3egDSjZryYhSGOx/KZVBYyy4JgZT76dLJ UZ0QcBiAppHZvXJePAVBbr7UqXAoIubzh0WZFjZRfdLVjqZkbOvvg1DDTXcTETGnUGBF 4oLPCJVIHp+3LPlJdBdxK+Siw7YfbyLXBxno2K7TMYVMkwFvfOEgQJlmxNwUsniyz2At c3iE/V+ssceRSuSU92BXnKmI59SElvdmN46dlWFxTAbSayZLP/dvS7IwTyACMUGdWo3B mO/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686681297; x=1689273297; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=90+H2Fj8tbaOnY9UyUQZKaWVzjBOTUXw143dC3sCxPg=; b=lTWTd7n60Tv/7ut9B4aTxOzx+ChCXgLS4HpRdiXyU55ntWZ5GO5wQXN9iiY0+rMcd3 U0nH5UOFGla5W6mGfqBTTIIp3TQ2wVO5mH2EtO4UircLxqFugdDMPpTKhV9kBHsk1kNE 4XMqcKqJWlHjrouaBaKAtn09rZ9VhiTlD22NY6yfgmDLWx/9O2tCP0bZtyRYrUcQlAkn 80AbSkQgDtg3pMOM9j1NPef634c1N5VArT8xvxRFTyLlyjquxkV9QldT3FqU6sHyMMei 6yZlmzqOiKAaQoPg3ECOX2o/CHDv02jOZHFXEeWiKuZ4mhKECFAhZnynnqtvClevb4xx Mzrg== X-Gm-Message-State: AC+VfDxl/7RQWLJTma0ZZXjEzGNaBQZHr8Q4pfdeQ6v3yN7uq2kFQVBY S42t8G527AxVuY/oMcT+2E9FODV/LXl01Q== X-Google-Smtp-Source: ACHHUZ5vTXQ/EosV4Jw0jBGeFIS2rD5CpKEa6wT+za2yLKkh0pTpzAOhE+TP7mIrkn42417X5qfX1A== X-Received: by 2002:a17:902:db09:b0:1b3:d357:5ea6 with SMTP id m9-20020a170902db0900b001b3d3575ea6mr5159045plx.53.1686681297022; Tue, 13 Jun 2023 11:34:57 -0700 (PDT) Received: from JRT-PC.lan ([103.252.200.22]) by smtp.gmail.com with ESMTPSA id u3-20020a170902e80300b001b04aee1f99sm10531125plg.228.2023.06.13.11.34.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 11:34:56 -0700 (PDT) From: James Raphael Tiovalen To: dev@openvswitch.org Date: Wed, 14 Jun 2023 02:34:41 +0800 Message-Id: <20230613183443.31540-7-jamestiotio@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230613183443.31540-1-jamestiotio@gmail.com> References: <20230613183443.31540-1-jamestiotio@gmail.com> MIME-Version: 1.0 Cc: Simon Horman , James Raphael Tiovalen Subject: [ovs-dev] [PATCH v12 6/8] ovs-vsctl: Fix crash when routing is enabled X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" In the case where routing is enabled, the bridge member of the `vsctl_port` structs is not populated. This can cause a crash if we attempt to access it. This patch fixes the crash by checking if the bridge member is valid before attempting to access it. In the `check_conflicts` function, we print both the port name and the bridge name if routing is disabled and we only print the port name if routing is enabled. Signed-off-by: James Raphael Tiovalen Reviewed-by: Simon Horman Acked-by: Eelco Chaudron --- utilities/ovs-vsctl.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index b3c75f8ba..f55c2965a 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -888,14 +888,23 @@ check_conflicts(struct vsctl_context *vsctl_ctx, const char *name, port = shash_find_data(&vsctl_ctx->ports, name); if (port) { - ctl_fatal("%s because a port named %s already exists on " - "bridge %s", msg, name, port->bridge->name); + if (port->bridge) { + ctl_fatal("%s because a port named %s already exists on " + "bridge %s", msg, name, port->bridge->name); + } else { + ctl_fatal("%s because a port named %s already exists", msg, name); + } } iface = shash_find_data(&vsctl_ctx->ifaces, name); if (iface) { - ctl_fatal("%s because an interface named %s already exists " - "on bridge %s", msg, name, iface->port->bridge->name); + if (iface->port->bridge) { + ctl_fatal("%s because an interface named %s already exists " + "on bridge %s", msg, name, iface->port->bridge->name); + } else { + ctl_fatal("%s because an interface named %s already exists", msg, + name); + } } free(msg); @@ -935,7 +944,7 @@ find_port(struct vsctl_context *vsctl_ctx, const char *name, bool must_exist) ovs_assert(vsctl_ctx->cache_valid); port = shash_find_data(&vsctl_ctx->ports, name); - if (port && !strcmp(name, port->bridge->name)) { + if (port && port->bridge && !strcmp(name, port->bridge->name)) { port = NULL; } if (must_exist && !port) { @@ -953,7 +962,8 @@ find_iface(struct vsctl_context *vsctl_ctx, const char *name, bool must_exist) ovs_assert(vsctl_ctx->cache_valid); iface = shash_find_data(&vsctl_ctx->ifaces, name); - if (iface && !strcmp(name, iface->port->bridge->name)) { + if (iface && iface->port->bridge && + !strcmp(name, iface->port->bridge->name)) { iface = NULL; } if (must_exist && !iface) {