Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8460753ybl; Thu, 16 Jan 2020 17:18:15 -0800 (PST) X-Google-Smtp-Source: APXvYqzsHAQRxeqYSyd06Ptq11THIffrPtfG4zE95NKfApF3jYP0UR9DQaFiebRTX/hNCgVZjGtE X-Received: by 2002:a05:6830:160c:: with SMTP id g12mr4353078otr.82.1579223895327; Thu, 16 Jan 2020 17:18:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579223895; cv=none; d=google.com; s=arc-20160816; b=V+DxjXW9tHDySna6gGbYC/AL8uG/aWCAYZ6RzNisZME/r0MknBJm4PtO44yX/4fY2/ N459uWRR0N/YWjJD2kaEyCYZHDTKEe1MSOoUMzm7WHPSeieOsvQUd52ZjQJs7PYxC3OZ 4/XoNiNlBsmA34aS3h7Hm8Y1xQdLTTT/OgfsC0Srk8bXjXxfh2OI2Owfe+Hqq6QjQPeM GQHfejZojqow6LGbZZQmgwocWSOHeY9OyqQrn/FGboDoC8mP+fI3XCePvDpyCVLI8iMk reUcttDq9IFxeEiXizp1s2Gis5UMhjBuVCbF1WYDbAAn/fMGVyuPuifFH/QNUqBswgs0 euFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=C1qpxyvmYLyIuJ1UYomZktT1E6prQ08R4jbHPZg6dWQ=; b=G+FO4q6nL6J0HhcH8SGwEDiiwRuRb3KrMU0FYQpuIeGrzKZP7759PbTyFUXhcyrUHQ ZgBkBt8WQzx1HY0KlTGZwPjkKR+3InY+YdHi3gwNILXznRSRRqzBPVFHG43YxjBeal3w kcFLULqIiZKFrVkDQUCNAvNe1mc5E3/Aq/+VjLqvlr9VngTGPi794l1IKa/QLlPOyaEz 010lUIXNNH06nbu5TQ+N8030B1CtCk2lvxHVih99wCQCFkmFHHOTKlWACfLI5+wzkkDt +zcPlpm+yJPCsx86h2D76MH8eEGeoooG0gRggy29IVr1pU0yUS2xlopA7MGC1kps67Re xmvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=alkvLSJF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 12si12085505oiz.131.2020.01.16.17.18.03; Thu, 16 Jan 2020 17:18:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=alkvLSJF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388125AbgAPXY3 (ORCPT + 99 others); Thu, 16 Jan 2020 18:24:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:53474 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387739AbgAPXY1 (ORCPT ); Thu, 16 Jan 2020 18:24:27 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 995F820748; Thu, 16 Jan 2020 23:24:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579217067; bh=CS1XRDACWBXXeycLKvho87XDFgutnA8XGJnE6lEdYBg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=alkvLSJFM9GcM0AxUhrzG27FR4vkwY09ZSWrZkk3LAZN+qWhs64msOtUUDY2saKlW 9LrCJQBUg/Ko5sDOOOn3aEWNqiUYTEnF8S5PB7KvsTIkpz/VKjNK1QN9NI5G7XMJiS X8F3W6OaTwIIJNP5xEbzF9vzBkq3xSvZ6VfvzUc4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bjorn Andersson , Niklas Cassel , Lorenzo Pieralisi , Andrew Murray , Gustavo Pimentel Subject: [PATCH 5.4 134/203] PCI: dwc: Fix find_next_bit() usage Date: Fri, 17 Jan 2020 00:17:31 +0100 Message-Id: <20200116231756.802005832@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200116231745.218684830@linuxfoundation.org> References: <20200116231745.218684830@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Niklas Cassel commit 1137e61dcb99f7f8b54e77ed83f68b5b485a3e34 upstream. find_next_bit() takes a parameter of size long, and performs arithmetic that assumes that the argument is of size long. Therefore we cannot pass a u32, since this will cause find_next_bit() to read outside the stack buffer and will produce the following print: BUG: KASAN: stack-out-of-bounds in find_next_bit+0x38/0xb0 Fixes: 1b497e6493c4 ("PCI: dwc: Fix uninitialized variable in dw_handle_msi_irq()") Tested-by: Bjorn Andersson Signed-off-by: Niklas Cassel Signed-off-by: Lorenzo Pieralisi Reviewed-by: Andrew Murray Acked-by: Gustavo Pimentel Signed-off-by: Greg Kroah-Hartman --- drivers/pci/controller/dwc/pcie-designware-host.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/drivers/pci/controller/dwc/pcie-designware-host.c +++ b/drivers/pci/controller/dwc/pcie-designware-host.c @@ -78,7 +78,8 @@ static struct msi_domain_info dw_pcie_ms irqreturn_t dw_handle_msi_irq(struct pcie_port *pp) { int i, pos, irq; - u32 val, num_ctrls; + unsigned long val; + u32 status, num_ctrls; irqreturn_t ret = IRQ_NONE; num_ctrls = pp->num_vectors / MAX_MSI_IRQS_PER_CTRL; @@ -86,14 +87,14 @@ irqreturn_t dw_handle_msi_irq(struct pci for (i = 0; i < num_ctrls; i++) { dw_pcie_rd_own_conf(pp, PCIE_MSI_INTR0_STATUS + (i * MSI_REG_CTRL_BLOCK_SIZE), - 4, &val); - if (!val) + 4, &status); + if (!status) continue; ret = IRQ_HANDLED; + val = status; pos = 0; - while ((pos = find_next_bit((unsigned long *) &val, - MAX_MSI_IRQS_PER_CTRL, + while ((pos = find_next_bit(&val, MAX_MSI_IRQS_PER_CTRL, pos)) != MAX_MSI_IRQS_PER_CTRL) { irq = irq_find_mapping(pp->irq_domain, (i * MAX_MSI_IRQS_PER_CTRL) +