linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Finn Thain <fthain@telegraphics.com.au>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: <linux-m68k@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH 08/10] nubus: Fix pointer validation
Date: Sat,  8 Apr 2017 19:51:15 -0400 (EDT)	[thread overview]
Message-ID: <d3d345030d71b34e4e832a17a0302a56ec93eeff.1491695243.git.fthain@telegraphics.com.au> (raw)
In-Reply-To: <cover.1491695243.git.fthain@telegraphics.com.au>

Fix bounds checking on slot-space pointer movement.
Remove redundant test for zero byte-lanes value.
Fix broken byte-lanes vs. address validation.

Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
---
 drivers/nubus/nubus.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 1acf31c..eac5ec2 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -92,9 +92,6 @@ static void nubus_rewind(unsigned char **ptr, int len, int map)
 {
 	unsigned char *p=*ptr;
 
-	/* Sanity check */
-	if(len > 65536)
-		pr_err("rewind of 0x%08x!\n", len);
 	while(len)
 	{
 		do
@@ -110,8 +107,7 @@ static void nubus_rewind(unsigned char **ptr, int len, int map)
 static void nubus_advance(unsigned char **ptr, int len, int map)
 {
 	unsigned char *p = *ptr;
-	if(len>65536)
-		pr_err("advance of 0x%08x!\n", len);
+
 	while(len)
 	{
 		while(not_useful(p,map))
@@ -124,10 +120,15 @@ static void nubus_advance(unsigned char **ptr, int len, int map)
 
 static void nubus_move(unsigned char **ptr, int len, int map)
 {
+	unsigned long slot_space = (unsigned long)*ptr & 0xFF000000;
+
 	if(len > 0)
 		nubus_advance(ptr, len, map);
 	else if(len < 0)
 		nubus_rewind(ptr, -len, map);
+
+	if (((unsigned long)*ptr & 0xFF000000) != slot_space)
+		pr_err("%s: moved out of slot address space!\n", __func__);
 }
 
 /* Now, functions to read the sResource tree */
@@ -822,8 +823,6 @@ void __init nubus_probe_slot(int slot)
 			continue;
 
 		dp = *rp;
-		if(dp == 0)
-			continue;
 
 		/* The last byte of the format block consists of two
 		   nybbles which are "mirror images" of each other.
@@ -832,7 +831,7 @@ void __init nubus_probe_slot(int slot)
 			continue;
 		/* Check that this value is actually *on* one of the
 		   bytelanes it claims are valid! */
-		if ((dp & 0x0F) >= (1<<i))
+		if (not_useful(rp, dp))
 			continue;
 
 		/* Looks promising.  Let's put it on the list. */
-- 
2.10.2

  parent reply	other threads:[~2017-04-08 23:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-08 23:51 [PATCH 00/10] mac68k: Miscellaneous fixes, cleanup and modernization Finn Thain
2017-04-08 23:51 ` [PATCH 02/10] m68k/mac: Modernize printing of kernel messages Finn Thain
2017-04-08 23:51 ` [PATCH 07/10] nubus: Clean up printk calls (from mac68k CVS) Finn Thain
2017-04-08 23:51 ` [PATCH 01/10] m68k/mac: IOP - Modernize printing of kernel messages Finn Thain
2017-04-08 23:51 ` [PATCH 09/10] nubus: Clean up whitespace Finn Thain
2017-04-08 23:51 ` [PATCH 04/10] m68k/mac: Clarify IOP message alloc/free confusion Finn Thain
2017-04-08 23:51 ` [PATCH 10/10] nubus: Add MVC and VSC video card definitions Finn Thain
2017-04-08 23:51 ` [PATCH 03/10] m68k/mac: Adopt platform_device_register_simple() Finn Thain
2017-04-08 23:51 ` [PATCH 05/10] nubus: Fix nubus_rewinddir (from mac68k CVS) Finn Thain
2017-04-08 23:51 ` Finn Thain [this message]
2017-04-08 23:51 ` [PATCH 06/10] nubus: Remove slot zero probe " Finn Thain
2017-04-16 10:29 ` [PATCH 00/10] mac68k: Miscellaneous fixes, cleanup and modernization Geert Uytterhoeven
2017-04-17  1:50   ` Finn Thain
2017-04-20  7:56     ` Geert Uytterhoeven

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=d3d345030d71b34e4e832a17a0302a56ec93eeff.1491695243.git.fthain@telegraphics.com.au \
    --to=fthain@telegraphics.com.au \
    --cc=geert@linux-m68k.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-m68k@vger.kernel.org \
    /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).