From patchwork Thu Mar 26 13:56:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 1262001 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: 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=hY2SWZYZ; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48p63q3H94z9sRY for ; Fri, 27 Mar 2020 00:56:55 +1100 (AEDT) Received: from localhost ([::1]:52244 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHT09-0004TN-Dk for incoming@patchwork.ozlabs.org; Thu, 26 Mar 2020 09:56:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60361) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHSzr-0004TH-TH for qemu-devel@nongnu.org; Thu, 26 Mar 2020 09:56:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHSzq-00088z-VS for qemu-devel@nongnu.org; Thu, 26 Mar 2020 09:56:35 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:43830) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jHSzq-00088q-S3 for qemu-devel@nongnu.org; Thu, 26 Mar 2020 09:56:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585230994; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fxngKB3n3H/APZAzYheqOCIOrULfa5FCCSkY14DVWqg=; b=hY2SWZYZHqU+oA7MsOe8rANtcg6dwKPY15mG+0677/3rWPUkgocU41MS7MRioiQ+mdiMGw 9duL2Pj5dSnBoaEhwsIBzC8fobrRE6FoABXUKmpgGmOG1dxWMGsQIg79dyNyRbCy5OLPUe YaP/LtE8BMU0zD+C1uIL4jI4vQpmrTM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-202-6pl3JBfnMwij3qs-iit3RA-1; Thu, 26 Mar 2020 09:56:31 -0400 X-MC-Unique: 6pl3JBfnMwij3qs-iit3RA-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 829BD189F763; Thu, 26 Mar 2020 13:56:30 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DFE646; Thu, 26 Mar 2020 13:56:27 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Subject: [PATCH] acpi: pcihp: fix left shift undefined behavior in acpi_pcihp_eject_slot() Date: Thu, 26 Mar 2020 09:56:24 -0400 Message-Id: <20200326135624.32464-1-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, mst@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Coverity spots subj in following guest triggered code path pci_write(, data = 0) -> acpi_pcihp_eject_slot(,slots = 0) uinst32_t slot = ctz32(slots) ... ... = ~(1U << slot) where 'slot' value is 32 in case 'slots' bitmap is empty. 'slots' is a bitmap and empty one shouldn't do anything so return early doing nothing if resulted slot value is not valid (i.e. not in 0-31 range) Reported-by: Peter Maydell Signed-off-by: Igor Mammedov --- hw/acpi/pcihp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c index 4dcef372bf..0dc963e983 100644 --- a/hw/acpi/pcihp.c +++ b/hw/acpi/pcihp.c @@ -154,7 +154,7 @@ static void acpi_pcihp_eject_slot(AcpiPciHpState *s, unsigned bsel, unsigned slo trace_acpi_pci_eject_slot(bsel, slot); - if (!bus) { + if (!bus || slot > 31) { return; }