From nobody Sun May 5 16:50:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1660036306; cv=none; d=zohomail.com; s=zohoarc; b=BAeE9t30+GAxHrOa2URqjJnvKd97XibC5OHYUX+uHxSnAocm9m9d9e+DUqyv7oRMLeY/xOIs9uXq6QtrpckHCV6lw1WMVB4ZNfllD1CyhuHwrNHVT00AgG+kkD7y8QuwFY3ud4EOCt05td5HJGp7p9hXfHAn1HaSeBqL4Vgoeiw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660036306; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sv2ylwUb77fjOOXBggXxwWMSrl9pFWc0E8Ej2Afz9ck=; b=HDD7uy1C6sG0NUFubO9cBTrT5xX+fvdLsNazW1PV9OL8g7xY3hMYSxGC44hzhOBtPmYRoK19r84tZ+Tj34n5rNYCkvIgQtFKnO1+4ZqT22sBJRDvwbUwcu0F4ebzdyIByzZbvmAZnwCd+aj22tNL+CvzRhimZoagOXRhdAahD3A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1660036306340711.0926473351051; Tue, 9 Aug 2022 02:11:46 -0700 (PDT) Received: from localhost ([::1]:53072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oLLH7-0003h6-9r for importer@patchew.org; Tue, 09 Aug 2022 05:11:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35504) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oLLEk-0001oH-UJ for qemu-devel@nongnu.org; Tue, 09 Aug 2022 05:09:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29892) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oLLEg-0005Yq-Bl for qemu-devel@nongnu.org; Tue, 09 Aug 2022 05:09:16 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-294-gRCh6sq9Plmk1e59YAs6Sg-1; Tue, 09 Aug 2022 05:09:08 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E951F8032F0; Tue, 9 Aug 2022 09:09:07 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-255.pek2.redhat.com [10.72.13.255]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F2C24010E3C; Tue, 9 Aug 2022 09:09:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660036150; 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=sv2ylwUb77fjOOXBggXxwWMSrl9pFWc0E8Ej2Afz9ck=; b=OFOVs2Q+0OvWfYG2dvyW3g8jEVNTG4KkLytrTPgSU3i4jOmR/qL//f9byUHMmkEpVpo9eR +eVKZ+zcx8RM+XC+LYob7UXSz5aUaa1EiVDjygk1/Om5ao4R2C3+gPUKQdyNZ9BGlrn/Hs ZOfFCJ5xTTKYC7NJTPJhJaNsLjm0NQ0= X-MC-Unique: gRCh6sq9Plmk1e59YAs6Sg-1 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Cc: Richard Henderson , Jason Wang Subject: [PULL] hw/net/rocker: Avoid undefined shifts with more than 31 ports Date: Tue, 9 Aug 2022 17:08:59 +0800 Message-Id: <20220809090859.28338-2-jasowang@redhat.com> In-Reply-To: <20220809090859.28338-1-jasowang@redhat.com> References: <20220809090859.28338-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1660036307411100001 Content-Type: text/plain; charset="utf-8" From: Peter Maydell In rocker_port_phys_link_status() and rocker_port_phys_enable_read() we construct a 64-bit value with one bit per front-panel port. However we accidentally do the shift as 32-bit arithmetic, which means that if there are more than 31 front-panel ports this is undefined behaviour. Fix the problem by ensuring we use 64-bit arithmetic for the whole calculation. (We won't ever shift off the 64-bit value because ROCKER_FP_PORTS_MAX is 62.) Resolves: Coverity CID 1487121, 1487160 Reviewed-by: Richard Henderson Signed-off-by: Peter Maydell Signed-off-by: Jason Wang --- hw/net/rocker/rocker.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c index 31f2340..d8f3f16 100644 --- a/hw/net/rocker/rocker.c +++ b/hw/net/rocker/rocker.c @@ -1010,7 +1010,7 @@ static uint64_t rocker_port_phys_link_status(Rocker *= r) FpPort *port =3D r->fp_port[i]; =20 if (fp_port_get_link_up(port)) { - status |=3D 1 << (i + 1); + status |=3D 1ULL << (i + 1); } } return status; @@ -1025,7 +1025,7 @@ static uint64_t rocker_port_phys_enable_read(Rocker *= r) FpPort *port =3D r->fp_port[i]; =20 if (fp_port_enabled(port)) { - ret |=3D 1 << (i + 1); + ret |=3D 1ULL << (i + 1); } } return ret; --=20 2.7.4