Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3935214imm; Mon, 8 Oct 2018 11:57:40 -0700 (PDT) X-Google-Smtp-Source: ACcGV61Isvdrr2kQcWMqy/rqCTfvEO+KeRAxvbTYZCwdBKtWhuilrSNAKm9HP3z4oxTWH8O7Zkrm X-Received: by 2002:a65:53c9:: with SMTP id z9-v6mr22408007pgr.203.1539025059995; Mon, 08 Oct 2018 11:57:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539025059; cv=none; d=google.com; s=arc-20160816; b=VCIqyo7nYlkOZ4+ztzufBx4NW9UycnP2XlPHd9JWh9ZwvX8Jb1zV9SVhSeaVJLkg+q oqKisYym089Kv+VZG3492RdrmBoC2oFj9Ii5WPqk9Yv93Gc/Du03BMRPenKEFkwYHPLj SEAs8TBaymmMeTFY8eH5dhbnLjSc8AXWuyACcztKc8j4j1HnmXOShCx0AuLhJVsXx1v7 fqRfEqp7rP3tKkViQbeShLYaMmPe2z4eDtt8PJJZJtS/Qce+T/FnyjovsYKzEj1+JlYE g2BX8CzDRUGvd3q+l9JcSHdWS7FSsPGMePkkES1zFMFbqOoT3RZiWXisQtdDkfLKfnKk l8+g== 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=XitdSbeftexkjcXiXE/cptw/UOxOTYQpxqsRDP9EoLw=; b=MolS58JuA4+fP1ns5OZo/uTtk44tdefA0Oz8l++0WTph1N1jfWAgR96SygAUJk5FN2 GleJj65UoHvCXoVOsTgZMsfaF1JwVk/A3Im+CzsWXKtVxJXcnxhN8yCEyYdXUa2pgDha JtiS2KCDDqByoqtyvdpx9cxWlZ+ji4st5QVQSUcqPJwnPDufTnx8mz2ANB+lCbdNkTvN sMg3Iw16kHZmQfwuHFQX+o4AOBMUpsKrhfTbWa2oj++5K5vNNvapXCpgwO9beEdeZe8D B8n+H6OWuE9FVwbbt12Ndt9edJIjVtfsOnGscb33f3O5+npr+up+Ik9qspgGTZZ11AfM zgIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wyD+nQzL; 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 q23-v6si17868066pgj.229.2018.10.08.11.57.25; Mon, 08 Oct 2018 11:57:39 -0700 (PDT) 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=wyD+nQzL; 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 S1732716AbeJICGZ (ORCPT + 99 others); Mon, 8 Oct 2018 22:06:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:56770 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729253AbeJICGY (ORCPT ); Mon, 8 Oct 2018 22:06:24 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (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 697012087D; Mon, 8 Oct 2018 18:53:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024797; bh=1a3KgHOl0HYUol6glTiiVGXwbqWadMqBp8Aj4EAsnsM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wyD+nQzLJathr8f2pjjbtmbwuErnqHkIOFWxTqBNzqd5JrOBhgcW0/uHJSEpxThWi tqL4imXhZcwVhf0jyr3DdhNQ8VLekpdBiGNmrDxQq3CRUzjzlZfvlGVa0wG0Fxp6cZ CbJzDufZLawFlnqhk1vfEHQJCKK0UUgg34rc4o1M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Will Deacon , Arnd Bergmann , Andrew Murray , Sasha Levin Subject: [PATCH 4.18 139/168] asm-generic: io: Fix ioport_map() for !CONFIG_GENERIC_IOMAP && CONFIG_INDIRECT_PIO Date: Mon, 8 Oct 2018 20:31:59 +0200 Message-Id: <20181008175625.318696719@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175620.043587728@linuxfoundation.org> References: <20181008175620.043587728@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrew Murray [ Upstream commit 500dd232449e7c07500e713dc6970aa713f8e4f1 ] The !CONFIG_GENERIC_IOMAP version of ioport_map uses MMIO_UPPER_LIMIT to prevent users from making I/O accesses outside the expected I/O range - however it erroneously treats MMIO_UPPER_LIMIT as a mask which is contradictory to its other users. The introduction of CONFIG_INDIRECT_PIO, which subtracts an arbitrary amount from IO_SPACE_LIMIT to form MMIO_UPPER_LIMIT, results in ioport_map mangling the given port rather than capping it. We address this by aligning more closely with the CONFIG_GENERIC_IOMAP implementation of ioport_map by using the comparison operator and returning NULL where the port exceeds MMIO_UPPER_LIMIT. Though note that we preserve the existing behavior of masking with IO_SPACE_LIMIT such that we don't break existing buggy drivers that somehow rely on this masking. Fixes: 5745392e0c2b ("PCI: Apply the new generic I/O management on PCI IO hosts") Reported-by: Will Deacon Reviewed-by: Arnd Bergmann Signed-off-by: Andrew Murray Signed-off-by: Will Deacon Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- include/asm-generic/io.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/include/asm-generic/io.h +++ b/include/asm-generic/io.h @@ -1026,7 +1026,8 @@ static inline void __iomem *ioremap_wt(p #define ioport_map ioport_map static inline void __iomem *ioport_map(unsigned long port, unsigned int nr) { - return PCI_IOBASE + (port & MMIO_UPPER_LIMIT); + port &= IO_SPACE_LIMIT; + return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port; } #endif