From patchwork Mon Oct 14 18:31:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Saenz Julienne X-Patchwork-Id: 11189297 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D40EA14DB for ; Mon, 14 Oct 2019 18:32:54 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AC75620873 for ; Mon, 14 Oct 2019 18:32:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FMm7erfF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AC75620873 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=B4sIb5pIJOgKpz3CEimbDqyI8t4QgvayYgVySpMjBM4=; b=FMm7erfF3Ti7iP jfQzQYMUv+uWVxdLiOUEY/6RZUYLmXoWWB2Q7l9oDysB33xFuhb+o5zQB7HakpWH9ovc9A5q3dwi+ o8eX5m0eGw6Ucgr3W8sn6jrAczPYn8l3rFJwv1LTUE2W1Ey4wPNYjgQiZhd/Dej9wlfiwcaQhcgYE IPSQ5hKa3E7paZibE0FEInzVKm4Ei/t0B1b2QW/2wiixGEVyTB00WY7bSA1fXEWE1PDdloHVwiQ28 mhSY2wpXZD7lk14JF1VgQvISn4llDckVEt055Ew41IzT/U6iTNiJGKeUYoNbTna3UDAKMS5H0qKG8 S+rxRU99+uRYbkpWNBxg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iK59J-0007Dq-GY; Mon, 14 Oct 2019 18:32:53 +0000 Received: from mx2.suse.de ([195.135.220.15] helo=mx1.suse.de) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iK58L-0006FH-6d; Mon, 14 Oct 2019 18:31:54 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E3DD2BB7F; Mon, 14 Oct 2019 18:31:51 +0000 (UTC) From: Nicolas Saenz Julienne To: Robin Murphy , linux-arm-kernel@lists.infradead.org, bcm-kernel-feedback-list@broadcom.com, linux-rpi-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC 4/5] dma/direct: check for overflows in ARM's dma_capable() Date: Mon, 14 Oct 2019 20:31:06 +0200 Message-Id: <20191014183108.24804-5-nsaenzjulienne@suse.de> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191014183108.24804-1-nsaenzjulienne@suse.de> References: <20191014183108.24804-1-nsaenzjulienne@suse.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191014_113153_393437_8AF12608 X-CRM114-Status: GOOD ( 10.23 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [195.135.220.15 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: f.fainelli@gmail.com, Russell King , hch@infradead.org, mbrugger@suse.com, wahrenst@gmx.net, Nicolas Saenz Julienne Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The Raspberry Pi 4 has a 1GB ZONE_DMA area starting at address 0x00000000 and a mapping between physical and DMA memory offset by 0xc0000000. It transpires that, on non LPAE systems, any attempt to translate physical addresses outside of ZONE_DMA will result in an overflow. The resulting DMA addresses will not be detected by arm's dma_capable() as they still fit in the device's DMA mask. Fix this by failing to validate a DMA address smaller than the lowest possible DMA address. Signed-off-by: Nicolas Saenz Julienne --- arch/arm/include/asm/dma-direct.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm/include/asm/dma-direct.h b/arch/arm/include/asm/dma-direct.h index b67e5fc1fe43..ee8ad47a14e3 100644 --- a/arch/arm/include/asm/dma-direct.h +++ b/arch/arm/include/asm/dma-direct.h @@ -2,6 +2,8 @@ #ifndef ASM_ARM_DMA_DIRECT_H #define ASM_ARM_DMA_DIRECT_H 1 +#include + static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr) { unsigned int offset = paddr & ~PAGE_MASK; @@ -21,6 +23,10 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size) if (!dev->dma_mask) return 0; + /* Check if address overflowed */ + if (addr < __phys_to_dma(dev, PFN_UP(min_low_pfn))) + return 0; + mask = *dev->dma_mask; limit = (mask + 1) & ~mask;