From patchwork Thu Aug 10 09:19:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 13349096 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 400F9C001DE for ; Thu, 10 Aug 2023 09:20:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:References:MIME-Version:Message-Id:Date :Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: List-Owner; bh=Im2JcMjfA7pSTUXePFVi40aW96xhh4CB1bmu+CHZYxI=; b=q0mmJaIhuVb8dP y5gsOSDwhsC91J7uCM077QtcrdxOWOiZVtsxR+hcc7hTC2MvH4LISmsdm1BSumh10EFn/mw1YlAxr cXeMrMB9ZplGJOpk9nuMBNfa8Ns0QIZL0eHzf3KkZt2J3UHktGnWkw6vZ5wu6TSYm8P4nPCbdoS+R 5ux2jKpyAV7oTOqT1fh3eEGdoc4wFXOlF5DZ4IxjPunx6LWDNVaTbJFew6UDLpcj4B9q6rQRCsrbN 3X6kzGRnC/qxfJj205ANNngUNd6Xbri3fBKKqkg4gutxflO5+jeTS482zD33hcv320ANGWDb4gaNU HY4y6uSR5WDL8T6yaxpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qU1qE-006yBM-12; Thu, 10 Aug 2023 09:20:26 +0000 Received: from mailout2.w1.samsung.com ([210.118.77.12]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qU1qB-006y9t-24 for linux-arm-kernel@lists.infradead.org; Thu, 10 Aug 2023 09:20:25 +0000 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20230810092017euoutp02df0caf18a41cf437715e32f530e50e3d~5_xiHzx5H2723727237euoutp02Q for ; Thu, 10 Aug 2023 09:20:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20230810092017euoutp02df0caf18a41cf437715e32f530e50e3d~5_xiHzx5H2723727237euoutp02Q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1691659217; bh=QoClOrdI4RdByI00yXTFHg7j9E7DmiY7US96iwKAhaw=; h=From:To:Cc:Subject:Date:References:From; b=No8kffyMP8s/uzcC7VWFdYmmnTH7P0NcoRyPRUcGyT3Pu+rGmuo2IICzlkBn7yrQ+ WAjAcVBOcOC1Wzg928NF7JJAA5LpCUZWhvtE3MBkPUctHbaUQ5iXA856BglecJ18zV FGED3UoqIgDgLO8PM/75FFiwmC7Eg+8XHkKIdxK4= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20230810092017eucas1p18efdff903fca3c7dcc6d86863914493b~5_xh6JbFA3218732187eucas1p1d; Thu, 10 Aug 2023 09:20:17 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 41.CE.42423.1DBA4D46; Thu, 10 Aug 2023 10:20:17 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230810092017eucas1p23930e5e5ec443ac7776002f2f09967d4~5_xhnoU-F2123221232eucas1p2n; Thu, 10 Aug 2023 09:20:17 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230810092017eusmtrp16964dd133a8fc6ce491f9c5b24516a77~5_xhmuQQl0594805948eusmtrp1s; Thu, 10 Aug 2023 09:20:17 +0000 (GMT) X-AuditID: cbfec7f2-a3bff7000002a5b7-4f-64d4abd1b7af Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 3B.9B.10549.1DBA4D46; Thu, 10 Aug 2023 10:20:17 +0100 (BST) Received: from AMDC4653.eu.corp.samsungelectronics.net (unknown [106.120.51.32]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230810092016eusmtip12c5ea43f9dd13ae1e5edbf6ed97f6bf3~5_xhHr2NS2978429784eusmtip1P; Thu, 10 Aug 2023 09:20:16 +0000 (GMT) From: Marek Szyprowski To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Marek Szyprowski , Russell King , "Matthew Wilcox (Oracle)" , Andrew Morton , Mike Rapoport Subject: [PATCH] arm: dma-mapping: don't call folio_next() beyond the requested region Date: Thu, 10 Aug 2023 11:19:55 +0200 Message-Id: <20230810091955.3579004-1-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprFKsWRmVeSWpSXmKPExsWy7djPc7oXV19JMZiyW8Fizvo1bBabHl9j tbi8aw6bxaGpexkt1h65y25xZP12JovfP+awObB7XL52kdlj8wotj02rOtk8Tsz4zeKxeUm9 R9+WVYwenzfJBbBHcdmkpOZklqUW6dslcGXsPMdSsJqtom/fGvYGxumsXYycHBICJhJ7Jp5g 7mLk4hASWMEoseDlMTYI5wujxOxXjSwQzmdGiet7m+FaPl1eCdWynFFiw5kbLCAJIYFWJok3 5xhBbDYBQ4mut11sILaIgJvEjcYOJp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q9k7mLk4hASWMooceTgSyaIhIzE yWkNUEXCEn+udbFBFDUzSUy9up4NJMEmYCjR9bYLzBYR8JBo+3cPbBKzwC1GiQnb37GDJIQF wiQ+/HkINpVFQFVi8ve3jCA2r4C9xP5J91kgNshL7D94lhkiLihxcuYTsDgzULx562zmCYx8 s5CkZiFJLWBkWsUoklpanJueW2yoV5yYW1yal66XnJ+7iREY9NuO/dy8g3Heq496hxiZOBgP MUpwMCuJ8NoGX0oR4k1JrKxKLcqPLyrNSS0+xGgKdN9EZinR5Hxg3OWVxBuaGZgamphZGpha mhkrifN6FnQkCgmkJ5akZqemFqQWwfQxcXBKNTBVmHRuN1HYtD/lRGexmZnk0uQZMnHHfkx/ fc/0zSrrPfd+ejPua1+//5e1UcQryS+bzhjoRKYyNdk/uji/IfDcCzMG9WnTTuzRSVNKVpuz ZOI5sbX+1ofNcu5dvFAozzh/CuvLYE4zfacvR5//bygJSlunpRIrfUY+rUw/ZUf5ixrfJK0H k1cmb7tR5ie6MebYo6oGbdZ1113+hu6V7AgW6dc4t1fjo5Jb3IRLN7aKGu+dsNb5R//aPPsX d2epmGprfAhaUmg17YU6C2uVwt+2rYnMbhOvhJos+qiaaibP4ZdsutH5kml8r5lUx40ZkfeX hdYVy9lp8S2+ssYq3kdnx4PYo1s0ZJYuDxQ71KvEUpyRaKjFXFScCACv2/22AwMAAA== X-CMS-MailID: 20230810092017eucas1p23930e5e5ec443ac7776002f2f09967d4 X-Msg-Generator: CA X-RootMTR: 20230810092017eucas1p23930e5e5ec443ac7776002f2f09967d4 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230810092017eucas1p23930e5e5ec443ac7776002f2f09967d4 References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230810_022023_946642_245374AF X-CRM114-Status: GOOD ( 14.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a check for the non-zero offset case to avoid calling folio_next() beyond the requested region and relying on its parameters. Fixes: cc24e9c0895c ("arm: implement the new page table range API") Signed-off-by: Marek Szyprowski Suggested-by: Matthew Wilcox --- arch/arm/mm/dma-mapping.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 0474840224d9..6c952d6899f2 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -715,6 +715,8 @@ static void __dma_page_dev_to_cpu(struct page *page, unsigned long off, if (offset) { left -= folio_size(folio) - offset; + if (left <= 0) + return; folio = folio_next(folio); }