From patchwork Wed Feb 14 09:58:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Benli Ye X-Patchwork-Id: 873292 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=) 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 3zhFGy4n97z9t3C for ; Wed, 14 Feb 2018 20:58:48 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 11D3B10C6; Wed, 14 Feb 2018 09:58:46 +0000 (UTC) X-Original-To: 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 053BA10B9 for ; Wed, 14 Feb 2018 09:58:45 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from EX13-EDG-OU-001.vmware.com (ex13-edg-ou-001.vmware.com [208.91.0.189]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 6022E418 for ; Wed, 14 Feb 2018 09:58:44 +0000 (UTC) Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Wed, 14 Feb 2018 01:58:37 -0800 Received: from EX13-CAS-001.vmware.com (ex13-cas-001.vmware.com [10.113.191.51]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id BADA6B0774; Wed, 14 Feb 2018 01:58:39 -0800 (PST) Received: from dev.openstack.local (10.113.170.11) by EX13-MBX-000.vmware.com (10.113.191.20) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Wed, 14 Feb 2018 01:58:38 -0800 From: Daniel Benli Ye To: , , Date: Wed, 14 Feb 2018 01:58:31 -0800 Message-ID: <1518602311-16709-1-git-send-email-daniely@vmware.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.113.170.11] X-ClientProxiedBy: EX13-CAS-001.vmware.com (10.113.191.51) To EX13-MBX-000.vmware.com (10.113.191.20) Received-SPF: None (EX13-EDG-OU-001.vmware.com: daniely@vmware.com does not designate permitted sender hosts) X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD 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 v1] ofproto-dpif-ipfix: Fix an issue in flow key part 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: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Benli Ye As struct ipfix_data_record_flow_key_iface didn't calculate its length in flow key part, it may cause problem when flow key part length is not enough. Use MAX_IF_LEN and MAX_IF_DESCR to pre-allocate memory for ipfix_data_record_flow_key_iface. Signed-off-by: Daniel Benli Ye --- ofproto/ofproto-dpif-ipfix.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/ofproto/ofproto-dpif-ipfix.c b/ofproto/ofproto-dpif-ipfix.c index c7ddeb9..1058927 100644 --- a/ofproto/ofproto-dpif-ipfix.c +++ b/ofproto/ofproto-dpif-ipfix.c @@ -314,6 +314,7 @@ BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_flow_key_common) == 20); /* Part of data record flow key for interface information. Since some of the * elements have variable length, members of this structure should be appended * to the 'struct dp_packet' one by one. */ +OVS_PACKED( struct ipfix_data_record_flow_key_iface { ovs_be32 if_index; /* (INGRESS | EGRESS)_INTERFACE */ ovs_be32 if_type; /* (INGRESS | EGRESS)_INTERFACE_TYPE */ @@ -321,7 +322,9 @@ struct ipfix_data_record_flow_key_iface { char *if_name; uint8_t if_descr_len; /* Variable length element: INTERFACE_DESCRIPTION */ char *if_descr; -}; +}); +BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_flow_key_iface) == + 10 + 2 * sizeof(char *)); /* Part of data record flow key for VLAN entities. */ OVS_PACKED( @@ -511,8 +514,21 @@ BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_aggregated_tcp) == 48); */ #define MAX_TUNNEL_KEY_LEN 8 +#define MAX_IF_NAME_LEN 64 +#define MAX_IF_DESCR_LEN 128 + +/* + * Calculate interface information length in flow key. + * This is used to calculate max flow key length. + */ +#define FLOW_KEY_IFACE_LEN \ + (sizeof(struct ipfix_data_record_flow_key_iface) \ + - 2 * sizeof(char *) \ + + MAX_IF_NAME_LEN + MAX_IF_DESCR_LEN) + #define MAX_FLOW_KEY_LEN \ (sizeof(struct ipfix_data_record_flow_key_common) \ + + FLOW_KEY_IFACE_LEN \ + sizeof(struct ipfix_data_record_flow_key_vlan) \ + sizeof(struct ipfix_data_record_flow_key_ip) \ + MAX(sizeof(struct ipfix_data_record_flow_key_ipv4), \ @@ -1396,7 +1412,6 @@ ipfix_define_template_fields(enum ipfix_proto_l2 l2, enum ipfix_proto_l3 l3, DEF(ETHERNET_TYPE); DEF(ETHERNET_HEADER_LENGTH); - /* Interface Information Elements */ DEF(INGRESS_INTERFACE); DEF(INGRESS_INTERFACE_TYPE); DEF(INTERFACE_NAME); @@ -2030,9 +2045,11 @@ ipfix_get_iface_data_record(const struct dpif_ipfix *di, odp_port_t port_no, smap_destroy(&netdev_status); data->if_index = htonl(port->ifindex); - data->if_descr_len = data->if_descr ? strlen(data->if_descr) : 0; + data->if_descr_len = data->if_descr ? strlen(data->if_descr) > MAX_IF_DESCR_LEN + ? MAX_IF_DESCR_LEN : strlen(data->if_descr) : 0; data->if_name = nullable_xstrdup(netdev_get_name(port->ofport->netdev)); - data->if_name_len = data->if_name ? strlen(data->if_name) : 0; + data->if_name_len = data->if_name ? strlen(data->if_name) > MAX_IF_NAME_LEN + ? MAX_IF_NAME_LEN : strlen(data->if_name) : 0; return 0; }