From patchwork Thu Aug 18 09:41:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ales Musil X-Patchwork-Id: 1667620 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" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ftZyxrmF; 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 4M7fz65SvGz1yg3 for ; Thu, 18 Aug 2022 19:41:22 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 4261F61162; Thu, 18 Aug 2022 09:41:20 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 4261F61162 Authentication-Results: smtp3.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ftZyxrmF 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 BlyoaymYBtXT; Thu, 18 Aug 2022 09:41:19 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id 4EFC260C28; Thu, 18 Aug 2022 09:41:18 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 4EFC260C28 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1164DC0032; Thu, 18 Aug 2022 09:41:18 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2749FC002D for ; Thu, 18 Aug 2022 09:41:16 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id E848784036 for ; Thu, 18 Aug 2022 09:41:15 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org E848784036 Authentication-Results: smtp1.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ftZyxrmF X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id inH4AyMoE668 for ; Thu, 18 Aug 2022 09:41:15 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org F007C84029 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id F007C84029 for ; Thu, 18 Aug 2022 09:41:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660815673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=WLbXF7GN9H5afqrT6AHP6M8KpG3i6etKivhAnDL6PzY=; b=ftZyxrmFPiiMh6vnVof1RF55Zva6X7nATCsXlhhAkT5Vn313JRHtlUcJHY7VJB57Wop9lW Qo9uFGjlNbc2ry/CpnsOUn89knWWiFiWrvcbdmm5Zqh+thxJwlb5D0PUXWW8GdQk039Bq2 W6/GOEE1FTwbV7fawCQkkdhnQbfyS/A= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-340-CnUHWQCFNAuDdyXgt83fBA-1; Thu, 18 Aug 2022 05:41:12 -0400 X-MC-Unique: CnUHWQCFNAuDdyXgt83fBA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4389A1C06ED3 for ; Thu, 18 Aug 2022 09:41:11 +0000 (UTC) Received: from amusil.redhat.com (unknown [10.34.130.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1EC514583C2; Thu, 18 Aug 2022 09:41:10 +0000 (UTC) From: Ales Musil To: dev@openvswitch.org Date: Thu, 18 Aug 2022 11:41:10 +0200 Message-Id: <20220818094110.160733-1-amusil@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH ovn v2] controller: Fix wrong controller action definition 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" The controller action had a wrong wrong userdata_len due to missing substraction of previous data len. The pointer to oc was not moved correctly so it could in theory point to wrong memory. In order to fix that expose encode_start_controller_op and encode_finish_controller_op which are helper methods to define the controller action. Use those instead of manually creating the action. At the same time use stack buffer for the ofpbuf which should be large enough to hold related data without any heap allocations. Fixes: e52c2451 ("physical.c: Fix bug of wrong use in vm migration") Signed-off-by: Ales Musil Acked-by: Mark Michelson --- controller/physical.c | 19 ++++++------------- include/ovn/actions.h | 4 ++++ lib/actions.c | 4 ++-- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/controller/physical.c b/controller/physical.c index 552837bcd..bc8c304fe 100644 --- a/controller/physical.c +++ b/controller/physical.c @@ -992,8 +992,8 @@ setup_rarp_activation_strategy(const struct sbrec_port_binding *binding, struct ovn_desired_flow_table *flow_table) { struct match match = MATCH_CATCHALL_INITIALIZER; - struct ofpbuf ofpacts; - ofpbuf_init(&ofpacts, 0); + uint64_t stub[1024 / 8]; + struct ofpbuf ofpacts = OFPBUF_STUB_INITIALIZER(stub); /* Unblock the port on ingress RARP. */ match_set_dl_type(&match, htons(ETH_TYPE_RARP)); @@ -1001,18 +1001,11 @@ setup_rarp_activation_strategy(const struct sbrec_port_binding *binding, load_logical_ingress_metadata(binding, zone_ids, &ofpacts); - struct ofpact_controller *oc = ofpact_put_CONTROLLER(&ofpacts); - oc->max_len = UINT16_MAX; - oc->reason = OFPR_ACTION; - - struct action_header ah = { - .opcode = htonl(ACTION_OPCODE_ACTIVATION_STRATEGY_RARP) - }; - ofpbuf_put(&ofpacts, &ah, sizeof ah); + uint32_t ofs = + encode_start_controller_op(ACTION_OPCODE_ACTIVATION_STRATEGY_RARP, + false, NX_CTLR_NO_METER, &ofpacts); + encode_finish_controller_op(ofs, &ofpacts); - ofpacts.header = oc; - oc->userdata_len = ofpacts.size - (sizeof *oc); - ofpact_finish_CONTROLLER(&ofpacts, &oc); put_resubmit(OFTABLE_LOG_INGRESS_PIPELINE, &ofpacts); ofctrl_add_flow(flow_table, OFTABLE_PHY_TO_LOG, 1010, diff --git a/include/ovn/actions.h b/include/ovn/actions.h index 33c319f1c..cbcf4130c 100644 --- a/include/ovn/actions.h +++ b/include/ovn/actions.h @@ -829,4 +829,8 @@ void ovnacts_free(struct ovnact[], size_t ovnacts_len); char *ovnact_op_to_string(uint32_t); int encode_ra_dnssl_opt(char *data, char *buf, int buf_len); +size_t encode_start_controller_op(enum action_opcode opcode, bool pause, + uint32_t meter_id, struct ofpbuf *ofpacts); +void encode_finish_controller_op(size_t ofs, struct ofpbuf *ofpacts); + #endif /* ovn/actions.h */ diff --git a/lib/actions.c b/lib/actions.c index aab044306..5c70ef411 100644 --- a/lib/actions.c +++ b/lib/actions.c @@ -78,7 +78,7 @@ ovnact_init(struct ovnact *ovnact, enum ovnact_type type, size_t len) ovnact->len = len; } -static size_t +size_t encode_start_controller_op(enum action_opcode opcode, bool pause, uint32_t meter_id, struct ofpbuf *ofpacts) { @@ -99,7 +99,7 @@ encode_start_controller_op(enum action_opcode opcode, bool pause, return ofs; } -static void +void encode_finish_controller_op(size_t ofs, struct ofpbuf *ofpacts) { struct ofpact_controller *oc = ofpbuf_at_assert(ofpacts, ofs, sizeof *oc);