From patchwork Fri Jul 29 15:59:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 594363 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp1475721maz; Fri, 29 Jul 2022 09:01:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vpurIha0NKTBZR6tp7XN3lenHVnu0/CZbBGFXBbEulKIgB8s4RV+3rOmhoTbltVsBIi6Gc X-Received: by 2002:a05:622a:10a:b0:31f:1cf6:70d4 with SMTP id u10-20020a05622a010a00b0031f1cf670d4mr3868101qtw.139.1659110503877; Fri, 29 Jul 2022 09:01:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659110503; cv=none; d=google.com; s=arc-20160816; b=w6LcvZwWLzHlKVPP6XmxdS+dXXrhXVOdO0G4A+CdLpRkP11Zm45CYFk6WDJehfBd6A IsGL7X72NmnC65IKOm2LCVcsJ1IfepvksWWn2IaonYGjssCGtckuQ9C0QyldvlQ3Ancd kwsYkChcbiTdcF5RYQlt9zYysMGRSbc1Te9ceiP/9LAgyY0k5owqSZLZ7dyMjRjOHrIC TK2c54NANP7m1I2dBgKrg+kGkD52FuvrGtFeLhRl/QqeDeocPPqalAnW0jXSqV56cESF sT8tDrZb2IgmQIG6p6DsPzbe5rEGUpHvZsIzSyugMh79WwjYq3d315IlLk8EkYQ7dwn7 RLBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=XrT6CJtYpDChJQmlrXKLKRnBd08Xi8ZOtp9m/6/Dbzk=; b=k87H0kggComud09RfuFp6YPB59Tguh0ckfXehqcTNJAKaG7x4lGyV6aWH6aPQoDsMt aAzMzVu3exuDLR4r89hqLicO54aqdkc/GVBQslZPKQKT2r5fhO2HQ80sGGiE2ne2bNVd YtbPo0LggACHFkFz7m0bEdDtUDOHLDeJJNv6fdKnRt/MNrDW5FHmrIaOOz6tr3ML+pU/ HEMbHHK6vjNRzXOC8CDOrsMWDJkZs7v1TFH+paIF95JZ4Fi9gEKfs95zUTlgr4tLK05c k7QAsKezRiCNOFuBXLBfhZ+zfWkDXCbetcYoGqf2d2b7bbYmLOTMROy59H1N7CL6jTvv ipRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="d2QCH4/9"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id cg11-20020a05622a408b00b0031eeeced215si2534111qtb.12.2022.07.29.09.01.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 Jul 2022 09:01:43 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="d2QCH4/9"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHSQp-0005Jd-9v for patch@linaro.org; Fri, 29 Jul 2022 12:01:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHSOo-0005I1-Rj for qemu-devel@nongnu.org; Fri, 29 Jul 2022 11:59:38 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]:40682) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oHSOm-0001S6-OT for qemu-devel@nongnu.org; Fri, 29 Jul 2022 11:59:38 -0400 Received: by mail-wm1-x32c.google.com with SMTP id ay11-20020a05600c1e0b00b003a3013da120so4335669wmb.5 for ; Fri, 29 Jul 2022 08:59:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=XrT6CJtYpDChJQmlrXKLKRnBd08Xi8ZOtp9m/6/Dbzk=; b=d2QCH4/9fRdEZML3u2VPmUbEcer1Kt1jzOaWdt2d+96yweR2HwudHG5Q8MsurYjZZD wbud8ztkhbZm/P/OfUb9zeweF4iz0bjPfdCFWXYpmk7gous0EXxvBgNtV3Vmzv/5WhJT ognmDrloMUzwR47J27zx8EwICAogTuI/F/1yUIJj5JX6D/hCoDl7GQ9rbPSJ51yJ/WFe Tzkdpg9mB5IH8AKZjQw3iLRqyc700KrHA/Jj3c4YlxcDJCWJPFAnJZSajTWVbdkVVIHh opgwYMSPLwUHcE9TKjwPOlFYLUP935qb5ZAgBuSJgaVsVgUtFvisxZc79hH3v2NbTcz0 m5Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=XrT6CJtYpDChJQmlrXKLKRnBd08Xi8ZOtp9m/6/Dbzk=; b=MeYotG636GdFTowo0qX0JVtw2ye0xKUijn4MpCEhn34gFtMs4KyNTuwcBNAvIhB9w9 cUI9w5M0dHh7E/EYHB7Y2OWyAi3Itn9xM4+Mkn6BAldizyuwD7FhBBhKQ+yjuaUZgMOs ytJP8ZVAz9bkQeOAVwK2rjeCfmmUf7+1zAfk0F3mkCkUu+wYwaiMjlgeFpQEZz3NWlMC Y+ZRasVXrAx0qxGC7I4feir4zATQlX4kPOjCNbZF103wJ3Smc/TpV0KOgb3MPgEb2k3N NMLDiX+IwUFJmXmJoyteHn+a2I120HQZ/h/0PnzQtDcajl6E4p2iz2MPypVUobYVJAaI vASw== X-Gm-Message-State: AJIora8m0UZ8P9A6FU5reDhOkNj49d4uA4H0AjoK5GHgu1oRBNWPr1h6 hoCnaS6+vFRKKFuKKjc4xL0Z4F5/32nH7Q== X-Received: by 2002:a05:600c:2854:b0:3a3:1551:d7d with SMTP id r20-20020a05600c285400b003a315510d7dmr2854471wmb.174.1659110374868; Fri, 29 Jul 2022 08:59:34 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id y14-20020a5d620e000000b0021db7b0162esm4143699wru.105.2022.07.29.08.59.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 08:59:34 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Jiri Pirko , Jason Wang Subject: [PATCH] hw/net/rocker: Avoid undefined shifts with more than 31 ports Date: Fri, 29 Jul 2022 16:59:32 +0100 Message-Id: <20220729155932.2477385-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- 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 31f2340fb91..d8f3f16fe87 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 = r->fp_port[i]; if (fp_port_get_link_up(port)) { - status |= 1 << (i + 1); + status |= 1ULL << (i + 1); } } return status; @@ -1025,7 +1025,7 @@ static uint64_t rocker_port_phys_enable_read(Rocker *r) FpPort *port = r->fp_port[i]; if (fp_port_enabled(port)) { - ret |= 1 << (i + 1); + ret |= 1ULL << (i + 1); } } return ret;