From patchwork Mon Aug 4 02:58:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 34758 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f69.google.com (mail-pa0-f69.google.com [209.85.220.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 94CEF204FF for ; Mon, 4 Aug 2014 03:03:11 +0000 (UTC) Received: by mail-pa0-f69.google.com with SMTP id kx10sf47115777pab.4 for ; Sun, 03 Aug 2014 20:03:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=FICq+7BMDge/nJdVXL4Xc5xWLZ21UX+vO8Z2sINLXxQ=; b=IEUsY5b3Lx741NCK6clOvoyCPq4UCswdaB06olA0J+vXsVWaODwAhopRfCKzmoEyNh WuEQfK9CWj+3FTohZ1a/jG+T79jZZufKcZDaCB1ca0jx1XRF9ECKTYfuf8S+1OdjU6OQ hWpJEdoPYQ/a4X2FwsAg5wAaxgfTv4eki3FOcUcMFQFxuodBoFCykGvnzK8T0AK1BBeX 4zX0GHKzxEI7AFXcMMPEqXvf8s6j5H7PbWxyUsy3Ah1sp1d2qOc1CGpdeznYB5KX13Ab A/VckcnbidNspFD2qcIIjHYQHCo8HZN6U/7nlQHe3QZjFLtAwuJRcRYltVSy4bCe3HS9 tEgg== X-Gm-Message-State: ALoCoQkhoik9+eiLzGYFjg0cly1fG97thDANgUK1wfV9alTwXngmz8cG8S1yIynJWVVlYcvNaQxd X-Received: by 10.67.5.71 with SMTP id ck7mr8242935pad.9.1407121390874; Sun, 03 Aug 2014 20:03:10 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.81.169 with SMTP id f38ls1974401qgd.24.gmail; Sun, 03 Aug 2014 20:03:10 -0700 (PDT) X-Received: by 10.220.250.203 with SMTP id mp11mr20546534vcb.2.1407121390771; Sun, 03 Aug 2014 20:03:10 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id ti11si11259064vdb.10.2014.08.03.20.03.10 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 03 Aug 2014 20:03:10 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id hq11so10151029vcb.30 for ; Sun, 03 Aug 2014 20:03:10 -0700 (PDT) X-Received: by 10.220.182.73 with SMTP id cb9mr20747210vcb.9.1407121390657; Sun, 03 Aug 2014 20:03:10 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp267793vcb; Sun, 3 Aug 2014 20:03:10 -0700 (PDT) X-Received: by 10.68.176.5 with SMTP id ce5mr5562548pbc.93.1407121388852; Sun, 03 Aug 2014 20:03:08 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id kn9si16108254pbc.239.2014.08.03.20.03.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Aug 2014 20:03:08 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XE8X7-0008WQ-3D; Mon, 04 Aug 2014 03:01:57 +0000 Received: from mail-pd0-f171.google.com ([209.85.192.171]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XE8Wi-0007mf-1M for linux-arm-kernel@lists.infradead.org; Mon, 04 Aug 2014 03:01:36 +0000 Received: by mail-pd0-f171.google.com with SMTP id z10so8795419pdj.16 for ; Sun, 03 Aug 2014 20:01:10 -0700 (PDT) X-Received: by 10.70.35.67 with SMTP id f3mr11860621pdj.34.1407121270515; Sun, 03 Aug 2014 20:01:10 -0700 (PDT) Received: from localhost.localdomain ([98.126.25.141]) by mx.google.com with ESMTPSA id jb5sm15729523pbd.73.2014.08.03.20.01.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 03 Aug 2014 20:01:10 -0700 (PDT) From: Haojian Zhuang To: arnd@arndb.de, olof@lixom.net, marc.zyngier@arm.com, jason@lakedaemon.net, linux-arm-kernel@lists.infradead.org, nicolas.pitre@linaro.org, khilman@linaro.org, xuwei5@hisilicon.com, arm@kernel.org Subject: [PATCH v16 9/9] of: fdt: fix memory address be truncated Date: Mon, 4 Aug 2014 10:58:08 +0800 Message-Id: <1407121088-4151-10-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1407121088-4151-1-git-send-email-haojian.zhuang@linaro.org> References: <1407121088-4151-1-git-send-email-haojian.zhuang@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140803_200132_117993_EA587797 X-CRM114-Status: GOOD ( 11.36 ) X-Spam-Score: -1.4 (-) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-1.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.192.171 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.7 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.192.171 listed in wl.mailspike.net] Cc: Haojian Zhuang X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: haojian.zhuang@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 early_init_dt_add_memory_arch() accepts base & size parameters as u64 type. memblock_add() accepts base & size parameters as phys_addr_t type. But phys_addr_t isn't equal to u64. In 32-bit system, phys_addr_t is 32-bit long. If 64-bit memory address is specified in DTS file, it'll be truncated into 32-bit address. So create two values to store base & size first as phys_addr_t type. Then compare them with u64 base & u64 size. If they don't match, discard them. Signed-off-by: Haojian Zhuang --- drivers/of/fdt.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index c4cddf0..10d5382 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -878,6 +878,8 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size) { const u64 phys_offset = __pa(PAGE_OFFSET); + phys_addr_t mbase, msize; + base &= PAGE_MASK; size &= PAGE_MASK; if (base + size < phys_offset) { @@ -885,6 +887,14 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size) base, base + size); return; } + /* phys_addr_t may not be equal to u64 */ + mbase = base; + msize = size; + if ((mbase != base) || (msize != size)) { + pr_warning("Ignoring memory block 0x%llx - 0x%llx\n", + base, base + size); + return; + } if (base < phys_offset) { pr_warning("Ignoring memory range 0x%llx - 0x%llx\n", base, phys_offset);