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);