From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5794415F36; Tue, 21 Jul 2026 18:17:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784657826; cv=none; b=LnNmIAhiEnnGGhTon1gDskyrX33xrQVgAtPpczXXsqn1xVdQRfRXop3OA3YAo73XYrjsXMPmSnQEUuNhudgmp0noUPreIxAQuHUBJnfisbqvfs1mFx3WdAtAGCCBEpDHRxzdrMpaL7bDPXLPxzB1zhorwmziwA58I8LAgIlOyHw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784657826; c=relaxed/simple; bh=HXb+Qmn8azFBBLgAiPvhcsaQX7tMtwDSjXZUfpLvIsQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AtB6YZyNsUxh6d/4uSx0TpzhIIX05C3AZePsRAOzsa7xLD+VR1xWR/mQNs48xVNWorx9Ho0G/6Lyrlez9Pn0CjiZUKU/Td5Pc/JQfIccqpFEhtU5gb+6q9BR8nofeJ5Z/a5ukQQoTqJQ0mKn+mYXQFL9V5ersw6XAx0Bb4eJVVM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=mPqrPT+r; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="mPqrPT+r" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D6D11F000E9; Tue, 21 Jul 2026 18:17:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784657825; bh=nNSgWz60sxOf6P22EZPms4veVOdKumG8nj/WxG7r4tc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mPqrPT+rrQwlCE30Ak4puqMfO0atLnefroR3lv68FUeY5lnA2SLYyBQhQ62W7D+gS nZtP+zRPgphOI6/iEX+aE14QMRaSl+/6QnbZPRBFbCds0RscnviyzAL6D+BcAWaUrn d23zoszye3WIaAasNseiEVwI6LlbmK6+xhSL84cU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Bjorn Helgaas , Magnus Lindholm , Shivaprasad G Bhat , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Sasha Levin Subject: [PATCH 6.18 0911/1611] alpha/PCI: Fix __pci_mmap_fits() overflow for zero-length BARs Date: Tue, 21 Jul 2026 17:17:07 +0200 Message-ID: <20260721152535.879294265@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152514.750365251@linuxfoundation.org> References: <20260721152514.750365251@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Krzysztof Wilczyński [ Upstream commit 802a3b3f470b9bc1148f26e01fc9cbfeb4dfcb57 ] Currently, __pci_mmap_fits() computes the BAR size using "pci_resource_len() - 1", which wraps to a large value when the BAR length is zero, causing the bounds check to incorrectly succeed. Add an early return for empty resources. Fixes: 10a0ef39fbd1 ("PCI/alpha: pci sysfs resources") Signed-off-by: Krzysztof Wilczyński Signed-off-by: Bjorn Helgaas Tested-by: Magnus Lindholm Tested-by: Shivaprasad G Bhat Reviewed-by: Ilpo Järvinen Acked-by: Magnus Lindholm Link: https://patch.msgid.link/20260508043543.217179-15-kwilczynski@kernel.org Signed-off-by: Sasha Levin --- arch/alpha/kernel/pci-sysfs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/alpha/kernel/pci-sysfs.c b/arch/alpha/kernel/pci-sysfs.c index 2324720c3e83fb..21833d1c867d78 100644 --- a/arch/alpha/kernel/pci-sysfs.c +++ b/arch/alpha/kernel/pci-sysfs.c @@ -37,12 +37,16 @@ static int hose_mmap_page_range(struct pci_controller *hose, static int __pci_mmap_fits(struct pci_dev *pdev, int num, struct vm_area_struct *vma, int sparse) { + resource_size_t len = pci_resource_len(pdev, num); unsigned long nr, start, size; int shift = sparse ? 5 : 0; + if (!len) + return 0; + nr = vma_pages(vma); start = vma->vm_pgoff; - size = ((pci_resource_len(pdev, num) - 1) >> (PAGE_SHIFT - shift)) + 1; + size = ((len - 1) >> (PAGE_SHIFT - shift)) + 1; if (start < size && size - start >= nr) return 1; -- 2.53.0