Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2750255ybh; Mon, 5 Aug 2019 06:16:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0wSPcedHRfqhRBUIICxEjyetndQ6WEtVj6FKIp1FvIt8TAV/mZs4Lh4M64MrI6AEL7fq9 X-Received: by 2002:a63:2ec9:: with SMTP id u192mr133404954pgu.16.1565010969836; Mon, 05 Aug 2019 06:16:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565010969; cv=none; d=google.com; s=arc-20160816; b=cMleWrGDOeQBbX/SVBtS0Zr/QFK9DYIuhT0Iofwamgf3brF19PWpjR/v1pT1G+EZkm TK3SWGrVoOokwvpNoiiogyoCOc1PGQQICeGb1Hje0ae2qEuZBLB1e2lTLzKrl5VNHSGk xH0Z2tNAKzFFMujWBgBI5dS202cERyUEM7x3ymHI+oLmIxMptxBsuHMZIqUFQNjHCi+M eVgX1nv2tlDPf7q7xGynjcF1zzP1DTO+TBgTYwt0XZ7IEO/32hfG6Pp2pf1XhfCPUQ1P bKXW9NHgVQD7ulaCwcDX5Nddl5WS8rXHU393A9jHN8B3CUazDkhe3MCHeaQUJWO8O/D8 uzhQ== 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=f43lvbD6uay4OeyBzGlUtJG+CykM9CJ1FGYuu+CdEQw=; b=z55EWSseMQvr3eBd+RE7o9aeyn3Fxw2gxqkgpZ6IRg3HJ392LyQxPKcRqK51ceS2UB TVnr2RhHr051mCZf3I2G852QqGc6MtoMlDbymF7lzeeIOWKSzzHHYZ5d2jGCb+mTX2VR Bbq/ZENd5rfCTnKZm2D8ZyiEEX/7vlXQxnciuLlasCY3WC0Xfotwx4xEzSPoub6rRh5b iRQayorHovZgvTyl+HfxZ0Rn/9+rwSEu4sH22BAGIbdBGLp/YU3jq63i4LSAvBZ/+BsQ CSJI7VRkGSeRFkeWQKVk28UIWOtKXjuVnWoTiiv888C8ITT5YwZv94OipoAmU6V+Ye6S K/bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LzUb+SWa; 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 f37si10783572pgb.225.2019.08.05.06.15.54; Mon, 05 Aug 2019 06:16:09 -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=LzUb+SWa; 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 S1729919AbfHENPY (ORCPT + 99 others); Mon, 5 Aug 2019 09:15:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:44662 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728884AbfHENHQ (ORCPT ); Mon, 5 Aug 2019 09:07:16 -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 3345F2173B; Mon, 5 Aug 2019 13:07:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565010435; bh=CPidt5qYrKRZHVWOKAKvDOcmkxJnxtGZPC+iMWtWdFI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LzUb+SWaKiaZjJbEqASoki4fC5bcTmZAv4P1wshiSrkPVUT661BtUW5kuCI2dQiq1 eZMkBoBGSZbU/NKKrGFVjPmy2cbPUjdoQ3e93GQaF19s2RF81IUqGYl3CgXXu08gHG mTZG9gxbz92/KMxG6NKFriqHnn7BUlgufvY+843I= 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 4.14 22/53] mm/cma.c: fail if fixed declaration cant be honored Date: Mon, 5 Aug 2019 15:02:47 +0200 Message-Id: <20190805124930.521354885@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190805124927.973499541@linuxfoundation.org> References: <20190805124927.973499541@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 56761e40d1918..c4a34c813d470 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -277,6 +277,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); @@ -307,6 +313,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