linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers: char: mem: Fix thinko in kmem address checks
@ 2017-01-04 11:37 Robin Murphy
  2017-01-04 11:45 ` Greg KH
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Robin Murphy @ 2017-01-04 11:37 UTC (permalink / raw)
  To: gregkh, Jason; +Cc: linux-kernel, stable

When borrowing the pfn_valid() check from mmap_kmem(), somebody managed
to get physical and virtual addresses spectacularly muddled up, such
that we've ended up with checks for one being the other. Whilst this
does indeed prevent out-of-bounds accesses crashing, on most systems it
also prevents the more desirable use-case of working at all ever.

Check the *virtual* offset correctly for what it is.

Reported-by: Jason A. Donenfeld <Jason@zx2c4.com>
CC: stable@vger.kernel.org
Fixes: 148a1bc84398 ("drivers: char: mem: Check {read,write}_kmem() addresses")
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
 drivers/char/mem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 5bb1985ec484..bdc6a4018604 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -381,7 +381,7 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
 	char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
 	int err = 0;
 
-	if (!pfn_valid(PFN_DOWN(p)))
+	if (!virt_addr_valid(p))
 		return -EIO;
 
 	read = 0;
@@ -512,7 +512,7 @@ static ssize_t write_kmem(struct file *file, const char __user *buf,
 	char *kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */
 	int err = 0;
 
-	if (!pfn_valid(PFN_DOWN(p)))
+	if (!virt_addr_valid(p))
 		return -EIO;
 
 	if (p < (unsigned long) high_memory) {
-- 
2.10.2.dirty

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-01-11 19:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-04 11:37 [PATCH] drivers: char: mem: Fix thinko in kmem address checks Robin Murphy
2017-01-04 11:45 ` Greg KH
2017-01-04 17:19   ` Greg KH
2017-01-04 16:46 ` kbuild test robot
2017-01-05 17:15 ` [PATCH v2] drivers: char: mem: Fix thinkos " Robin Murphy
2017-01-10 17:49   ` Greg KH
2017-01-11 19:18     ` Jason A. Donenfeld

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).