From patchwork Fri Dec 17 13:16:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1570016 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=UpK5biek; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JFqJb4fBWz9t6S for ; Sat, 18 Dec 2021 00:17:03 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 36EF083E68; Fri, 17 Dec 2021 13:17:01 +0000 (UTC) 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 M1hbAunt940X; Fri, 17 Dec 2021 13:17:00 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 839F283E60; Fri, 17 Dec 2021 13:16:59 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5D649C002F; Fri, 17 Dec 2021 13:16:59 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id CEFD3C0012 for ; Fri, 17 Dec 2021 13:16:58 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id B0955415E7 for ; Fri, 17 Dec 2021 13:16:58 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp4.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CgBlL1WP-_mH for ; Fri, 17 Dec 2021 13:16:58 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp4.osuosl.org (Postfix) with ESMTPS id 231FC41548 for ; Fri, 17 Dec 2021 13:16:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639747017; 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: in-reply-to:in-reply-to:references:references; bh=YDj67n0n+8tJ2dBhJVO2ChgHyZW1U2XOeIPJai/h3xU=; b=UpK5biekUoxgsnnA4pBJog7VlJ23570qU5yY5afZAwuswLz3341nGWANeNsokUE+FU+ItH 59LfoWZ3y3UGjQO6PrBGFtIhMGlhmRgNBipJYQCx2k7z8UFXld1+YZZTl3bGh2GV7Sg5l1 C34kcng6bwm+N6h8B9XQNlZ4mDcUVlE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-213-rpvDOCQWN8y4J0afdNVBUw-1; Fri, 17 Dec 2021 08:16:54 -0500 X-MC-Unique: rpvDOCQWN8y4J0afdNVBUw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 044CA801B0F; Fri, 17 Dec 2021 13:16:53 +0000 (UTC) Received: from dceara.remote.csb (unknown [10.39.193.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FD89610A7; Fri, 17 Dec 2021 13:16:51 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Fri, 17 Dec 2021 14:16:48 +0100 Message-Id: <20211217131646.30994.85869.stgit@dceara.remote.csb> In-Reply-To: <20211217131623.30994.63519.stgit@dceara.remote.csb> References: <20211217131623.30994.63519.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dceara@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 01/11] util: Avoid false positive UB when iterating collections. 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" UB Sanitizer was flagging OBJECT_CONTAINING() as undefined behavior due to the way it's used when iterating through collections, e.g., HMAP_FOR_EACH_INIT(). However, in such cases we don't actually dereference the pointer, we just use its value. Avoid the undefined behavior by casting to 'void *' first. Signed-off-by: Dumitru Ceara --- include/openvswitch/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h index 228b185c3a5f..cfbd5f1a3375 100644 --- a/include/openvswitch/util.h +++ b/include/openvswitch/util.h @@ -128,7 +128,7 @@ OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char *); * from the type of '*OBJECT'. */ #define OBJECT_CONTAINING(POINTER, OBJECT, MEMBER) \ ((OVS_TYPEOF(OBJECT)) (void *) \ - ((char *) (POINTER) - OBJECT_OFFSETOF(OBJECT, MEMBER))) + ((uintptr_t)(void *)(POINTER) - OBJECT_OFFSETOF(OBJECT, MEMBER))) /* Given POINTER, the address of the given MEMBER within an object of the type * that that OBJECT points to, assigns the address of the outer object to From patchwork Fri Dec 17 13:16:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1570017 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=iA9ewL/J; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JFqJy5hYWz9t6S for ; Sat, 18 Dec 2021 00:17:22 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id BF4BE41D61; Fri, 17 Dec 2021 13:17:19 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id I2GcOwISPouF; Fri, 17 Dec 2021 13:17:18 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id D52FF41642; Fri, 17 Dec 2021 13:17:17 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id B9F05C002F; Fri, 17 Dec 2021 13:17:17 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 535C9C0012 for ; Fri, 17 Dec 2021 13:17:16 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 0D310610BC for ; Fri, 17 Dec 2021 13:17:10 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com 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 2_ux1nPleju1 for ; Fri, 17 Dec 2021 13:17:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id 4F23E610C0 for ; Fri, 17 Dec 2021 13:17:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639747028; 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: in-reply-to:in-reply-to:references:references; bh=vZ4L0YHC9yUcf6ja+Qe7dYxXCk/h1UZ5PuJh2/jlHW0=; b=iA9ewL/J3QYh9OIWM/80AgQh2yUxfuwi6Pg+ftMyuppYUrZ6tHXnUzRPG2pJ6sGMAfXXQA yHPa5uYoHrXNTeNCEmogUv3gNzCy0Ht6Rub5Dp35Rtww6y8OLCn+J1Uhnu5DODcduYtpLQ XvUnRFw7akfJsW9XY16daQXIRFLrVhE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-651-26m4iCtBO2yNFfIHrvP0Fg-1; Fri, 17 Dec 2021 08:17:05 -0500 X-MC-Unique: 26m4iCtBO2yNFfIHrvP0Fg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4E84F8DD876; Fri, 17 Dec 2021 13:17:04 +0000 (UTC) Received: from dceara.remote.csb (unknown [10.39.193.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id 663CD45D8A; Fri, 17 Dec 2021 13:17:03 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Fri, 17 Dec 2021 14:16:59 +0100 Message-Id: <20211217131658.30994.78806.stgit@dceara.remote.csb> In-Reply-To: <20211217131623.30994.63519.stgit@dceara.remote.csb> References: <20211217131623.30994.63519.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dceara@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 02/11] treewide: Don't pass NULL to library functions that expect non-NULL. 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" It's actually undefined behavior to pass NULL to standard library functions that manipulate arrays (e.g., qsort, memcpy, memcmp), even if the passed number of items is 0. UB Sanitizer reports: ovsdb/monitor.c:408:9: runtime error: null pointer passed as argument 1, which is declared to never be null #0 0x406ae1 in ovsdb_monitor_columns_sort ovsdb/monitor.c:408 #1 0x406ae1 in ovsdb_monitor_add ovsdb/monitor.c:1683 [...] lib/ovsdb-data.c:1970:5: runtime error: null pointer passed as argument 2, which is declared to never be null #0 0x4071c8 in ovsdb_datum_push_unsafe lib/ovsdb-data.c:1970 #1 0x471cd0 in ovsdb_datum_apply_diff_in_place lib/ovsdb-data.c:2345 [...] ofproto/ofproto-dpif-rid.c:159:17: runtime error: null pointer passed as argument 1, which is declared to never be null #0 0x4df5d8 in frozen_state_equal ofproto/ofproto-dpif-rid.c:159 #1 0x4dfd27 in recirc_find_equal ofproto/ofproto-dpif-rid.c:179 [...] Signed-off-by: Dumitru Ceara --- lib/dpif-netdev.c | 4 +++- lib/ofp-actions.c | 2 +- lib/ofpbuf.c | 4 ++++ lib/ovsdb-data.c | 4 ++++ ofproto/ofproto-dpif-rid.c | 6 ++++-- ovsdb/monitor.c | 4 ++++ 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index a790df5fd697..f62202a8b53d 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -4506,8 +4506,10 @@ dp_netdev_actions_create(const struct nlattr *actions, size_t size) struct dp_netdev_actions *netdev_actions; netdev_actions = xmalloc(sizeof *netdev_actions + size); - memcpy(netdev_actions->actions, actions, size); netdev_actions->size = size; + if (size) { + memcpy(netdev_actions->actions, actions, size); + } return netdev_actions; } diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c index ecf914eac10b..f21b3c579f2b 100644 --- a/lib/ofp-actions.c +++ b/lib/ofp-actions.c @@ -9147,7 +9147,7 @@ bool ofpacts_equal(const struct ofpact *a, size_t a_len, const struct ofpact *b, size_t b_len) { - return a_len == b_len && !memcmp(a, b, a_len); + return a_len == b_len && (!a_len || !memcmp(a, b, a_len)); } /* Returns true if the 'a_len' bytes of actions in 'a' and the 'b_len' bytes of diff --git a/lib/ofpbuf.c b/lib/ofpbuf.c index 4edb3c114ae6..271105bdea17 100644 --- a/lib/ofpbuf.c +++ b/lib/ofpbuf.c @@ -384,6 +384,10 @@ ofpbuf_put_zeros(struct ofpbuf *b, size_t size) void * ofpbuf_put(struct ofpbuf *b, const void *p, size_t size) { + if (!size) { + return ofpbuf_tail(b); + } + void *dst = ofpbuf_put_uninit(b, size); memcpy(dst, p, size); return dst; diff --git a/lib/ovsdb-data.c b/lib/ovsdb-data.c index 2832e94ea04a..6b1c20ff85a0 100644 --- a/lib/ovsdb-data.c +++ b/lib/ovsdb-data.c @@ -1967,6 +1967,10 @@ ovsdb_datum_push_unsafe(struct ovsdb_datum *dst, unsigned int start_idx, unsigned int n, const struct ovsdb_type *type) { + if (n == 0) { + return; + } + memcpy(&dst->keys[dst->n], &src->keys[start_idx], n * sizeof src->keys[0]); if (type->value.type != OVSDB_TYPE_VOID) { memcpy(&dst->values[dst->n], &src->values[start_idx], diff --git a/ofproto/ofproto-dpif-rid.c b/ofproto/ofproto-dpif-rid.c index 29aafc2c0b40..f01468025c03 100644 --- a/ofproto/ofproto-dpif-rid.c +++ b/ofproto/ofproto-dpif-rid.c @@ -156,7 +156,7 @@ frozen_state_equal(const struct frozen_state *a, const struct frozen_state *b) && uuid_equals(&a->ofproto_uuid, &b->ofproto_uuid) && !memcmp(&a->metadata, &b->metadata, sizeof a->metadata) && a->stack_size == b->stack_size - && !memcmp(a->stack, b->stack, a->stack_size) + && (!a->stack_size || !memcmp(a->stack, b->stack, a->stack_size)) && a->mirrors == b->mirrors && a->conntracked == b->conntracked && a->was_mpls == b->was_mpls @@ -164,7 +164,9 @@ frozen_state_equal(const struct frozen_state *a, const struct frozen_state *b) b->ofpacts, b->ofpacts_len) && ofpacts_equal(a->action_set, a->action_set_len, b->action_set, b->action_set_len) - && !memcmp(a->userdata, b->userdata, a->userdata_len) + && a->userdata_len == b->userdata_len + && (!a->userdata_len + || !memcmp(a->userdata, b->userdata, a->userdata_len)) && uuid_equals(&a->xport_uuid, &b->xport_uuid)); } diff --git a/ovsdb/monitor.c b/ovsdb/monitor.c index ab814cf20e26..0f222cc99284 100644 --- a/ovsdb/monitor.c +++ b/ovsdb/monitor.c @@ -405,6 +405,10 @@ ovsdb_monitor_columns_sort(struct ovsdb_monitor *dbmon) SHASH_FOR_EACH (node, &dbmon->tables) { struct ovsdb_monitor_table *mt = node->data; + if (mt->n_columns == 0) { + continue; + } + qsort(mt->columns, mt->n_columns, sizeof *mt->columns, compare_ovsdb_monitor_column); for (i = 0; i < mt->n_columns; i++) { From patchwork Fri Dec 17 13:17:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1570018 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=LgWFyID3; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JFqKC1NvMz9t6S for ; Sat, 18 Dec 2021 00:17:35 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id A22D841D76; Fri, 17 Dec 2021 13:17:32 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9znn_TItmnAO; Fri, 17 Dec 2021 13:17:31 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id DEC7F41D44; Fri, 17 Dec 2021 13:17:30 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A60C8C002F; Fri, 17 Dec 2021 13:17:30 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2EA10C002F for ; Fri, 17 Dec 2021 13:17:30 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 3A99D41D44 for ; Fri, 17 Dec 2021 13:17:22 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7UEjoQhaITYK for ; Fri, 17 Dec 2021 13:17:21 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp4.osuosl.org (Postfix) with ESMTPS id 8392D41D72 for ; Fri, 17 Dec 2021 13:17:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639747040; 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: in-reply-to:in-reply-to:references:references; bh=r8sJDDIZj/6RdKH5D3+kNl1koqBJNFuy/mYxdUC5kcc=; b=LgWFyID3aQ9HsJVWvbMXQ6b0d+6cuDzRVK3pDVdrONDZt9bQwyLNjHUK6jnfIkESFWr7Vr JkJtIuINvglOy9yPbf5sIkeJLJ2Tus1oUQO7JUNHxBpC5UjwoDEriy2GCwRYmWm1ck3r2l tCmQ90+yUJTAyNJJ2Rt1gQtKhf9vG9g= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-633-Sk-fXryTO9OuHrxirV-pjg-1; Fri, 17 Dec 2021 08:17:17 -0500 X-MC-Unique: Sk-fXryTO9OuHrxirV-pjg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4FFDA2F41; Fri, 17 Dec 2021 13:17:16 +0000 (UTC) Received: from dceara.remote.csb (unknown [10.39.193.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A9641948C; Fri, 17 Dec 2021 13:17:14 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Fri, 17 Dec 2021 14:17:11 +0100 Message-Id: <20211217131709.30994.5953.stgit@dceara.remote.csb> In-Reply-To: <20211217131623.30994.63519.stgit@dceara.remote.csb> References: <20211217131623.30994.63519.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dceara@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 03/11] dpif-netdev: Fix misaligned access. 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" UB Sanitizer report: lib/dpif-netdev.c:6758:13: runtime error: member access within misaligned address 0x7f7f24d25010 for type 'struct dp_netdev_pmd_thread', which requires 64 byte alignment 0x7f7f24d25010: note: pointer points here 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ #0 0x5fbfde in dp_netdev_configure_pmd lib/dpif-netdev.c:6758 #1 0x5fbde9 in dp_netdev_set_nonpmd lib/dpif-netdev.c:6715 #2 0x5d6fdd in create_dp_netdev lib/dpif-netdev.c:1769 #3 0x5d72d0 in dpif_netdev_open lib/dpif-netdev.c:1807 #4 0x61c83f in do_open lib/dpif.c:347 [...] lib/dpif-netdev.c:1724:6: runtime error: member access within misaligned address 0x000002005eb0 for type 'struct dp_netdev', which requires 64 byte alignment 0x000002005eb0: note: pointer points here 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ #0 0x5d6660 in create_dp_netdev lib/dpif-netdev.c:1724 #1 0x5d72d0 in dpif_netdev_open lib/dpif-netdev.c:1807 #2 0x61c846 in do_open lib/dpif.c:347 #3 0x61ca9c in dpif_create lib/dpif.c:402 #4 0x61cac9 in dpif_create_and_open lib/dpif.c:415 #5 0x48f235 in open_dpif_backer ofproto/ofproto-dpif.c:776 [...] Signed-off-by: Dumitru Ceara --- lib/dpif-netdev.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index f62202a8b53d..25d8a3ff2009 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -1718,7 +1718,7 @@ create_dp_netdev(const char *name, const struct dpif_class *class, ovsthread_once_done(&tsc_freq_check); } - dp = xzalloc(sizeof *dp); + dp = xzalloc_cacheline(sizeof *dp); shash_add(&dp_netdevs, name, dp); *CONST_CAST(const struct dpif_class **, &dp->class) = class; @@ -1888,7 +1888,7 @@ dp_netdev_free(struct dp_netdev *dp) free(dp->pmd_cmask); free(CONST_CAST(char *, dp->name)); - free(dp); + free_cacheline(dp); } static void @@ -5672,7 +5672,7 @@ reconfigure_pmd_threads(struct dp_netdev *dp) if (!pmd) { struct ds name = DS_EMPTY_INITIALIZER; - pmd = xzalloc(sizeof *pmd); + pmd = xzalloc_cacheline(sizeof *pmd); dp_netdev_configure_pmd(pmd, dp, core->core_id, core->numa_id); ds_put_format(&name, "pmd-c%02d/id:", core->core_id); @@ -6713,7 +6713,7 @@ dp_netdev_set_nonpmd(struct dp_netdev *dp) { struct dp_netdev_pmd_thread *non_pmd; - non_pmd = xzalloc(sizeof *non_pmd); + non_pmd = xzalloc_cacheline(sizeof *non_pmd); dp_netdev_configure_pmd(non_pmd, dp, NON_PMD_CORE_ID, OVS_NUMA_UNSPEC); } @@ -6830,7 +6830,7 @@ dp_netdev_destroy_pmd(struct dp_netdev_pmd_thread *pmd) seq_destroy(pmd->reload_seq); ovs_mutex_destroy(&pmd->port_mutex); ovs_mutex_destroy(&pmd->bond_mutex); - free(pmd); + free_cacheline(pmd); } /* Stops the pmd thread, removes it from the 'dp->poll_threads', From patchwork Fri Dec 17 13:17:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1570019 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=VhJczXM6; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JFqKP0zynz9t6S for ; Sat, 18 Dec 2021 00:17:44 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 9228883E5F; Fri, 17 Dec 2021 13:17:42 +0000 (UTC) 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 2XnDxGUc3L81; Fri, 17 Dec 2021 13:17:41 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id C689384BFE; Fri, 17 Dec 2021 13:17:40 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A5B7BC002F; Fri, 17 Dec 2021 13:17:40 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3846EC002F for ; Fri, 17 Dec 2021 13:17:39 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 7352284BF4 for ; Fri, 17 Dec 2021 13:17:31 +0000 (UTC) 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 9ZQLaPnmOq58 for ; Fri, 17 Dec 2021 13:17:31 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id D953784BF0 for ; Fri, 17 Dec 2021 13:17:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639747049; 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: in-reply-to:in-reply-to:references:references; bh=X46z+kV9ug1/ri8S3KZ7AMg7xTz9cTvnBcnpcDjzPes=; b=VhJczXM6RVr1WhljVmfL2yqNeQx2Ci3Pwutjo6PUI/Ulel55jFj2nsUfzDAV/d5S+aoYxq qY2bx9f6aQLuxQ48x7w2qJa4TQC+rZsXn0xN1h6VPJpD0WJnyxejW6MKDp041LOZ9cTjIa rPAxmIu2sEV4k9OnsvP6OQzWYNKE4eE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-665-u_JIZgKsOtimhsMKawTrwA-1; Fri, 17 Dec 2021 08:17:28 -0500 X-MC-Unique: u_JIZgKsOtimhsMKawTrwA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6E8C710247A7; Fri, 17 Dec 2021 13:17:27 +0000 (UTC) Received: from dceara.remote.csb (unknown [10.39.193.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFB904E2BF; Fri, 17 Dec 2021 13:17:25 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Fri, 17 Dec 2021 14:17:23 +0100 Message-Id: <20211217131721.30994.23948.stgit@dceara.remote.csb> In-Reply-To: <20211217131623.30994.63519.stgit@dceara.remote.csb> References: <20211217131623.30994.63519.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dceara@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 04/11] stopwatch: Fix buffer underflow when computing percentiles. 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" UB Sanitizer report: lib/stopwatch.c:119:22: runtime error: index 18446744073709551615 out of bounds for type 'long long unsigned int [50]' #0 0x698358 in calc_percentile lib/stopwatch.c:119 #1 0x69ada1 in add_sample lib/stopwatch.c:231 #2 0x69c086 in stopwatch_end_sample_protected lib/stopwatch.c:386 #3 0x69c522 in stopwatch_thread lib/stopwatch.c:441 #4 0x684bae in ovsthread_wrapper lib/ovs-thread.c:383 #5 0x7f042838b298 in start_thread (/lib64/libpthread.so.0+0x9298) #6 0x7f04277f2352 in clone (/lib64/libc.so.6+0x100352) Signed-off-by: Dumitru Ceara --- lib/stopwatch.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/stopwatch.c b/lib/stopwatch.c index f5602163bc16..1c71df1a127e 100644 --- a/lib/stopwatch.c +++ b/lib/stopwatch.c @@ -114,7 +114,6 @@ static void calc_percentile(unsigned long long n_samples, struct percentile *pctl, unsigned long long new_sample) { - if (n_samples < P_SQUARE_MIN) { pctl->samples[n_samples - 1] = new_sample; } @@ -228,13 +227,12 @@ add_sample(struct stopwatch *sw, unsigned long long new_sample) sw->min = new_sample; } - calc_percentile(sw->n_samples, &sw->pctl, new_sample); - if (sw->n_samples++ == 0) { sw->short_term.average = sw->long_term.average = new_sample; return; } + calc_percentile(sw->n_samples, &sw->pctl, new_sample); calc_average(&sw->short_term, new_sample); calc_average(&sw->long_term, new_sample); } From patchwork Fri Dec 17 13:17:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1570020 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=L8J8iIqy; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JFqKp1YBlz9t6S for ; Sat, 18 Dec 2021 00:18:05 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 83DFB40BB0; Fri, 17 Dec 2021 13:18:03 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uhNejLBG810n; Fri, 17 Dec 2021 13:18:02 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id 1039440BCF; Fri, 17 Dec 2021 13:18:01 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E7E01C002F; Fri, 17 Dec 2021 13:18:00 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6DC33C0012 for ; Fri, 17 Dec 2021 13:17:59 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 4FFBD84BF0 for ; Fri, 17 Dec 2021 13:17:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com 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 97JI1yc3GoXV for ; Fri, 17 Dec 2021 13:17:42 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 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 9613484BEA for ; Fri, 17 Dec 2021 13:17:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639747061; 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: in-reply-to:in-reply-to:references:references; bh=iXK5aMS3SfzdryWpEGCfmBgqloFZRmopfMPOJ84Aruw=; b=L8J8iIqyaThMbxbQ/LzsGYtBrsTSEhf4Rdn5YpnNUUvaZcRCQ7gGRkDDjGJsIF1pHn8Cxx Hh1ksdHdtB25pMzJ7XMWXy8oRlLFbNxgzueF6t88eYnPEL7BHgMu47cJCpMgmeFR7esFz5 bj2eVLH8ls52ceyJQ1Z5WzOEo9PHJ58= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-86-p0hMEAoDPmWsjFPgYGQ_9A-1; Fri, 17 Dec 2021 08:17:40 -0500 X-MC-Unique: p0hMEAoDPmWsjFPgYGQ_9A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 74D8F801962; Fri, 17 Dec 2021 13:17:39 +0000 (UTC) Received: from dceara.remote.csb (unknown [10.39.193.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D5D91948C; Fri, 17 Dec 2021 13:17:38 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Fri, 17 Dec 2021 14:17:35 +0100 Message-Id: <20211217131732.30994.825.stgit@dceara.remote.csb> In-Reply-To: <20211217131623.30994.63519.stgit@dceara.remote.csb> References: <20211217131623.30994.63519.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dceara@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 05/11] treewide: Fix invalid bit shift operations. 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" UB Sanitizer reports: tests/test-hash.c:59:40: runtime error: shift exponent 64 is too large for 64-bit type 'long unsigned int' #0 0x44c3c9 in get_range128 tests/test-hash.c:59 #1 0x44cb2e in check_hash_bytes128 tests/test-hash.c:178 #2 0x44d14d in test_hash_main tests/test-hash.c:282 [...] ofproto/ofproto-dpif-xlate.c:5607:45: runtime error: left shift of 65535 by 16 places cannot be represented in type 'int' #0 0x53fe9f in xlate_sample_action ofproto/ofproto-dpif-xlate.c:5607 #1 0x54d625 in do_xlate_actions ofproto/ofproto-dpif-xlate.c:7160 #2 0x553b76 in xlate_actions ofproto/ofproto-dpif-xlate.c:7806 #3 0x4fcb49 in upcall_xlate ofproto/ofproto-dpif-upcall.c:1237 #4 0x4fe02f in process_upcall ofproto/ofproto-dpif-upcall.c:1456 #5 0x4fda99 in upcall_cb ofproto/ofproto-dpif-upcall.c:1358 [...] tests/test-util.c:89:23: runtime error: left shift of 1 by 31 places cannot be represented in type 'int' #0 0x476415 in test_ctz tests/test-util.c:89 [...] lib/dpif-netlink.c:396:33: runtime error: left shift of 1 by 31 places cannot be represented in type 'int' #0 0x571b9f in dpif_netlink_open lib/dpif-netlink.c:396 Signed-off-by: Dumitru Ceara --- lib/dpif-netlink.c | 2 +- ofproto/ofproto-dpif-xlate.c | 3 ++- tests/test-hash.c | 2 +- tests/test-util.c | 13 ++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 424a28401901..8bd975225aa2 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -84,7 +84,7 @@ enum { MAX_PORTS = USHRT_MAX }; #define EPOLLEXCLUSIVE (1u << 28) #endif -#define OVS_DP_F_UNSUPPORTED (1 << 31); +#define OVS_DP_F_UNSUPPORTED (1u << 31); /* This PID is not used by the kernel datapath when using dispatch per CPU, * but it is required to be set (not zero). */ diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index f8146663ad95..d4d42db72128 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -5604,7 +5604,8 @@ xlate_sample_action(struct xlate_ctx *ctx, /* Scale the probability from 16-bit to 32-bit while representing * the same percentage. */ - uint32_t probability = (os->probability << 16) | os->probability; + uint32_t probability = + ((uint32_t) os->probability << 16) | os->probability; /* If ofp_port in flow sample action is equel to ofp_port, * this sample action is a input port action. */ diff --git a/tests/test-hash.c b/tests/test-hash.c index 5d3f8ea43f65..7c33922e3f02 100644 --- a/tests/test-hash.c +++ b/tests/test-hash.c @@ -174,7 +174,7 @@ check_hash_bytes128(void (*hash)(const void *, size_t, uint32_t, ovs_u128 *), set_bit128(&in2, j, n_bits); hash(&in2, sizeof(ovs_u128), 0, &out2); - for (ofs = 0; ofs < 128 - min_unique; ofs++) { + for (ofs = 1; ofs < 128 - min_unique; ofs++) { uint64_t bits1 = get_range128(&out1, ofs, unique_mask); uint64_t bits2 = get_range128(&out2, ofs, unique_mask); diff --git a/tests/test-util.c b/tests/test-util.c index f0fd0421086b..7d899fbbfd92 100644 --- a/tests/test-util.c +++ b/tests/test-util.c @@ -43,17 +43,16 @@ check_log_2_floor(uint32_t x, int n) static void test_log_2_floor(struct ovs_cmdl_context *ctx OVS_UNUSED) { - int n; - - for (n = 0; n < 32; n++) { + for (uint32_t n = 0; n < 32; n++) { /* Check minimum x such that f(x) == n. */ - check_log_2_floor(1 << n, n); + check_log_2_floor(UINT32_C(1) << n, n); /* Check maximum x such that f(x) == n. */ - check_log_2_floor((1 << n) | ((1 << n) - 1), n); + check_log_2_floor((UINT32_C(1) << n) | ((UINT32_C(1) << n) - 1), n); /* Check a random value in the middle. */ - check_log_2_floor((random_uint32() & ((1 << n) - 1)) | (1 << n), n); + check_log_2_floor((random_uint32() & ((UINT32_C(1) << n) - 1)) + | (UINT32_C(1) << n), n); } /* log_2_floor(0) is undefined, so don't check it. */ @@ -86,7 +85,7 @@ test_ctz(struct ovs_cmdl_context *ctx OVS_UNUSED) for (n = 0; n < 32; n++) { /* Check minimum x such that f(x) == n. */ - check_ctz32(1 << n, n); + check_ctz32(UINT32_C(1) << n, n); /* Check maximum x such that f(x) == n. */ check_ctz32(UINT32_MAX << n, n); From patchwork Fri Dec 17 13:17:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1570021 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=UtD7+0Gl; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JFqL7722cz9t6S for ; Sat, 18 Dec 2021 00:18:23 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 8BDAB41D65; Fri, 17 Dec 2021 13:18:21 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QuPkrYgu10JV; Fri, 17 Dec 2021 13:18:20 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id D9B74416F5; Fri, 17 Dec 2021 13:18:19 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 9ACC8C0039; Fri, 17 Dec 2021 13:18:19 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 717E5C002F for ; Fri, 17 Dec 2021 13:18:18 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 28D1183E62 for ; Fri, 17 Dec 2021 13:17:56 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com 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 k9jo6roHEfqT for ; Fri, 17 Dec 2021 13:17:55 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id 8001684BEC for ; Fri, 17 Dec 2021 13:17:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639747074; 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: in-reply-to:in-reply-to:references:references; bh=VAsTIQYYpCtL/sGxDi0uCKUKi9rmbYYckZUIOsIAWBs=; b=UtD7+0GlZp0diuKqO28wAq2toWxhB46okkgEskeC0HhJMMX5h0eBMSPOXDNC7ybjKdg/px Ggtndvt4j+7Qet2ejG5u76uauZLQ3o9sorwT83369RW/Gv3rhO2fcptSF8e1tncvBxI5/l J+QWnGnHdKsqj1PWV3i0uWxICAtp+g8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-629-Jr3J7RYcNgCdksc6gtdGeQ-1; Fri, 17 Dec 2021 08:17:53 -0500 X-MC-Unique: Jr3J7RYcNgCdksc6gtdGeQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5AE6F801962; Fri, 17 Dec 2021 13:17:52 +0000 (UTC) Received: from dceara.remote.csb (unknown [10.39.193.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F8F660BD8; Fri, 17 Dec 2021 13:17:49 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Fri, 17 Dec 2021 14:17:46 +0100 Message-Id: <20211217131744.30994.82325.stgit@dceara.remote.csb> In-Reply-To: <20211217131623.30994.63519.stgit@dceara.remote.csb> References: <20211217131623.30994.63519.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dceara@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 06/11] ovsdb-idlc: Avoid accessing member within NULL idl index cursors. 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" Reported by UndefinedBehaviorSanitizer: tests/idltest.c:3602:12: runtime error: member access within null pointer of type 'const struct idltest_simple' #0 0x4295af in idltest_simple_cursor_first_ge tests/idltest.c:3602 #1 0x41c81b in test_idl_compound_index_single_column tests/test-ovsdb.c:3128 #2 0x41e035 in do_idl_compound_index tests/test-ovsdb.c:3277 #3 0x4cf640 in ovs_cmdl_run_command__ lib/command-line.c:247 #4 0x4cf79f in ovs_cmdl_run_command lib/command-line.c:278 #5 0x4072f7 in main tests/test-ovsdb.c:79 #6 0x7fa858675b74 in __libc_start_main (/lib64/libc.so.6+0x27b74) #7 0x4060ed in _start (/root/ovs/tests/test-ovsdb+0x4060ed) Signed-off-by: Dumitru Ceara --- ovsdb/ovsdb-idlc.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in index 5a02c8f936a0..10a70ae26f96 100755 --- a/ovsdb/ovsdb-idlc.in +++ b/ovsdb/ovsdb-idlc.in @@ -1292,7 +1292,7 @@ struct ovsdb_idl_cursor struct ovsdb_idl_index *index, const struct %(s)s *target) { ovs_assert(index->table->class_ == &%(p)stable_%(tl)s); - return ovsdb_idl_cursor_first_ge(index, &target->header_); + return ovsdb_idl_cursor_first_ge(index, target ? &target->header_ : NULL); } struct %(s)s * From patchwork Fri Dec 17 13:18:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1570023 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=W+uZWLYH; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JFqLs2dm7z9t6S for ; Sat, 18 Dec 2021 00:19:01 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 0DFDA41D9B; Fri, 17 Dec 2021 13:18:59 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oqHv6OWX5E6T; Fri, 17 Dec 2021 13:18:57 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id E0273415F7; Fri, 17 Dec 2021 13:18:56 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id C5087C002F; Fri, 17 Dec 2021 13:18:56 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3D4DFC0012 for ; Fri, 17 Dec 2021 13:18:56 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 88C9C610D0 for ; Fri, 17 Dec 2021 13:18:23 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=fail (1024-bit key) reason="fail (body has been altered)" header.d=redhat.com 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 GjFkancI4jSD for ; Fri, 17 Dec 2021 13:18:22 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id 932A5610D5 for ; Fri, 17 Dec 2021 13:18:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639747101; 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: in-reply-to:in-reply-to:references:references; bh=opBGN0ES4DryfV8O0MpN7e3nZOgALPvHATHjaf+oXMI=; b=W+uZWLYH20VG/o8HedV4fkMdWkHDWUlieuwiu7ad6fQs7/B/HtTiU5xzMWjwoVvShddsAc ZVHb3/AQAJqeESWwNPfntdSlKQkYwiyGdLregNWAbZwxCx2eZnp9oiYFkYgM2VdDP6ehHw uUPs9EY/J8bnsRKGsvoVNj6w6fQUejk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-576-gxya8mByMkyRz8N_lAqwHg-1; Fri, 17 Dec 2021 08:18:13 -0500 X-MC-Unique: gxya8mByMkyRz8N_lAqwHg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 41D591F2DC; Fri, 17 Dec 2021 13:18:12 +0000 (UTC) Received: from dceara.remote.csb (unknown [10.39.193.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id 138465DF21; Fri, 17 Dec 2021 13:18:10 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Fri, 17 Dec 2021 14:18:07 +0100 Message-Id: <20211217131759.30994.52947.stgit@dceara.remote.csb> In-Reply-To: <20211217131623.30994.63519.stgit@dceara.remote.csb> References: <20211217131623.30994.63519.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dceara@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 07/11] ofp-actions: ofp-errors: Use aligned structures when decoding ofp actions. 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" When decoding multiple actions in ofpacts_decode(), make sure that when we advance to the next action it will be properly aligned (multiple of OFPACT_ALIGNTO). If not, clone or trim the ofpbuf to ensure proper aligment. One example is parsing the OVN "eth.dst[40] = 1;" action, which triggered the following warning from UndefinedBehaviorSanitizer: lib/meta-flow.c:3210:9: runtime error: member access within misaligned address 0x000000de4e36 for type 'const union mf_value', which requires 8 byte alignment 0x000000de4e36: note: pointer points here 00 00 00 00 01 00 00 00 00 00 00 00 00 00 70 4e de 00 00 00 00 00 10 51 de 00 00 00 00 00 c0 4f ^ #0 0x5818bc in mf_format lib/meta-flow.c:3210 #1 0x5b6047 in format_SET_FIELD lib/ofp-actions.c:3342 #2 0x5d68ab in ofpact_format lib/ofp-actions.c:9213 #3 0x5d6ee0 in ofpacts_format lib/ofp-actions.c:9237 #4 0x410922 in test_parse_actions tests/test-ovn.c:1360 Another example is when running one of the fuzz tests: lib/ofp-actions.c:5347:12: runtime error: member access within misaligned address 0x0000016ba274 for type 'const struct nx_action_learn', which requires 8 byte alignment 0x0000016ba274: note: pointer points here 20 20 20 20 ff ff 00 38 00 00 23 20 00 10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 00 03 20 00 ^ #0 0x52cece in decode_LEARN_common lib/ofp-actions.c:5347 #1 0x52dcf6 in decode_NXAST_RAW_LEARN lib/ofp-actions.c:5463 #2 0x548604 in ofpact_decode lib/ofp-actions.inc2:4723 #3 0x53ee43 in ofpacts_decode lib/ofp-actions.c:7781 #4 0x53efc1 in ofpacts_pull_openflow_actions__ lib/ofp-actions.c:7820 #5 0x5409e1 in ofpacts_pull_openflow_instructions lib/ofp-actions.c:8396 #6 0x5608a8 in ofputil_decode_flow_stats_reply lib/ofp-flow.c:1100 [...] Or: lib/ofp-print.c:1218:24: runtime error: member access within misaligned address 0x0000019229d2 for type 'const struct ofp_header', which requires 4 byte alignment 0x0000019229d2: note: pointer points here 00 00 5a 5a 05 22 00 3e 00 00 00 09 00 00 00 00 00 00 00 03 05 0d 00 2e 00 00 00 09 ff ff ff ff ^ #0 0x7d45cc in ofp_to_string lib/ofp-print.c:1218 #1 0x774fa8 in ofperr_msg_format lib/ofp-errors.c:253 #2 0x7d2617 in ofp_print_error_msg lib/ofp-print.c:435 #3 0x7d3eb7 in ofp_to_string__ lib/ofp-print.c:998 #4 0x7d47fb in ofp_to_string lib/ofp-print.c:1244 #5 0x8dcc4b in do_send lib/vconn.c:688 #6 0x8dca64 in vconn_send lib/vconn.c:671 [...] Signed-off-by: Dumitru Ceara --- include/openvswitch/ofp-actions.h | 1 + include/openvswitch/util.h | 3 +++ lib/meta-flow.c | 6 +++++ lib/nx-match.c | 7 ++++++ lib/ofp-actions.c | 44 +++++++++++++++++++++++++++---------- lib/ofp-errors.c | 2 ++ ofproto/ofproto-dpif-xlate.c | 13 ++++++++--- 7 files changed, 60 insertions(+), 16 deletions(-) diff --git a/include/openvswitch/ofp-actions.h b/include/openvswitch/ofp-actions.h index 41bcb55d2056..3b67675fe02a 100644 --- a/include/openvswitch/ofp-actions.h +++ b/include/openvswitch/ofp-actions.h @@ -203,6 +203,7 @@ BUILD_ASSERT_DECL(sizeof(struct ofpact) == 4); /* Alignment. */ #define OFPACT_ALIGNTO 8 #define OFPACT_ALIGN(SIZE) ROUND_UP(SIZE, OFPACT_ALIGNTO) +#define OFPACT_IS_ALIGNED(ADDR) ((uintptr_t) (ADDR) % OFPACT_ALIGNTO == 0) #define OFPACT_PADDED_MEMBERS(MEMBERS) PADDED_MEMBERS(OFPACT_ALIGNTO, MEMBERS) /* Returns the ofpact following 'ofpact'. */ diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h index cfbd5f1a3375..9a22ed56c505 100644 --- a/include/openvswitch/util.h +++ b/include/openvswitch/util.h @@ -285,6 +285,9 @@ is_pow2(uintmax_t x) * segfault, so it is important to be aware of correct alignment. */ #define ALIGNED_CAST(TYPE, ATTR) ((TYPE) (void *) (ATTR)) +#define IS_PTR_ALIGNED(OBJ) \ + (!(OBJ) || (uintptr_t) (OBJ) % __alignof__(OVS_TYPEOF(OBJ)) == 0) + #ifdef __cplusplus } #endif diff --git a/lib/meta-flow.c b/lib/meta-flow.c index e03cd8d0c5cd..92bfd350a92b 100644 --- a/lib/meta-flow.c +++ b/lib/meta-flow.c @@ -3172,6 +3172,8 @@ mf_format(const struct mf_field *mf, const struct ofputil_port_map *port_map, struct ds *s) { + union mf_value aligned_mask; + if (mask) { if (is_all_zeros(mask, mf->n_bytes)) { ds_put_cstr(s, "ANY"); @@ -3207,6 +3209,10 @@ mf_format(const struct mf_field *mf, break; case MFS_ETHERNET: + if (!IS_PTR_ALIGNED(mask)) { + memcpy(&aligned_mask.mac, mask, sizeof aligned_mask.mac); + mask = &aligned_mask; + } eth_format_masked(value->mac, mask ? &mask->mac : NULL, s); break; diff --git a/lib/nx-match.c b/lib/nx-match.c index 440f5f7630c9..6e87deffc0d0 100644 --- a/lib/nx-match.c +++ b/lib/nx-match.c @@ -31,6 +31,7 @@ #include "openvswitch/ofp-match.h" #include "openvswitch/ofp-port.h" #include "openvswitch/ofpbuf.h" +#include "openvswitch/util.h" #include "openvswitch/vlog.h" #include "packets.h" #include "openvswitch/shash.h" @@ -1491,9 +1492,15 @@ nx_put_entry(struct ofpbuf *b, const struct mf_field *mff, enum ofp_version version, const union mf_value *value, const union mf_value *mask) { + union mf_value aligned_mask; bool masked; int len, offset; + if (!IS_PTR_ALIGNED(mask)) { + memcpy(&aligned_mask, mask, mff->n_bytes); + mask = &aligned_mask; + } + len = mf_field_len(mff, value, mask, &masked); offset = mff->n_bytes - len; diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c index f21b3c579f2b..040456ad532d 100644 --- a/lib/ofp-actions.c +++ b/lib/ofp-actions.c @@ -7749,16 +7749,15 @@ check_GOTO_TABLE(const struct ofpact_goto_table *a, static void log_bad_action(const struct ofp_action_header *actions, size_t actions_len, - const struct ofp_action_header *bad_action, enum ofperr error) + size_t bad_action_offset, enum ofperr error) { if (!VLOG_DROP_WARN(&rl)) { struct ds s; ds_init(&s); ds_put_hex_dump(&s, actions, actions_len, 0, false); - VLOG_WARN("bad action at offset %#"PRIxPTR" (%s):\n%s", - (char *)bad_action - (char *)actions, - ofperr_get_name(error), ds_cstr(&s)); + VLOG_WARN("bad action at offset %"PRIuSIZE" (%s):\n%s", + bad_action_offset, ofperr_get_name(error), ds_cstr(&s)); ds_destroy(&s); } } @@ -7769,25 +7768,46 @@ ofpacts_decode(const void *actions, size_t actions_len, const struct vl_mff_map *vl_mff_map, uint64_t *ofpacts_tlv_bitmap, struct ofpbuf *ofpacts) { - struct ofpbuf openflow = ofpbuf_const_initializer(actions, actions_len); - while (openflow.size) { - const struct ofp_action_header *action = openflow.data; + struct ofpbuf openflow_actions + = ofpbuf_const_initializer(actions, actions_len); + struct ofpbuf *openflow = &openflow_actions; + + enum ofperr error = 0; + while (openflow->size) { + /* Ensure the next action data is properly aligned. Trimming removes + * all headroom and ensures alignment. The headroom is also removed + * when cloning and ofpbuf. + */ + if (!OFPACT_IS_ALIGNED(openflow->data)) { + if (openflow == &openflow_actions) { + openflow = ofpbuf_clone(openflow); + } else { + ofpbuf_trim(openflow); + } + } + + const struct ofp_action_header *action = openflow->data; + size_t action_offset = actions_len - openflow->size; enum ofp_raw_action_type raw; - enum ofperr error; uint64_t arg; - error = ofpact_pull_raw(&openflow, ofp_version, &raw, &arg); + error = ofpact_pull_raw(openflow, ofp_version, &raw, &arg); if (!error) { error = ofpact_decode(action, raw, ofp_version, arg, vl_mff_map, ofpacts_tlv_bitmap, ofpacts); } if (error) { - log_bad_action(actions, actions_len, action, error); - return error; + log_bad_action(actions, actions_len, action_offset, error); + goto done; } } - return 0; + +done: + if (openflow != &openflow_actions) { + ofpbuf_delete(openflow); + } + return error; } static enum ofperr diff --git a/lib/ofp-errors.c b/lib/ofp-errors.c index 35191abf16dd..eb099d355270 100644 --- a/lib/ofp-errors.c +++ b/lib/ofp-errors.c @@ -20,6 +20,7 @@ #include "openflow/openflow.h" #include "openflow/nicira-ext.h" #include "openvswitch/dynamic-string.h" +#include "openvswitch/ofp-actions.h" #include "openvswitch/ofp-errors.h" #include "openvswitch/ofp-msgs.h" #include "openvswitch/ofp-print.h" @@ -346,6 +347,7 @@ ofperr_decode_msg(const struct ofp_header *oh, struct ofpbuf *payload) if (error && payload) { ofpbuf_init(payload, b.size); ofpbuf_push(payload, b.data, b.size); + ofpbuf_trim(payload); } return error; } diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index d4d42db72128..863b1f7237a9 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -7020,10 +7020,15 @@ do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len, /* Set the field only if the packet actually has it. */ if (mf_are_prereqs_ok(mf, flow, wc)) { - mf_mask_field_masked(mf, ofpact_set_field_mask(set_field), wc); - mf_set_flow_value_masked(mf, set_field->value, - ofpact_set_field_mask(set_field), - flow); + union mf_value *mask = ofpact_set_field_mask(set_field); + union mf_value aligned_mask; + + if (!IS_PTR_ALIGNED(mask)) { + memcpy(&aligned_mask, mask, mf->n_bytes); + mask = &aligned_mask; + } + mf_mask_field_masked(mf, mask, wc); + mf_set_flow_value_masked(mf, set_field->value, mask, flow); } else { xlate_report(ctx, OFT_WARN, "unmet prerequisites for %s, set_field ignored", From patchwork Fri Dec 17 13:18:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1570024 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=IEHh57Ra; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JFqM02SJsz9t6S for ; Sat, 18 Dec 2021 00:19:08 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 9EB7584C27; Fri, 17 Dec 2021 13:19:06 +0000 (UTC) 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 kCVIiavC52FZ; Fri, 17 Dec 2021 13:19:05 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id A929184C16; Fri, 17 Dec 2021 13:19:04 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 84775C002F; Fri, 17 Dec 2021 13:19:04 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2C0B7C0038 for ; Fri, 17 Dec 2021 13:19:03 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 65128610D8 for ; Fri, 17 Dec 2021 13:18:31 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com 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 dz8vVLzJ2Gih for ; Fri, 17 Dec 2021 13:18:30 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id 79958610C4 for ; Fri, 17 Dec 2021 13:18:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639747109; 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: in-reply-to:in-reply-to:references:references; bh=BgMFPQc7KijXe8fBpKckcjB538zbc8qOpYWZ2MHYKDU=; b=IEHh57RaZ/KDTybaW78gNIGvgnavSIkWw6D9/YtOiqO69nia1rId8y55SZx02uoLUGgKl2 Jl+2zgyun+g4nZEogXWQeOHW0fHIGlSCH6LUudT52cX/eM4hm3uow+87q/D0wXCyDLuRCz 2FGWXJMjJ0jOVEDsGfRmfgJJ6T9ezCE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-614-iDfL6Z1XOT-30SN5t4YQ2Q-1; Fri, 17 Dec 2021 08:18:28 -0500 X-MC-Unique: iDfL6Z1XOT-30SN5t4YQ2Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5F89A1F2DA; Fri, 17 Dec 2021 13:18:27 +0000 (UTC) Received: from dceara.remote.csb (unknown [10.39.193.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A0A13D7E; Fri, 17 Dec 2021 13:18:26 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Fri, 17 Dec 2021 14:18:23 +0100 Message-Id: <20211217131817.30994.11565.stgit@dceara.remote.csb> In-Reply-To: <20211217131623.30994.63519.stgit@dceara.remote.csb> References: <20211217131623.30994.63519.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dceara@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 08/11] bfd: lldp: stp: Fix misaligned packet field access. 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" UB Sanitizer reports: lib/bfd.c:748:16: runtime error: member access within misaligned address 0x000001f0d6ea for type 'struct msg', which requires 4 byte alignment 0x000001f0d6ea: note: pointer points here 00 20 00 00 20 40 03 18 93 f9 0a 6e 00 00 00 00 00 0f 42 40 00 0f 42 40 00 00 00 00 cc 00 00 00 ^ #0 0x59008e in bfd_process_packet lib/bfd.c:748 #1 0x52a240 in process_special ofproto/ofproto-dpif-xlate.c:3370 #2 0x553452 in xlate_actions ofproto/ofproto-dpif-xlate.c:7766 #3 0x4fc9e6 in upcall_xlate ofproto/ofproto-dpif-upcall.c:1237 #4 0x4fdecc in process_upcall ofproto/ofproto-dpif-upcall.c:1456 #5 0x4fd936 in upcall_cb ofproto/ofproto-dpif-upcall.c:1358 [...] lib/stp.c:754:15: runtime error: member access within misaligned address 0x000002c4ea61 for type 'const struct stp_bpdu_header', which requires 2 byte alignment 0x000002c4ea61: note: pointer points here 26 42 42 03 00 00 00 00 00 80 00 aa 66 aa 66 00 01 00 00 00 00 80 00 aa 66 aa 66 00 01 80 02 00 ^ #0 0x8a2bce in stp_received_bpdu lib/stp.c:754 #1 0x51e603 in stp_process_packet ofproto/ofproto-dpif-xlate.c:1788 #2 0x52a96d in process_special ofproto/ofproto-dpif-xlate.c:3394 #3 0x5534df in xlate_actions ofproto/ofproto-dpif-xlate.c:7766 #4 0x4fcb49 in upcall_xlate ofproto/ofproto-dpif-upcall.c:1237 [...] lib/lldp/lldp.c:149:10: runtime error: load of misaligned address 0x7ffcc0ae72bd for type 'ovs_be16', which requires 2 byte alignment 0x7ffcc0ae72bd: note: pointer points here 8e e7 84 ad 04 00 05 46 61 73 74 45 74 68 65 72 6e 65 74 20 31 2f 35 e0 91 07 c9 3e 7f 00 00 80 ^ #0 0x718d63 in lldp_tlv_end lib/lldp/lldp.c:149 #1 0x7191de in lldp_send lib/lldp/lldp.c:184 #2 0x484d6c in test_aa_send tests/test-aa.c:238 [...] Signed-off-by: Dumitru Ceara --- lib/bfd.c | 51 ++++++++++++++++++++++++++++----------------------- lib/lldp/lldp.c | 4 +++- lib/stp.c | 16 ++++++++-------- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/lib/bfd.c b/lib/bfd.c index 3c965699ace3..9698576d071b 100644 --- a/lib/bfd.c +++ b/lib/bfd.c @@ -131,16 +131,17 @@ enum diag { * | Required Min Echo RX Interval | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ struct msg { - uint8_t vers_diag; /* Version and diagnostic. */ - uint8_t flags; /* 2bit State field followed by flags. */ - uint8_t mult; /* Fault detection multiplier. */ - uint8_t length; /* Length of this BFD message. */ - ovs_be32 my_disc; /* My discriminator. */ - ovs_be32 your_disc; /* Your discriminator. */ - ovs_be32 min_tx; /* Desired minimum tx interval. */ - ovs_be32 min_rx; /* Required minimum rx interval. */ - ovs_be32 min_rx_echo; /* Required minimum echo rx interval. */ + uint8_t vers_diag; /* Version and diagnostic. */ + uint8_t flags; /* 2bit State field followed by flags. */ + uint8_t mult; /* Fault detection multiplier. */ + uint8_t length; /* Length of this BFD message. */ + ovs_16aligned_be32 my_disc; /* My discriminator. */ + ovs_16aligned_be32 your_disc; /* Your discriminator. */ + ovs_16aligned_be32 min_tx; /* Desired minimum tx interval. */ + ovs_16aligned_be32 min_rx; /* Required minimum rx interval. */ + ovs_16aligned_be32 min_rx_echo; /* Required minimum echo rx interval. */ }; + BUILD_ASSERT_DECL(BFD_PACKET_LEN == sizeof(struct msg)); #define DIAG_MASK 0x1f @@ -634,9 +635,9 @@ bfd_put_packet(struct bfd *bfd, struct dp_packet *p, msg->mult = bfd->mult; msg->length = BFD_PACKET_LEN; - msg->my_disc = htonl(bfd->disc); - msg->your_disc = htonl(bfd->rmt_disc); - msg->min_rx_echo = htonl(0); + put_16aligned_be32(&msg->my_disc, htonl(bfd->disc)); + put_16aligned_be32(&msg->your_disc, htonl(bfd->rmt_disc)); + put_16aligned_be32(&msg->min_rx_echo, htonl(0)); if (bfd_in_poll(bfd)) { min_tx = bfd->poll_min_tx; @@ -646,8 +647,8 @@ bfd_put_packet(struct bfd *bfd, struct dp_packet *p, min_rx = bfd->min_rx; } - msg->min_tx = htonl(min_tx * 1000); - msg->min_rx = htonl(min_rx * 1000); + put_16aligned_be32(&msg->min_tx, htonl(min_tx * 1000)); + put_16aligned_be32(&msg->min_rx, htonl(min_rx * 1000)); bfd->flags &= ~FLAG_FINAL; *oam = bfd->oam; @@ -781,12 +782,12 @@ bfd_process_packet(struct bfd *bfd, const struct flow *flow, goto out; } - if (!msg->my_disc) { + if (!get_16aligned_be32(&msg->my_disc)) { log_msg(VLL_WARN, msg, "NULL my_disc", bfd); goto out; } - pkt_your_disc = ntohl(msg->your_disc); + pkt_your_disc = ntohl(get_16aligned_be32(&msg->your_disc)); if (pkt_your_disc) { /* Technically, we should use the your discriminator field to figure * out which 'struct bfd' this packet is destined towards. That way a @@ -806,7 +807,7 @@ bfd_process_packet(struct bfd *bfd, const struct flow *flow, bfd_status_changed(bfd); } - bfd->rmt_disc = ntohl(msg->my_disc); + bfd->rmt_disc = ntohl(get_16aligned_be32(&msg->my_disc)); bfd->rmt_state = rmt_state; bfd->rmt_flags = flags; bfd->rmt_diag = msg->vers_diag & DIAG_MASK; @@ -834,7 +835,7 @@ bfd_process_packet(struct bfd *bfd, const struct flow *flow, bfd->rmt_mult = msg->mult; } - rmt_min_rx = MAX(ntohl(msg->min_rx) / 1000, 1); + rmt_min_rx = MAX(ntohl(get_16aligned_be32(&msg->min_rx)) / 1000, 1); if (bfd->rmt_min_rx != rmt_min_rx) { bfd->rmt_min_rx = rmt_min_rx; if (bfd->next_tx) { @@ -843,7 +844,7 @@ bfd_process_packet(struct bfd *bfd, const struct flow *flow, log_msg(VLL_INFO, msg, "New remote min_rx", bfd); } - bfd->rmt_min_tx = MAX(ntohl(msg->min_tx) / 1000, 1); + bfd->rmt_min_tx = MAX(ntohl(get_16aligned_be32(&msg->min_tx)) / 1000, 1); bfd->detect_time = bfd_rx_interval(bfd) * bfd->rmt_mult + time_msec(); if (bfd->state == STATE_ADMIN_DOWN) { @@ -1105,10 +1106,14 @@ log_msg(enum vlog_level level, const struct msg *p, const char *message, bfd_diag_str(p->vers_diag & DIAG_MASK), bfd_state_str(p->flags & STATE_MASK), p->mult, p->length, bfd_flag_str(p->flags & FLAGS_MASK), - ntohl(p->my_disc), ntohl(p->your_disc), - ntohl(p->min_tx), ntohl(p->min_tx) / 1000, - ntohl(p->min_rx), ntohl(p->min_rx) / 1000, - ntohl(p->min_rx_echo), ntohl(p->min_rx_echo) / 1000); + ntohl(get_16aligned_be32(&p->my_disc)), + ntohl(get_16aligned_be32(&p->your_disc)), + ntohl(get_16aligned_be32(&p->min_tx)), + ntohl(get_16aligned_be32(&p->min_tx)) / 1000, + ntohl(get_16aligned_be32(&p->min_rx)), + ntohl(get_16aligned_be32(&p->min_rx)) / 1000, + ntohl(get_16aligned_be32(&p->min_rx_echo)), + ntohl(get_16aligned_be32(&p->min_rx_echo)) / 1000); bfd_put_details(&ds, bfd); VLOG(level, "%s", ds_cstr(&ds)); ds_destroy(&ds); diff --git a/lib/lldp/lldp.c b/lib/lldp/lldp.c index 18afbab9a7fe..dfeb2a800244 100644 --- a/lib/lldp/lldp.c +++ b/lib/lldp/lldp.c @@ -146,7 +146,9 @@ static void lldp_tlv_end(struct dp_packet *p, unsigned int start) { ovs_be16 *tlv = dp_packet_at_assert(p, start, 2); - *tlv |= htons((dp_packet_size(p) - (start + 2)) & 0x1ff); + put_unaligned_be16(tlv, + get_unaligned_be16(tlv) + | htons((dp_packet_size(p) - (start + 2)) & 0x1ff)); } int diff --git a/lib/stp.c b/lib/stp.c index 809b405a5298..a869b5f390ce 100644 --- a/lib/stp.c +++ b/lib/stp.c @@ -737,7 +737,7 @@ void stp_received_bpdu(struct stp_port *p, const void *bpdu, size_t bpdu_size) { struct stp *stp = p->stp; - const struct stp_bpdu_header *header; + struct stp_bpdu_header header; ovs_mutex_lock(&mutex); if (p->state == STP_DISABLED) { @@ -750,19 +750,19 @@ stp_received_bpdu(struct stp_port *p, const void *bpdu, size_t bpdu_size) goto out; } - header = bpdu; - if (header->protocol_id != htons(STP_PROTOCOL_ID)) { + memcpy(&header, bpdu, sizeof header); + if (header.protocol_id != htons(STP_PROTOCOL_ID)) { VLOG_WARN("%s: received BPDU with unexpected protocol ID %"PRIu16, - stp->name, ntohs(header->protocol_id)); + stp->name, ntohs(header.protocol_id)); p->error_count++; goto out; } - if (header->protocol_version != STP_PROTOCOL_VERSION) { + if (header.protocol_version != STP_PROTOCOL_VERSION) { VLOG_DBG("%s: received BPDU with unexpected protocol version %"PRIu8, - stp->name, header->protocol_version); + stp->name, header.protocol_version); } - switch (header->bpdu_type) { + switch (header.bpdu_type) { case STP_TYPE_CONFIG: if (bpdu_size < sizeof(struct stp_config_bpdu)) { VLOG_WARN("%s: received config BPDU with invalid size %"PRIuSIZE, @@ -785,7 +785,7 @@ stp_received_bpdu(struct stp_port *p, const void *bpdu, size_t bpdu_size) default: VLOG_WARN("%s: received BPDU of unexpected type %"PRIu8, - stp->name, header->bpdu_type); + stp->name, header.bpdu_type); p->error_count++; goto out; } From patchwork Fri Dec 17 13:18:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1570025 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=ThXkDDjE; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JFqMB2MySz9t6S for ; Sat, 18 Dec 2021 00:19:18 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 13D3840BF3; Fri, 17 Dec 2021 13:19:16 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ew0k5SeMSzNn; Fri, 17 Dec 2021 13:19:14 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id A968840BF5; Fri, 17 Dec 2021 13:19:13 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 80B1FC002F; Fri, 17 Dec 2021 13:19:13 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 33B25C0038 for ; Fri, 17 Dec 2021 13:19:12 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 0FAB8610BE for ; Fri, 17 Dec 2021 13:18:51 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com 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 991EBS8JnvRf for ; Fri, 17 Dec 2021 13:18:50 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id 39616610C7 for ; Fri, 17 Dec 2021 13:18:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639747129; 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: in-reply-to:in-reply-to:references:references; bh=I8YevzR0W3a/6lVW6lzHE47tlPSCIcULtjr0Dd0EZ90=; b=ThXkDDjESZs353PbdWWsQYBpbKjDuIEsdgrxh+uqy8RRYkn/aZq+6gJViCwIEvhOvIgNwA bdOe1YxGzhDOv9IXbRjvX8YqCrQMQlVV76Z3PloIXsvGSGgrsdtcz+F+DUGXlnzrnYiH1/ FTfMM5xVFjO+wjuP4YphLKzdGfah9aQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-518-7rcEKtiNOu-KUKKFvdrNKQ-1; Fri, 17 Dec 2021 08:18:48 -0500 X-MC-Unique: 7rcEKtiNOu-KUKKFvdrNKQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6F7F485B6C1; Fri, 17 Dec 2021 13:18:47 +0000 (UTC) Received: from dceara.remote.csb (unknown [10.39.193.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id D2D392B05E; Fri, 17 Dec 2021 13:18:43 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Fri, 17 Dec 2021 14:18:35 +0100 Message-Id: <20211217131832.30994.53181.stgit@dceara.remote.csb> In-Reply-To: <20211217131623.30994.63519.stgit@dceara.remote.csb> References: <20211217131623.30994.63519.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dceara@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 09/11] dp-packet: Ensure packet base is always non-NULL. 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" UB Sanitizer report: lib/dp-packet.h:297:39: runtime error: applying zero offset to null pointer #0 0x7946f5 in dp_packet_tail /root/ovs/./lib/dp-packet.h:297:39 #1 0x794331 in dp_packet_tailroom /root/ovs/./lib/dp-packet.h:325:49 #2 0x7942a0 in dp_packet_prealloc_tailroom /root/ovs/lib/dp-packet.c:297:16 #3 0xc347cf in eth_compose /root/ovs/lib/packets.c:1061:5 [...] Signed-off-by: Dumitru Ceara --- lib/netdev-dummy.c | 6 +++--- ofproto/bond.c | 3 ++- ofproto/ofproto-dpif-trace.c | 4 ++-- ofproto/ofproto-dpif-xlate.c | 4 ++-- ofproto/ofproto-dpif.c | 6 +++--- utilities/ovs-ofctl.c | 6 ++---- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c index 1f386b81bbaf..2bb6c38bd5ca 100644 --- a/lib/netdev-dummy.c +++ b/lib/netdev-dummy.c @@ -188,7 +188,7 @@ dummy_packet_stream_init(struct dummy_packet_stream *s, struct stream *stream) { int rxbuf_size = stream ? 2048 : 0; s->stream = stream; - dp_packet_init(&s->rxbuf, rxbuf_size); + dp_packet_init(&s->rxbuf, MAX(rxbuf_size, ETH_HEADER_LEN)); ovs_list_init(&s->txq); } @@ -1149,7 +1149,7 @@ netdev_dummy_send(struct netdev *netdev, int qid OVS_UNUSED, if (flow.dl_type == htons(ETH_TYPE_ARP) && flow.nw_proto == ARP_OP_REQUEST && flow.nw_dst == dev->address.s_addr) { - struct dp_packet *reply = dp_packet_new(0); + struct dp_packet *reply = dp_packet_new(ETH_HEADER_LEN); compose_arp(reply, ARP_OP_REPLY, dev->hwaddr, flow.dl_src, false, flow.nw_dst, flow.nw_src); netdev_dummy_queue_packet(dev, reply, NULL, 0); @@ -1647,7 +1647,7 @@ eth_from_flow_str(const char *s, size_t packet_size, return NULL; } - packet = dp_packet_new(0); + packet = dp_packet_new(MAX(packet_size, ETH_HEADER_LEN)); if (packet_size) { flow_compose(packet, flow, NULL, 0); if (dp_packet_size(packet) < packet_size) { diff --git a/ofproto/bond.c b/ofproto/bond.c index cdfdf0b9d8c0..8ab27ed09c3a 100644 --- a/ofproto/bond.c +++ b/ofproto/bond.c @@ -809,7 +809,8 @@ bond_compose_learning_packet(struct bond *bond, const struct eth_addr eth_src, flow.dl_src = eth_src; member = choose_output_member(bond, &flow, NULL, vlan); - packet = dp_packet_new(0); + packet = dp_packet_new(2 + ETH_HEADER_LEN + VLAN_HEADER_LEN + + ARP_ETH_HEADER_LEN); compose_rarp(packet, eth_src); if (vlan) { eth_push_vlan(packet, htons(ETH_TYPE_VLAN), htons(vlan)); diff --git a/ofproto/ofproto-dpif-trace.c b/ofproto/ofproto-dpif-trace.c index 78a54c715dc7..b4a9974689d1 100644 --- a/ofproto/ofproto-dpif-trace.c +++ b/ofproto/ofproto-dpif-trace.c @@ -245,7 +245,7 @@ parse_flow_and_packet(int argc, const char *argv[], struct dp_packet payload; memset(&payload, 0, sizeof payload); - dp_packet_init(&payload, 0); + dp_packet_init(&payload, ETH_HEADER_LEN); if (dp_packet_put_hex(&payload, argv[++i], NULL)[0] != '\0') { dp_packet_uninit(&payload); error = xstrdup("Trailing garbage in packet data"); @@ -436,7 +436,7 @@ parse_flow_and_packet(int argc, const char *argv[], if (generate_packet) { /* Generate a packet, as requested. */ - packet = dp_packet_new(0); + packet = dp_packet_new(ETH_HEADER_LEN); flow_compose(packet, flow, l7, l7_len); } else if (packet) { /* Use the metadata from the flow and the packet argument to diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index 863b1f7237a9..81c0e6ebf850 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -3490,7 +3490,7 @@ tnl_send_nd_request(struct xlate_ctx *ctx, const struct xport *out_dev, { struct dp_packet packet; - dp_packet_init(&packet, 0); + dp_packet_init(&packet, ETH_HEADER_LEN); compose_nd_ns(&packet, eth_src, ipv6_src, ipv6_dst); compose_table_xlate(ctx, out_dev, &packet); dp_packet_uninit(&packet); @@ -3503,7 +3503,7 @@ tnl_send_arp_request(struct xlate_ctx *ctx, const struct xport *out_dev, { struct dp_packet packet; - dp_packet_init(&packet, 0); + dp_packet_init(&packet, ETH_HEADER_LEN); compose_arp(&packet, ARP_OP_REQUEST, eth_src, eth_addr_zero, true, ip_src, ip_dst); diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index bc3df8ea1510..e44e365dd405 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -1268,7 +1268,7 @@ check_ct_eventmask(struct dpif_backer *backer) nl_msg_end_nested(&actions, ct_start); /* Compose a dummy UDP packet. */ - dp_packet_init(&packet, 0); + dp_packet_init(&packet, ETH_HEADER_LEN); flow_compose(&packet, &flow, NULL, 64); /* Execute the actions. On older datapaths this fails with EINVAL, on @@ -1361,7 +1361,7 @@ check_ct_timeout_policy(struct dpif_backer *backer) nl_msg_end_nested(&actions, ct_start); /* Compose a dummy UDP packet. */ - dp_packet_init(&packet, 0); + dp_packet_init(&packet, ETH_HEADER_LEN); flow_compose(&packet, &flow, NULL, 64); /* Execute the actions. On older datapaths this fails with EINVAL, on @@ -3501,7 +3501,7 @@ send_pdu_cb(void *port_, const void *pdu, size_t pdu_size) struct dp_packet packet; void *packet_pdu; - dp_packet_init(&packet, 0); + dp_packet_init(&packet, ETH_HEADER_LEN); packet_pdu = eth_compose(&packet, eth_addr_lacp, ea, ETH_TYPE_LACP, pdu_size); memcpy(packet_pdu, pdu, pdu_size); diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index ede7f1e61ab8..55b5e1a4c95a 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -4902,15 +4902,13 @@ ofctl_compose_packet(struct ovs_cmdl_context *ctx) } struct dp_packet p; - memset(&p, 0, sizeof p); - dp_packet_init(&p, 0); + dp_packet_init(&p, ETH_HEADER_LEN); void *l7 = NULL; size_t l7_len = 64; if (ctx->argc > 2) { struct dp_packet payload; - memset(&payload, 0, sizeof payload); - dp_packet_init(&payload, 0); + dp_packet_init(&payload, ETH_HEADER_LEN); if (dp_packet_put_hex(&payload, ctx->argv[2], NULL)[0] != '\0') { ovs_fatal(0, "%s: trailing garbage in packet data", ctx->argv[2]); } From patchwork Fri Dec 17 13:19:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1570027 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=ZhiLLNZl; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JFqN76jfLz9t6S for ; Sat, 18 Dec 2021 00:20:07 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 9E9E541E18; Fri, 17 Dec 2021 13:20:05 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id f-ndTPSSyxWk; Fri, 17 Dec 2021 13:20:04 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 59E8D41DC3; Fri, 17 Dec 2021 13:20:03 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 549DFC006E; Fri, 17 Dec 2021 13:20:02 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 30B61C0012 for ; Fri, 17 Dec 2021 13:20:00 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 55EE340C0A for ; Fri, 17 Dec 2021 13:19:17 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dz_K6dDANkGG for ; Fri, 17 Dec 2021 13:19:15 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp2.osuosl.org (Postfix) with ESMTPS id 8394240BCD for ; Fri, 17 Dec 2021 13:19:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639747154; 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: in-reply-to:in-reply-to:references:references; bh=sFs55alGW+MfmYVRZZlloNzXwhpnKw3nIrfXBUulSOM=; b=ZhiLLNZlw5zsylVcxgl5Pc5+9CG2mC1NyALUFH6+i7/k6bh7hiW8SQBdQJyyUoFyGM4aNy aHNYiqaXm39vEMlQLhUPamZC6t2yoRZJmiGPmHhGXkAlk0ppf5d1R+Ga/OfHoFr4MKMeRW cuZJgmxe2eIcOkEob4OD8esbiNuIpeI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-613-LbpaJvYDP4WU7zWZh01Dcg-1; Fri, 17 Dec 2021 08:19:11 -0500 X-MC-Unique: LbpaJvYDP4WU7zWZh01Dcg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3EF19344B0; Fri, 17 Dec 2021 13:19:10 +0000 (UTC) Received: from dceara.remote.csb (unknown [10.39.193.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DB9C1036B4D; Fri, 17 Dec 2021 13:19:06 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Fri, 17 Dec 2021 14:19:02 +0100 Message-Id: <20211217131852.30994.52950.stgit@dceara.remote.csb> In-Reply-To: <20211217131623.30994.63519.stgit@dceara.remote.csb> References: <20211217131623.30994.63519.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dceara@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 10/11] treewide: Avoid offsetting NULL pointers. 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" This is undefined behavior and was reported by UB Sanitizer: lib/meta-flow.c:3445:16: runtime error: member access within null pointer of type 'struct vl_mf_field' #0 0x6aad0f in mf_get_vl_mff lib/meta-flow.c:3445 #1 0x6d96d7 in mf_from_oxm_header lib/nx-match.c:260 #2 0x6d9e2e in nx_pull_header__ lib/nx-match.c:341 #3 0x6daafa in nx_pull_header lib/nx-match.c:488 #4 0x6abcb6 in mf_vl_mff_nx_pull_header lib/meta-flow.c:3605 #5 0x73b9be in decode_NXAST_RAW_REG_MOVE lib/ofp-actions.c:2652 #6 0x764ccd in ofpact_decode lib/ofp-actions.inc2:4681 [...] lib/sset.c:315:12: runtime error: applying zero offset to null pointer #0 0xcc2e6a in sset_at_position /root/ovs/lib/sset.c:315:12 #1 0x5734b3 in port_dump_next /root/ovs/ofproto/ofproto-dpif.c:4083:20 [...] lib/ovsdb-data.c:2194:56: runtime error: applying zero offset to null pointer #0 0x5e9530 in ovsdb_datum_added_removed /root/ovs/lib/ovsdb-data.c:2194:56 #1 0x4d6258 in update_row_ref_count /root/ovs/ovsdb/transaction.c:335:17 #2 0x4c360b in for_each_txn_row /root/ovs/ovsdb/transaction.c:1572:33 [...] lib/ofpbuf.c:440:30: runtime error: applying zero offset to null pointer #0 0x75066d in ofpbuf_push_uninit lib/ofpbuf.c:440 #1 0x46ac8a in ovnacts_parse lib/actions.c:4190 #2 0x46ad91 in ovnacts_parse_string lib/actions.c:4208 #3 0x4106d1 in test_parse_actions tests/test-ovn.c:1324 [...] lib/ofp-actions.c:3205:22: runtime error: applying non-zero offset 2 to null pointer #0 0x6e1641 in set_field_split_str /root/ovs/lib/ofp-actions.c:3205:22 [...] lib/tnl-ports.c:74:12: runtime error: applying zero offset to null pointer #0 0xceffe7 in tnl_port_cast /root/ovs/lib/tnl-ports.c:74:12 #1 0xcf14c3 in map_insert /root/ovs/lib/tnl-ports.c:116:13 [...] ofproto/ofproto.c:8905:16: runtime error: applying zero offset to null pointer #0 0x556795 in eviction_group_hash_rule /root/ovs/ofproto/ofproto.c:8905:16 #1 0x503f8d in eviction_group_add_rule /root/ovs/ofproto/ofproto.c:9022:42 [...] Also, it's valid to have an empty ofpact list and we should be able to try to iterate through it. UB Sanitizer report: include/openvswitch/ofp-actions.h:222:12: runtime error: applying zero offset to null pointer #0 0x665d69 in ofpact_end /root/ovs/./include/openvswitch/ofp-actions.h:222:12 #1 0x66b2cf in ofpacts_put_openflow_actions /root/ovs/lib/ofp-actions.c:8861:5 #2 0x6ffdd1 in ofputil_encode_flow_mod /root/ovs/lib/ofp-flow.c:447:9 [...] Signed-off-by: Dumitru Ceara --- include/openvswitch/ofp-actions.h | 4 +++- include/openvswitch/ofpbuf.h | 17 ++++++++++++----- lib/dynamic-string.c | 10 ++++++++-- lib/meta-flow.c | 4 +++- lib/ofp-actions.c | 8 ++++---- lib/ofpbuf.c | 4 ++++ lib/ovsdb-data.c | 37 +++++++++++++++++++++---------------- lib/ovsdb-data.h | 4 ++++ lib/sset.c | 4 +++- lib/tnl-ports.c | 2 +- ofproto/ofproto.c | 2 +- 11 files changed, 64 insertions(+), 32 deletions(-) diff --git a/include/openvswitch/ofp-actions.h b/include/openvswitch/ofp-actions.h index 3b67675fe02a..0991a0177411 100644 --- a/include/openvswitch/ofp-actions.h +++ b/include/openvswitch/ofp-actions.h @@ -219,7 +219,9 @@ struct ofpact *ofpact_next_flattened(const struct ofpact *); static inline struct ofpact * ofpact_end(const struct ofpact *ofpacts, size_t ofpacts_len) { - return ALIGNED_CAST(struct ofpact *, (uint8_t *) ofpacts + ofpacts_len); + return ofpacts + ? ALIGNED_CAST(struct ofpact *, (uint8_t *) ofpacts + ofpacts_len) + : NULL; } static inline bool diff --git a/include/openvswitch/ofpbuf.h b/include/openvswitch/ofpbuf.h index 1136ba04c84e..a9ff8a56e81c 100644 --- a/include/openvswitch/ofpbuf.h +++ b/include/openvswitch/ofpbuf.h @@ -179,7 +179,9 @@ static inline void ofpbuf_delete(struct ofpbuf *b) static inline void *ofpbuf_at(const struct ofpbuf *b, size_t offset, size_t size) { - return offset + size <= b->size ? (char *) b->data + offset : NULL; + return offset + size <= b->size && b->data + ? (char *) b->data + offset + : NULL; } /* Returns a pointer to byte 'offset' in 'b', which must contain at least @@ -188,20 +190,20 @@ static inline void *ofpbuf_at_assert(const struct ofpbuf *b, size_t offset, size_t size) { ovs_assert(offset + size <= b->size); - return ((char *) b->data) + offset; + return b->data ? (char *) b->data + offset : NULL; } /* Returns a pointer to byte following the last byte of data in use in 'b'. */ static inline void *ofpbuf_tail(const struct ofpbuf *b) { - return (char *) b->data + b->size; + return b->data ? (char *) b->data + b->size : NULL; } /* Returns a pointer to byte following the last byte allocated for use (but * not necessarily in use) in 'b'. */ static inline void *ofpbuf_end(const struct ofpbuf *b) { - return (char *) b->base + b->allocated; + return b->base ? (char *) b->base + b->allocated : NULL; } /* Returns the number of bytes of headroom in 'b', that is, the number of bytes @@ -249,6 +251,11 @@ static inline void *ofpbuf_pull(struct ofpbuf *b, size_t size) { ovs_assert(b->size >= size); void *data = b->data; + + if (!size) { + return data; + } + b->data = (char*)b->data + size; b->size = b->size - size; return data; @@ -270,7 +277,7 @@ static inline struct ofpbuf *ofpbuf_from_list(const struct ovs_list *list) static inline bool ofpbuf_equal(const struct ofpbuf *a, const struct ofpbuf *b) { return a->size == b->size && - memcmp(a->data, b->data, a->size) == 0; + (a->size == 0 || memcmp(a->data, b->data, a->size) == 0); } static inline bool ofpbuf_oversized(const struct ofpbuf *ofpacts) diff --git a/lib/dynamic-string.c b/lib/dynamic-string.c index fd0127ed1740..9b9a8f50e562 100644 --- a/lib/dynamic-string.c +++ b/lib/dynamic-string.c @@ -152,7 +152,10 @@ ds_put_format_valist(struct ds *ds, const char *format, va_list args_) va_copy(args, args_); available = ds->string ? ds->allocated - ds->length + 1 : 0; - needed = vsnprintf(&ds->string[ds->length], available, format, args); + needed = vsnprintf(ds->string + ? &ds->string[ds->length] + : NULL, + available, format, args); va_end(args); if (needed < available) { @@ -162,7 +165,10 @@ ds_put_format_valist(struct ds *ds, const char *format, va_list args_) va_copy(args, args_); available = ds->allocated - ds->length + 1; - needed = vsnprintf(&ds->string[ds->length], available, format, args); + needed = vsnprintf(ds->string + ? &ds->string[ds->length] + : NULL, + available, format, args); va_end(args); ovs_assert(needed < available); diff --git a/lib/meta-flow.c b/lib/meta-flow.c index 92bfd350a92b..2e64fed5f8f2 100644 --- a/lib/meta-flow.c +++ b/lib/meta-flow.c @@ -3448,7 +3448,9 @@ mf_get_vl_mff(const struct mf_field *mff, const struct vl_mff_map *vl_mff_map) { if (mff && mff->variable_len && vl_mff_map) { - return &mf_get_vl_mff__(mff->id, vl_mff_map)->mf; + struct vl_mf_field *vl_mff = mf_get_vl_mff__(mff->id, vl_mff_map); + + return vl_mff ? &vl_mff->mf : NULL; } return NULL; diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c index 040456ad532d..cf7240873dde 100644 --- a/lib/ofp-actions.c +++ b/lib/ofp-actions.c @@ -3202,14 +3202,14 @@ set_field_split_str(char *arg, char **key, char **value, char **delim) *value = arg; value_end = strstr(arg, "->"); + if (!value_end) { + return xasprintf("%s: missing `->'", arg); + } + *key = value_end + strlen("->"); if (delim) { *delim = value_end; } - - if (!value_end) { - return xasprintf("%s: missing `->'", arg); - } if (strlen(value_end) <= strlen("->")) { return xasprintf("%s: missing field name following `->'", arg); } diff --git a/lib/ofpbuf.c b/lib/ofpbuf.c index 271105bdea17..0330681b2518 100644 --- a/lib/ofpbuf.c +++ b/lib/ofpbuf.c @@ -436,6 +436,10 @@ ofpbuf_reserve(struct ofpbuf *b, size_t size) void * ofpbuf_push_uninit(struct ofpbuf *b, size_t size) { + if (!size) { + return b->data; + } + ofpbuf_prealloc_headroom(b, size); b->data = (char*)b->data - size; b->size += size; diff --git a/lib/ovsdb-data.c b/lib/ovsdb-data.c index 6b1c20ff85a0..306b8d0d946a 100644 --- a/lib/ovsdb-data.c +++ b/lib/ovsdb-data.c @@ -1957,6 +1957,19 @@ ovsdb_datum_add_unsafe(struct ovsdb_datum *datum, } } +void +ovsdb_datum_add_unsafe_index(struct ovsdb_datum *dst, + const struct ovsdb_datum *src, + size_t idx, + const struct ovsdb_type *type) +{ + const union ovsdb_atom *key = &src->keys[idx]; + const union ovsdb_atom *value = type->value.type != OVSDB_TYPE_VOID + ? &src->values[idx] + : NULL; + ovsdb_datum_add_unsafe(dst, key, value, type, NULL); +} + /* Adds 'n' atoms starting from index 'start_idx' from 'src' to the end of * 'dst'. 'dst' should have enough memory allocated to hold the additional * 'n' atoms. Atoms are not cloned, i.e. 'dst' will reference the same data. @@ -2165,12 +2178,10 @@ ovsdb_datum_added_removed(struct ovsdb_datum *added, int c = ovsdb_atom_compare_3way(&old->keys[oi], &new->keys[ni], type->key.type); if (c < 0) { - ovsdb_datum_add_unsafe(removed, &old->keys[oi], &old->values[oi], - type, NULL); + ovsdb_datum_add_unsafe_index(removed, old, oi, type); oi++; } else if (c > 0) { - ovsdb_datum_add_unsafe(added, &new->keys[ni], &new->values[ni], - type, NULL); + ovsdb_datum_add_unsafe_index(added, new, ni, type); ni++; } else { if (type->value.type != OVSDB_TYPE_VOID && @@ -2186,13 +2197,11 @@ ovsdb_datum_added_removed(struct ovsdb_datum *added, } for (; oi < old->n; oi++) { - ovsdb_datum_add_unsafe(removed, &old->keys[oi], &old->values[oi], - type, NULL); + ovsdb_datum_add_unsafe_index(removed, old, oi, type); } for (; ni < new->n; ni++) { - ovsdb_datum_add_unsafe(added, &new->keys[ni], &new->values[ni], - type, NULL); + ovsdb_datum_add_unsafe_index(added, new, ni, type); } } @@ -2228,12 +2237,10 @@ ovsdb_datum_diff(struct ovsdb_datum *diff, int c = ovsdb_atom_compare_3way(&old->keys[oi], &new->keys[ni], type->key.type); if (c < 0) { - ovsdb_datum_add_unsafe(diff, &old->keys[oi], &old->values[oi], - type, NULL); + ovsdb_datum_add_unsafe_index(diff, old, oi, type); oi++; } else if (c > 0) { - ovsdb_datum_add_unsafe(diff, &new->keys[ni], &new->values[ni], - type, NULL); + ovsdb_datum_add_unsafe_index(diff, new, ni, type); ni++; } else { if (type->value.type != OVSDB_TYPE_VOID && @@ -2247,13 +2254,11 @@ ovsdb_datum_diff(struct ovsdb_datum *diff, } for (; oi < old->n; oi++) { - ovsdb_datum_add_unsafe(diff, &old->keys[oi], &old->values[oi], - type, NULL); + ovsdb_datum_add_unsafe_index(diff, old, oi, type); } for (; ni < new->n; ni++) { - ovsdb_datum_add_unsafe(diff, &new->keys[ni], &new->values[ni], - type, NULL); + ovsdb_datum_add_unsafe_index(diff, new, ni, type); } } diff --git a/lib/ovsdb-data.h b/lib/ovsdb-data.h index 47115a7b85b7..31c7c27e6b93 100644 --- a/lib/ovsdb-data.h +++ b/lib/ovsdb-data.h @@ -280,6 +280,10 @@ void ovsdb_datum_add_unsafe(struct ovsdb_datum *, const union ovsdb_atom *value, const struct ovsdb_type *, const union ovsdb_atom *range_end_atom); +void ovsdb_datum_add_unsafe_index(struct ovsdb_datum *dst, + const struct ovsdb_datum *src, + size_t idx, + const struct ovsdb_type *type); /* Transactions with named-uuid row names. */ struct json *ovsdb_datum_to_json_with_row_names(const struct ovsdb_datum *, diff --git a/lib/sset.c b/lib/sset.c index b2e3f43ec91b..b18b948fa4e7 100644 --- a/lib/sset.c +++ b/lib/sset.c @@ -312,7 +312,9 @@ sset_at_position(const struct sset *set, struct sset_position *pos) struct hmap_node *hmap_node; hmap_node = hmap_at_position(&set->map, &pos->pos); - return SSET_NODE_FROM_HMAP_NODE(hmap_node); + return hmap_node + ? SSET_NODE_FROM_HMAP_NODE(hmap_node) + : NULL; } /* Replaces 'a' by the intersection of 'a' and 'b'. That is, removes from 'a' diff --git a/lib/tnl-ports.c b/lib/tnl-ports.c index 58269d3b1631..dd3320ccbb96 100644 --- a/lib/tnl-ports.c +++ b/lib/tnl-ports.c @@ -71,7 +71,7 @@ tnl_port_cast(const struct cls_rule *cr) { BUILD_ASSERT_DECL(offsetof(struct tnl_port_in, cr) == 0); - return CONTAINER_OF(cr, struct tnl_port_in, cr); + return cr ? CONTAINER_OF(cr, struct tnl_port_in, cr) : NULL; } static void diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 56aeac720935..c3ffbbb13b5b 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -8902,7 +8902,7 @@ eviction_group_hash_rule(struct rule *rule) hash = table->eviction_group_id_basis; miniflow_expand(rule->cr.match.flow, &flow); for (sf = table->eviction_fields; - sf < &table->eviction_fields[table->n_eviction_fields]; + sf && sf < &table->eviction_fields[table->n_eviction_fields]; sf++) { if (mf_are_prereqs_ok(sf->field, &flow, NULL)) { From patchwork Fri Dec 17 13:19:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1570026 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=RVv2U6cc; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JFqN53NYdz9t6S for ; Sat, 18 Dec 2021 00:20:05 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 3F24F40BDA; Fri, 17 Dec 2021 13:20:03 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id H3vSM0VPmLwF; Fri, 17 Dec 2021 13:20:01 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id BD69E40BA5; Fri, 17 Dec 2021 13:20:00 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 886C1C002F; Fri, 17 Dec 2021 13:20:00 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3D404C0038 for ; Fri, 17 Dec 2021 13:19:59 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id D5B58605AB for ; Fri, 17 Dec 2021 13:19:28 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=fail (1024-bit key) reason="fail (body has been altered)" header.d=redhat.com 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 MRCW2-ZeUr-4 for ; Fri, 17 Dec 2021 13:19:28 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id E82AE610D6 for ; Fri, 17 Dec 2021 13:19:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639747167; 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: in-reply-to:in-reply-to:references:references; bh=WUqP7otRoj/FkrAeVV6dQ1b8B0An5FGUZX/RsZmVPwg=; b=RVv2U6ccCx2drxnetm6FhRC3noS6u7xYYygn0ysMdqaWAHnC6JjIpUY7nqS5G02n3IFiVV r+xnu4kcNoowACw0wKVNNp0d5Iz8CLkathij4zkpT3MT7HVRlCTgclkAxgsiJuXrulFMKZ /v1ZhGXDAkjdnlrqvhwwyhlZT+MPJNU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-614-FMw7M1KSO_mFq2PH92SiVw-1; Fri, 17 Dec 2021 08:19:25 -0500 X-MC-Unique: FMw7M1KSO_mFq2PH92SiVw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C8AE41023F4D; Fri, 17 Dec 2021 13:19:24 +0000 (UTC) Received: from dceara.remote.csb (unknown [10.39.193.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4501610A7; Fri, 17 Dec 2021 13:19:23 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Fri, 17 Dec 2021 14:19:18 +0100 Message-Id: <20211217131916.30994.9967.stgit@dceara.remote.csb> In-Reply-To: <20211217131623.30994.63519.stgit@dceara.remote.csb> References: <20211217131623.30994.63519.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dceara@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 11/11] ci: Add UB Sanitizer. 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" Signed-off-by: Dumitru Ceara --- .ci/linux-build.sh | 6 ++++++ .github/workflows/build-and-test.yml | 5 +++++ configure.ac | 1 + tests/atlocal.in | 16 ++++++++++++++++ tests/automake.mk | 1 + tests/daemon.at | 8 ++++++++ tests/ovs-macros.at | 5 +++++ tests/ovsdb-server.at | 16 ++++++++++++++++ 8 files changed, 58 insertions(+) diff --git a/.ci/linux-build.sh b/.ci/linux-build.sh index ff6ae4b10031..5bdfc896bf0a 100755 --- a/.ci/linux-build.sh +++ b/.ci/linux-build.sh @@ -254,6 +254,12 @@ if [ "$ASAN" ]; then CFLAGS_FOR_OVS="${CFLAGS_FOR_OVS} ${CLFAGS_ASAN}" fi +if [ "$UBSAN" ]; then + # Use the default options configured in tests/atlocal.in, in UBSAN_OPTIONS. + CLFAGS_UBSAN="-O1 -fno-omit-frame-pointer -fno-common -fsanitize=undefined" + CFLAGS_FOR_OVS="${CFLAGS_FOR_OVS} ${CLFAGS_UBSAN}" +fi + save_OPTS="${OPTS} $*" OPTS="${EXTRA_OPTS} ${save_OPTS}" diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index eac3504e48f8..9e3583781baa 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -13,6 +13,7 @@ jobs: linux-headers-$(uname -r) build-essential fakeroot devscripts equivs AFXDP: ${{ matrix.afxdp }} ASAN: ${{ matrix.asan }} + UBSAN: ${{ matrix.ubsan }} CC: ${{ matrix.compiler }} DEB_PACKAGE: ${{ matrix.deb_package }} DPDK: ${{ matrix.dpdk }} @@ -44,6 +45,10 @@ jobs: testsuite: test kernel: 3.16 asan: asan + - compiler: clang + testsuite: test + kernel: 3.16 + ubsan: ubsan - compiler: gcc testsuite: test diff --git a/configure.ac b/configure.ac index eaa9bf7ee68a..8492824364a9 100644 --- a/configure.ac +++ b/configure.ac @@ -196,6 +196,7 @@ OVS_CHECK_LINUX_SCTP_CT OVS_CHECK_LINUX_VIRTIO_TYPES OVS_CHECK_DPDK OVS_CHECK_PRAGMA_MESSAGE +AC_SUBST([CFLAGS]) AC_SUBST([OVS_CFLAGS]) AC_SUBST([OVS_LDFLAGS]) diff --git a/tests/atlocal.in b/tests/atlocal.in index a0ad239ecef2..142ea2090bc8 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -4,6 +4,7 @@ OPENSSL_SUPPORTS_SNI='@OPENSSL_SUPPORTS_SNI@' HAVE_UNBOUND='@HAVE_UNBOUND@' EGREP='@EGREP@' PYTHON3='@PYTHON3@' +CFLAGS='@CFLAGS@' # PYTHONCOERCECLOCALE=0 disables the Unicode compatibility warning on # stderr that breaks almost any Python3 test (PEP 0538) @@ -197,6 +198,16 @@ else DIFF_SUPPORTS_NORMAL_FORMAT=no fi +# Check whether UB Sanitizer is being used. +case "$CFLAGS" in +*fsanitize=undefined*) + TESTS_WITH_UBSAN=yes + ;; +*) + TESTS_WITH_UBSAN=no + ;; +esac + # Turn off proxies. unset http_proxy unset https_proxy @@ -222,3 +233,8 @@ export OVS_CTL_TIMEOUT # matter break everything. ASAN_OPTIONS=detect_leaks=0:abort_on_error=true:log_path=asan:$ASAN_OPTIONS export ASAN_OPTIONS + +# Add some default flags for UndefinedBehaviorSanitizer, if it was used +# for the build. +UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=true:log_path=ubsan:$UBSAN_OPTIONS +export UBSAN_OPTIONS diff --git a/tests/automake.mk b/tests/automake.mk index 43731d097354..d1e787c10c76 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -213,6 +213,7 @@ check-local: set $(SHELL) '$(TESTSUITE)' -C tests AUTOTEST_PATH=$(AUTOTEST_PATH); \ "$$@" $(TESTSUITEFLAGS) || \ (test -z "$$(find $(TESTSUITE_DIR) -name 'asan.*')" && \ + test -z "$$(find $(TESTSUITE_DIR) -name 'ubsan.*')" && \ test X'$(RECHECK)' = Xyes && "$$@" --recheck) # Python Coverage support. diff --git a/tests/daemon.at b/tests/daemon.at index 39d9aa391e9b..d7981f9d23a6 100644 --- a/tests/daemon.at +++ b/tests/daemon.at @@ -81,6 +81,10 @@ AT_SKIP_IF([test "$IS_WIN32" = "yes"]) # This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it. ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS +# Skip it if UB Sanitizer is being used. There's no way to disable the +# SEGV check at runtime. +AT_SKIP_IF([test $TESTS_WITH_UBSAN = yes]) + # Start the daemon and wait for the pidfile to get created. on_exit 'kill $(cat *.pid)' AT_CHECK([ovsdb-server --monitor --pidfile --no-db 2>/dev/null & echo $!], @@ -149,6 +153,10 @@ AT_SKIP_IF([test "$IS_WIN32" = "yes"]) # This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it. ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS +# Skip it if UB Sanitizer is being used. There's no way to disable the +# SEGV check at runtime. +AT_SKIP_IF([test $TESTS_WITH_UBSAN = yes]) + on_exit 'kill $(cat *.pid)' # Start the daemon and make sure that the pidfile exists immediately. diff --git a/tests/ovs-macros.at b/tests/ovs-macros.at index 66545da5728f..7899583f3c21 100644 --- a/tests/ovs-macros.at +++ b/tests/ovs-macros.at @@ -216,6 +216,11 @@ ovs_cleanup() { cat asan.* AT_FAIL_IF([:]) fi + if test "$(echo ubsan.*)" != 'ubsan.*'; then + echo "Undefined Behavior Sanitizer reported errors in:" ubsan.* + cat ubsan.* + AT_FAIL_IF([:]) + fi } ovs_wait () { diff --git a/tests/ovsdb-server.at b/tests/ovsdb-server.at index 2b742f78b079..1e00be60684b 100644 --- a/tests/ovsdb-server.at +++ b/tests/ovsdb-server.at @@ -292,6 +292,10 @@ AT_SKIP_IF([test "$IS_WIN32" = "yes"]) # This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it. ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS +# Skip it if UB Sanitizer is being used. There's no way to disable the +# SEGV check at runtime. +AT_SKIP_IF([test $TESTS_WITH_UBSAN = yes]) + # Start ovsdb-server, initially with one db. ordinal_schema > schema AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore]) @@ -327,6 +331,10 @@ AT_SKIP_IF([test "$IS_WIN32" = "yes"]) # This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it. ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS +# Skip it if UB Sanitizer is being used. There's no way to disable the +# SEGV check at runtime. +AT_SKIP_IF([test $TESTS_WITH_UBSAN = yes]) + # Start ovsdb-server, initially with one db. ordinal_schema > schema AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore]) @@ -477,6 +485,10 @@ AT_SKIP_IF([test "$IS_WIN32" = "yes"]) # This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it. ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS +# Skip it if UB Sanitizer is being used. There's no way to disable the +# SEGV check at runtime. +AT_SKIP_IF([test $TESTS_WITH_UBSAN = yes]) + # Start ovsdb-server, initially with no remotes. ordinal_schema > schema AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore]) @@ -512,6 +524,10 @@ AT_SKIP_IF([test "$IS_WIN32" = "yes"]) # This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it. ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS +# Skip it if UB Sanitizer is being used. There's no way to disable the +# SEGV check at runtime. +AT_SKIP_IF([test $TESTS_WITH_UBSAN = yes]) + # Start ovsdb-server, initially with no remotes. ordinal_schema > schema AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])