From patchwork Wed Jun 19 12:45:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Pattrick X-Patchwork-Id: 1949677 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=K4ZZaBmB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W43J46D5dz20XW for ; Wed, 19 Jun 2024 22:45:40 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 4D015610FF; Wed, 19 Jun 2024 12:45:39 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id W46l5sMzESI9; Wed, 19 Jun 2024 12:45:38 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 482D46068F 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=K4ZZaBmB Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id 482D46068F; Wed, 19 Jun 2024 12:45:38 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1E95CC0012; Wed, 19 Jun 2024 12:45:38 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 38E0FC0011 for ; Wed, 19 Jun 2024 12:45:36 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 27B644047C for ; Wed, 19 Jun 2024 12:45:36 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 7clTMYpnLqyz for ; Wed, 19 Jun 2024 12:45:35 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=mkp@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp2.osuosl.org 2560940383 Authentication-Results: smtp2.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 2560940383 Authentication-Results: smtp2.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=K4ZZaBmB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp2.osuosl.org (Postfix) with ESMTPS id 2560940383 for ; Wed, 19 Jun 2024 12:45:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718801134; 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=1DdQAQhnlKZTPUg74E3bYpt4m4NhxVtlATayjGNlb/g=; b=K4ZZaBmBcIPK0NKu57VHYYbsYTmjyucr8NsFI8FA1o7DP4sM6i/0jMtnIidAky9yY9PMyd 61+w2gjhFC3p09jqW+6G8zXVbQd+O+ETIfoN3ZpzdjOnWFY2nol5FsoDvoFSN+G0XgU1bT sDx4Ig3NKMxMX9M9jL1+uzRwtCHMZW0= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-570-pk6HT464NqSzzMY10nmVsw-1; Wed, 19 Jun 2024 08:45:32 -0400 X-MC-Unique: pk6HT464NqSzzMY10nmVsw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9297A1954211 for ; Wed, 19 Jun 2024 12:45:31 +0000 (UTC) Received: from mpattric.remote.csb (unknown [10.22.8.8]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 657DD3000218; Wed, 19 Jun 2024 12:45:30 +0000 (UTC) From: Mike Pattrick To: dev@openvswitch.org Date: Wed, 19 Jun 2024 08:45:26 -0400 Message-Id: <20240619124526.328429-1-mkp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v2] ofp-prop: Fix unaligned 128 bit access. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" When compiling with '-fsanitize=address,undefined', the "ovs-ofctl ct-flush" test will yield the following undefined behavior flagged by UBSan. This problem is caused by the fact that 128bit property put/parse functions weren't adding appropriate padding before writing or reading the value. This patch uses get_32aligned_* functions to copy the bytes as they are aligned. lib/ofp-prop.c:277:14: runtime error: load of misaligned address 0x60600000687c for type 'union ovs_be128', which requires 8 byte alignment 0x60600000687c: note: pointer points here 00 05 00 14 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ab 00 ^ 0: in ofpprop_parse_u128 lib/ofp-prop.c:277 1: in ofp_ct_match_decode lib/ofp-ct.c:525 2: in ofp_print_nxt_ct_flush lib/ofp-print.c:959 3: in ofp_to_string__ lib/ofp-print.c:1206 4: in ofp_to_string lib/ofp-print.c:1264 5: in ofp_print lib/ofp-print.c:1308 6: in ofctl_ofp_print utilities/ovs-ofctl.c:4899 7: in ovs_cmdl_run_command__ lib/command-line.c:247 8: in ovs_cmdl_run_command lib/command-line.c:278 9: in main utilities/ovs-ofctl.c:186 Signed-off-by: Mike Pattrick --- v2: removed memcpy --- lib/ofp-prop.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/ofp-prop.c b/lib/ofp-prop.c index 0a685750c..842ecebea 100644 --- a/lib/ofp-prop.c +++ b/lib/ofp-prop.c @@ -21,6 +21,7 @@ #include "openvswitch/ofp-errors.h" #include "openvswitch/ofp-prop.h" #include "openvswitch/vlog.h" +#include "unaligned.h" #include "util.h" #include "uuid.h" @@ -190,11 +191,12 @@ ofpprop_parse_be64(const struct ofpbuf *property, ovs_be64 *value) enum ofperr ofpprop_parse_be128(const struct ofpbuf *property, ovs_be128 *value) { - ovs_be128 *p = property->msg; + ovs_32aligned_be128 *p = property->msg; + if (ofpbuf_msgsize(property) != sizeof *p) { return OFPERR_OFPBPC_BAD_LEN; } - *value = *p; + *value = get_32aligned_be128(p); return 0; } @@ -270,12 +272,13 @@ ofpprop_parse_u64(const struct ofpbuf *property, uint64_t *value) enum ofperr ofpprop_parse_u128(const struct ofpbuf *property, ovs_u128 *value) { - ovs_be128 *p = property->msg; - if (ofpbuf_msgsize(property) != sizeof *p) { - return OFPERR_OFPBPC_BAD_LEN; + enum ofperr error = ofpprop_parse_be128(property, (ovs_be128 *)value); + + if (!error) { + *value = ntoh128(*(ovs_be128 *)value); } - *value = ntoh128(*p); - return 0; + + return error; } /* Attempts to parse 'property' as a property containing a UUID. If