linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: akpm@linux-foundation.org, gregkh@linuxfoundation.org,
	linux-mm@kvack.org, linux@armlinux.org.uk, mcgrof@kernel.org,
	mm-commits@vger.kernel.org, nixiaoming@huawei.com,
	palmerdabbelt@google.com, stable@vger.kernel.org,
	torvalds@linux-foundation.org, wangkefeng.wang@huawei.com,
	wangliang101@huawei.com
Subject: [patch 7/7] lib: use PFN_PHYS() in devmem_is_allowed()
Date: Fri, 13 Aug 2021 16:54:45 -0700	[thread overview]
Message-ID: <20210813235445.iSOZmfuWE%akpm@linux-foundation.org> (raw)
In-Reply-To: <20210813165350.dc9afa56d27eadbd8ce629c0@linux-foundation.org>

From: Liang Wang <wangliang101@huawei.com>
Subject: lib: use PFN_PHYS() in devmem_is_allowed()

The physical address may exceed 32 bits on 32-bit systems with more than
32 bits of physcial address.  Use PFN_PHYS() in devmem_is_allowed(), or
the physical address may overflow and be truncated.

We found this bug when mapping a high addresses through devmem tool, when
CONFIG_STRICT_DEVMEM is enabled on the ARM with ARM_LPAE and devmem is
used to map a high address that is not in the iomem address range, an
unexpected error indicating no permission is returned.

This bug was initially introduced from v2.6.37, and the function was moved
to lib when v5.11.

Link: https://lkml.kernel.org/r/20210731025057.78825-1-wangliang101@huawei.com
Fixes: 087aaffcdf9c ("ARM: implement CONFIG_STRICT_DEVMEM by disabling access to RAM via /dev/mem")
Fixes: 527701eda5f1 ("lib: Add a generic version of devmem_is_allowed()")
Signed-off-by: Liang Wang <wangliang101@huawei.com>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Cc: Palmer Dabbelt <palmerdabbelt@google.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Liang Wang <wangliang101@huawei.com>
Cc: Xiaoming Ni <nixiaoming@huawei.com>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: <stable@vger.kernel.org>	[2.6.37+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 lib/devmem_is_allowed.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/lib/devmem_is_allowed.c~lib-use-pfn_phys-in-devmem_is_allowed
+++ a/lib/devmem_is_allowed.c
@@ -19,7 +19,7 @@
  */
 int devmem_is_allowed(unsigned long pfn)
 {
-	if (iomem_is_exclusive(pfn << PAGE_SHIFT))
+	if (iomem_is_exclusive(PFN_PHYS(pfn)))
 		return 0;
 	if (!page_is_ram(pfn))
 		return 1;
_


      parent reply	other threads:[~2021-08-13 23:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-13 23:53 incoming Andrew Morton
2021-08-13 23:54 ` [patch 1/7] kasan, kmemleak: reset tags when scanning block Andrew Morton
2021-08-13 23:54 ` [patch 2/7] kasan, slub: reset tag when printing address Andrew Morton
2021-08-13 23:54 ` [patch 3/7] slub: fix kmalloc_pagealloc_invalid_free unit test Andrew Morton
2021-08-13 23:54 ` [patch 4/7] mm: slub: fix slub_debug disabling for list of slabs Andrew Morton
2021-08-13 23:54 ` [patch 5/7] mm/madvise: report SIGBUS as -EFAULT for MADV_POPULATE_(READ|WRITE) Andrew Morton
2021-08-13 23:54 ` [patch 6/7] mm/memcg: fix incorrect flushing of lruvec data in obj_stock Andrew Morton
2021-08-13 23:54 ` Andrew Morton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210813235445.iSOZmfuWE%akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-mm@kvack.org \
    --cc=linux@armlinux.org.uk \
    --cc=mcgrof@kernel.org \
    --cc=mm-commits@vger.kernel.org \
    --cc=nixiaoming@huawei.com \
    --cc=palmerdabbelt@google.com \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=wangkefeng.wang@huawei.com \
    --cc=wangliang101@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).