From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BFE0C0650F for ; Mon, 5 Aug 2019 13:29:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ED8E220644 for ; Mon, 5 Aug 2019 13:29:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565011748; bh=OzrVIW2SNvPlP+RlL0NtWgabG5/XhuUEO1+3IKB8y7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=mGgx12oNYBTlZoLSsHIQ5/XpzDRAVARJ5E1V3NJHN9V55/JemSTlP7OTZmwGqdX3Q rUxTrP5DiYg/97IF2KOV/pDmeloen0RZOccfFqRmA8VbnTlQmvyjUL/Qq1/vot9S7a LORIAGCOH+B2jUr7wl6QzgnMhyiG7KM70gIMq6I8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730642AbfHENWQ (ORCPT ); Mon, 5 Aug 2019 09:22:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:58512 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730634AbfHENWN (ORCPT ); Mon, 5 Aug 2019 09:22:13 -0400 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 357222075B; Mon, 5 Aug 2019 13:22:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565011331; bh=OzrVIW2SNvPlP+RlL0NtWgabG5/XhuUEO1+3IKB8y7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r1qa/VCF1moZujjnq4aLfXXLjtEJ+1ztDPo9/mEQN2Rwc9KGRS1HA65BuCMnpZhIT nLvsnlnSEBTFI/heHq9rkrqXIkAhsOA9H43/ElrJ3hjrcOTrRCsNMsgR/k1nB7AXhX pPYUPUupgv53xknzuwMo2lvXQU8AUmZeuzOX9IiM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Doug Berger , Michal Nazarewicz , Yue Hu , Mike Rapoport , Laura Abbott , Peng Fan , Thomas Gleixner , Marek Szyprowski , Andrey Konovalov , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.2 053/131] mm/cma.c: fail if fixed declaration cant be honored Date: Mon, 5 Aug 2019 15:02:20 +0200 Message-Id: <20190805124954.979804900@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190805124951.453337465@linuxfoundation.org> References: <20190805124951.453337465@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 [ Upstream commit c633324e311243586675e732249339685e5d6faa ] The description of cma_declare_contiguous() indicates that if the 'fixed' argument is true the reserved contiguous area must be exactly at the address of the 'base' argument. However, the function currently allows the 'base', 'size', and 'limit' arguments to be silently adjusted to meet alignment constraints. This commit enforces the documented behavior through explicit checks that return an error if the region does not fit within a specified region. Link: http://lkml.kernel.org/r/1561422051-16142-1-git-send-email-opendmb@gmail.com Fixes: 5ea3b1b2f8ad ("cma: add placement specifier for "cma=" kernel parameter") Signed-off-by: Doug Berger Acked-by: Michal Nazarewicz Cc: Yue Hu Cc: Mike Rapoport Cc: Laura Abbott Cc: Peng Fan Cc: Thomas Gleixner Cc: Marek Szyprowski Cc: Andrey Konovalov Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/cma.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mm/cma.c b/mm/cma.c index 3340ef34c154a..4973d253dc83a 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -278,6 +278,12 @@ int __init cma_declare_contiguous(phys_addr_t base, */ alignment = max(alignment, (phys_addr_t)PAGE_SIZE << max_t(unsigned long, MAX_ORDER - 1, pageblock_order)); + if (fixed && base & (alignment - 1)) { + ret = -EINVAL; + pr_err("Region at %pa must be aligned to %pa bytes\n", + &base, &alignment); + goto err; + } base = ALIGN(base, alignment); size = ALIGN(size, alignment); limit &= ~(alignment - 1); @@ -308,6 +314,13 @@ int __init cma_declare_contiguous(phys_addr_t base, if (limit == 0 || limit > memblock_end) limit = memblock_end; + if (base + size > limit) { + ret = -EINVAL; + pr_err("Size (%pa) of region at %pa exceeds limit (%pa)\n", + &size, &base, &limit); + goto err; + } + /* Reserve memory */ if (fixed) { if (memblock_is_region_reserved(base, size) || -- 2.20.1