All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miles Chen <miles.chen@mediatek.com>
To: Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will.deacon@arm.com>
Cc: <linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>,
	<linux-mediatek@lists.infradead.org>, <wsd_upstream@mediatek.com>,
	Miles Chen <miles.chen@mediatek.com>
Subject: [PATCH] arm64: trap illegal translations in __virt_to_phys()
Date: Mon, 7 Jan 2019 19:21:20 +0800	[thread overview]
Message-ID: <1546860080-13027-1-git-send-email-miles.chen@mediatek.com> (raw)

Current __virt_to_phys() only print warning messages for non-linear
addresses. It's hard to catch all warnings by those messages. So add a
VIRTUAL_BUG_ON() to trap all non-linear and non-symbol addresses
(e.g., stack addresses)

Tested by pass stack addresses and symbol addresses to __pa(). Result:
stack addresses: kernel BUG()
symbol addresses: kernel warning message

Maybe we should trap all non-linear address translations in the future.

Signed-off-by: Miles Chen <miles.chen@mediatek.com>
---
 arch/arm64/mm/physaddr.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm64/mm/physaddr.c b/arch/arm64/mm/physaddr.c
index 67a9ba9eaa96..f6b935dad19c 100644
--- a/arch/arm64/mm/physaddr.c
+++ b/arch/arm64/mm/physaddr.c
@@ -14,6 +14,11 @@ phys_addr_t __virt_to_phys(unsigned long x)
 	      (void *)x,
 	      (void *)x);
 
+	/* trap all non-linear and non-symbol addresses */
+	VIRTUAL_BUG_ON(!__is_lm_address(x) &&
+			(x < (unsigned long)KERNEL_START ||
+			 x > (unsigned long)KERNEL_END));
+
 	return __virt_to_phys_nodebug(x);
 }
 EXPORT_SYMBOL(__virt_to_phys);
-- 
2.18.0


WARNING: multiple messages have this Message-ID (diff)
From: Miles Chen <miles.chen@mediatek.com>
To: Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will.deacon@arm.com>
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org,
	wsd_upstream@mediatek.com, Miles Chen <miles.chen@mediatek.com>
Subject: [PATCH] arm64: trap illegal translations in __virt_to_phys()
Date: Mon, 7 Jan 2019 19:21:20 +0800	[thread overview]
Message-ID: <1546860080-13027-1-git-send-email-miles.chen@mediatek.com> (raw)

Current __virt_to_phys() only print warning messages for non-linear
addresses. It's hard to catch all warnings by those messages. So add a
VIRTUAL_BUG_ON() to trap all non-linear and non-symbol addresses
(e.g., stack addresses)

Tested by pass stack addresses and symbol addresses to __pa(). Result:
stack addresses: kernel BUG()
symbol addresses: kernel warning message

Maybe we should trap all non-linear address translations in the future.

Signed-off-by: Miles Chen <miles.chen@mediatek.com>
---
 arch/arm64/mm/physaddr.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm64/mm/physaddr.c b/arch/arm64/mm/physaddr.c
index 67a9ba9eaa96..f6b935dad19c 100644
--- a/arch/arm64/mm/physaddr.c
+++ b/arch/arm64/mm/physaddr.c
@@ -14,6 +14,11 @@ phys_addr_t __virt_to_phys(unsigned long x)
 	      (void *)x,
 	      (void *)x);
 
+	/* trap all non-linear and non-symbol addresses */
+	VIRTUAL_BUG_ON(!__is_lm_address(x) &&
+			(x < (unsigned long)KERNEL_START ||
+			 x > (unsigned long)KERNEL_END));
+
 	return __virt_to_phys_nodebug(x);
 }
 EXPORT_SYMBOL(__virt_to_phys);
-- 
2.18.0

WARNING: multiple messages have this Message-ID (diff)
From: Miles Chen <miles.chen@mediatek.com>
To: Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will.deacon@arm.com>
Cc: Miles Chen <miles.chen@mediatek.com>,
	linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, wsd_upstream@mediatek.com
Subject: [PATCH] arm64: trap illegal translations in __virt_to_phys()
Date: Mon, 7 Jan 2019 19:21:20 +0800	[thread overview]
Message-ID: <1546860080-13027-1-git-send-email-miles.chen@mediatek.com> (raw)

Current __virt_to_phys() only print warning messages for non-linear
addresses. It's hard to catch all warnings by those messages. So add a
VIRTUAL_BUG_ON() to trap all non-linear and non-symbol addresses
(e.g., stack addresses)

Tested by pass stack addresses and symbol addresses to __pa(). Result:
stack addresses: kernel BUG()
symbol addresses: kernel warning message

Maybe we should trap all non-linear address translations in the future.

Signed-off-by: Miles Chen <miles.chen@mediatek.com>
---
 arch/arm64/mm/physaddr.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm64/mm/physaddr.c b/arch/arm64/mm/physaddr.c
index 67a9ba9eaa96..f6b935dad19c 100644
--- a/arch/arm64/mm/physaddr.c
+++ b/arch/arm64/mm/physaddr.c
@@ -14,6 +14,11 @@ phys_addr_t __virt_to_phys(unsigned long x)
 	      (void *)x,
 	      (void *)x);
 
+	/* trap all non-linear and non-symbol addresses */
+	VIRTUAL_BUG_ON(!__is_lm_address(x) &&
+			(x < (unsigned long)KERNEL_START ||
+			 x > (unsigned long)KERNEL_END));
+
 	return __virt_to_phys_nodebug(x);
 }
 EXPORT_SYMBOL(__virt_to_phys);
-- 
2.18.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

             reply	other threads:[~2019-01-07 11:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-07 11:21 Miles Chen [this message]
2019-01-07 11:21 ` [PATCH] arm64: trap illegal translations in __virt_to_phys() Miles Chen
2019-01-07 11:21 ` Miles Chen
2019-01-07 15:00 ` Mark Rutland
2019-01-07 15:00   ` Mark Rutland
2019-01-08  3:24   ` Miles Chen
2019-01-08  3:24     ` Miles Chen
2019-01-08  3:24     ` Miles Chen
2019-01-08 12:14     ` Mark Rutland
2019-01-08 12:14       ` Mark Rutland
2019-01-09  1:35       ` Miles Chen
2019-01-09  1:35         ` Miles Chen
2019-01-09  1:35         ` Miles Chen

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=1546860080-13027-1-git-send-email-miles.chen@mediatek.com \
    --to=miles.chen@mediatek.com \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=will.deacon@arm.com \
    --cc=wsd_upstream@mediatek.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.