Skip to contentSkip to conversation

old buffer overflow in moxa driver

PATCH dann frazier 7 participants 10 messages Apr 30, 2007 – May 3, 2007 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

hey,
I noticed that the moxa input checking security bug described by
CVE-2005-0504 appears to remain unfixed upstream.

The issue is described here:
http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2005-0504

Debian has been shipping the following patch from Andres Salomon. I tried contacting the listed maintainer a few months ago but received no response.

I've tested that this still applies to and compiles against 2.6.21.

drivers/char/moxa.c +6 -2
index 7dbaee8..e0d35c2 100644
@@ -1582,7 +1582,7 @@ copy:
 
 	if(copy_from_user(&dltmp, argp, sizeof(struct dl_str)))
 		return -EFAULT;
-	if(dltmp.cardno < 0 || dltmp.cardno >= MAX_BOARDS)
+	if(dltmp.cardno < 0 || dltmp.cardno >= MAX_BOARDS || dltmp.len < 0)
 		return -EINVAL;
 
 	switch(cmd)
@@ -2529,6 +2529,8 @@ static int moxaloadbios(int cardno, unsigned char __user *tmp, int len)
 	void __iomem *baseAddr;
 	int i;
 
+	if(len < 0 || len > sizeof(moxaBuff))
+		return -EINVAL;
 	if(copy_from_user(moxaBuff, tmp, len))
 		return -EFAULT;
 	baseAddr = moxa_boards[cardno].basemem;
@@ -2576,7 +2578,7 @@ static int moxaload320b(int cardno, unsigned char __user *tmp, int len)
 	void __iomem *baseAddr;
 	int i;
 
-	if(len > sizeof(moxaBuff))
+	if(len < 0 || len > sizeof(moxaBuff))
 		return -EINVAL;
 	if(copy_from_user(moxaBuff, tmp, len))
 		return -EFAULT;
@@ -2596,6 +2598,8 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len)
 	void __iomem *baseAddr, *ofsAddr;
 	int retval, port, i;
 
+	if(len < 0 || len > sizeof(moxaBuff))
+		return -EINVAL;
 	if(copy_from_user(moxaBuff, tmp, len))
 		return -EFAULT;
 	baseAddr = moxa_boards[cardno].basemem;
Signature · 1 line
dann frazier
#1 lore raw
Quoted 9 lines

I noticed that the moxa input checking security bug described by
CVE-2005-0504 appears to remain unfixed upstream.

The issue is described here:
http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2005-0504

Debian has been shipping the following patch from Andres Salomon. I tried contacting the listed maintainer a few months ago but received no response.

       case MOXA_LOAD_BIOS:
        case MOXA_FIND_BOARD:
        case MOXA_LOAD_C320B:
        case MOXA_LOAD_CODE:
                if (!capable(CAP_SYS_RAWIO))
                        return -EPERM;
                break;

At the point you abuse these calls you can already just load arbitary data from userspace anyway.

#2 lore raw
Quoted 18 lines · On Tuesday 01 May 2007 02:04:55 Alan Cox wrote:
Quoted 9 lines

I noticed that the moxa input checking security bug described by
CVE-2005-0504 appears to remain unfixed upstream.

The issue is described here:
http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2005-0504

Debian has been shipping the following patch from Andres Salomon. I tried contacting the listed maintainer a few months ago but received no response.

       case MOXA_LOAD_BIOS:
        case MOXA_FIND_BOARD:
        case MOXA_LOAD_C320B:
        case MOXA_LOAD_CODE:
                if (!capable(CAP_SYS_RAWIO))
                        return -EPERM;
                break;
Quoted 2 lines

At the point you abuse these calls you can already just load arbitary data from userspace anyway.

So the possible exploit will only work when run by root, is that what you mean? If so isn't that still a security problem?

Sorry if I misunderstood what you said.

Regards,
ismail

#3 lore raw
Quoted 5 lines
Quoted 2 lines

At the point you abuse these calls you can already just load arbitary data from userspace anyway.

So the possible exploit will only work when run by root, is that what you mean? If so isn't that still a security problem?

To exploit the hole you need CAP_SYS_RAWIO which is the highest capability of all. CAP_SYS_RAWIO gives you the ability to access hardware directly so since it checks for CAP_SYS_RAWIO it isn't security.

The patch isn't wrong however and adds some sanity checking so it would do no harm to send it to Andrew for -mm testing.

Alan

#4 lore raw
Quoted 9 lines · Alan Cox
Quoted 5 lines
Quoted 2 lines

At the point you abuse these calls you can already just load arbitary data from userspace anyway.

So the possible exploit will only work when run by root, is that what you mean? If so isn't that still a security problem?

To exploit the hole you need CAP_SYS_RAWIO which is the highest capability of all. CAP_SYS_RAWIO gives you the ability to access hardware directly so since it checks for CAP_SYS_RAWIO it isn't security.

I understand that, but without it, the driver might seem buggy as far as the person with permissions can write bad values and cause BUG(). On the other hand if the user has CAP_SYS_RAWIO, he has access to /dev/{k,}mem anyway ;).

Quoted 2 lines

The patch isn't wrong however and adds some sanity checking so it would do no harm to send it to Andrew for -mm testing.

Yes.

regards,

Signature · 4 lines
http://www.fi.muni.cz/~xslaby/            Jiri Slaby
faculty of informatics, masaryk university, brno, cz
e-mail: jirislaby gmail com, gpg pubkey fingerprint:
B674 9967 0407 CE62 ACC8  22A0 32CC 55C3 39D4 7A7E
#5 lore raw
In reply to Alan Cox

Alan Cox napsal(a):

Quoted 19 lines
Quoted 9 lines

I noticed that the moxa input checking security bug described by
CVE-2005-0504 appears to remain unfixed upstream.

The issue is described here:
http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2005-0504

Debian has been shipping the following patch from Andres Salomon. I tried contacting the listed maintainer a few months ago but received no response.

       case MOXA_LOAD_BIOS:
        case MOXA_FIND_BOARD:
        case MOXA_LOAD_C320B:
        case MOXA_LOAD_CODE:
                if (!capable(CAP_SYS_RAWIO))
                        return -EPERM;
                break;
Quoted 2 lines

At the point you abuse these calls you can already just load arbitary data from userspace anyway.

The problem is that we BUG_ON, when len < 0 in copy_from_user which is unlikely something we want to cause?

regards,

Signature · 4 lines
http://www.fi.muni.cz/~xslaby/            Jiri Slaby
faculty of informatics, masaryk university, brno, cz
e-mail: jirislaby gmail com, gpg pubkey fingerprint:
B674 9967 0407 CE62 ACC8  22A0 32CC 55C3 39D4 7A7E
#6 lore raw
Quoted 19 lines · Jiri Slaby

Alan Cox napsal(a):

Quoted 18 lines
Quoted 9 lines

I noticed that the moxa input checking security bug described by
CVE-2005-0504 appears to remain unfixed upstream.

The issue is described here:
http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2005-0504

Debian has been shipping the following patch from Andres Salomon. I tried contacting the listed maintainer a few months ago but received no response.

       case MOXA_LOAD_BIOS:
        case MOXA_FIND_BOARD:
        case MOXA_LOAD_C320B:
        case MOXA_LOAD_CODE:
                if (!capable(CAP_SYS_RAWIO))
                        return -EPERM;
                break;
Quoted 7 lines
Quoted 2 lines

At the point you abuse these calls you can already just load arbitary data from userspace anyway.

The problem is that we BUG_ON, when len < 0 in copy_from_user which is unlikely something we want to cause?

regards,

Right; the lack of input checking is most definitely a bug. It's no longer a security issue, as a CAP_SYS_RAWIO check was added at some point to the code path, but it's still a bug.

#7 lore raw
Quoted 3 lines · Andres Salomon

Right; the lack of input checking is most definitely a bug. It's no longer a security issue, as a CAP_SYS_RAWIO check was added at some point to the code path, but it's still a bug.

I hadn't noticed this, but yes - the CAP_SYS_RAWIO check was added in 2.6.16.

Signature · 1 line
dann frazier | HP Open Source and Linux Organization
#8 lore raw
In reply to dann frazier

Wow, I'd forgotten all about this one.

Quoted 56 lines · dann frazier

hey,
I noticed that the moxa input checking security bug described by
CVE-2005-0504 appears to remain unfixed upstream.

The issue is described here:
http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2005-0504

Debian has been shipping the following patch from Andres Salomon. I tried contacting the listed maintainer a few months ago but received no response.

I've tested that this still applies to and compiles against 2.6.21.

drivers/char/moxa.c +6 -2
index 7dbaee8..e0d35c2 100644
@@ -1582,7 +1582,7 @@ copy:
 
 	if(copy_from_user(&dltmp, argp, sizeof(struct dl_str)))
 		return -EFAULT;
-	if(dltmp.cardno < 0 || dltmp.cardno >= MAX_BOARDS)
+	if(dltmp.cardno < 0 || dltmp.cardno >= MAX_BOARDS || dltmp.len < 0)
 		return -EINVAL;
 
 	switch(cmd)
@@ -2529,6 +2529,8 @@ static int moxaloadbios(int cardno, unsigned char __user *tmp, int len)
 	void __iomem *baseAddr;
 	int i;
 
+	if(len < 0 || len > sizeof(moxaBuff))
+		return -EINVAL;
 	if(copy_from_user(moxaBuff, tmp, len))
 		return -EFAULT;
 	baseAddr = moxa_boards[cardno].basemem;
@@ -2576,7 +2578,7 @@ static int moxaload320b(int cardno, unsigned char __user *tmp, int len)
 	void __iomem *baseAddr;
 	int i;
 
-	if(len > sizeof(moxaBuff))
+	if(len < 0 || len > sizeof(moxaBuff))
 		return -EINVAL;
 	if(copy_from_user(moxaBuff, tmp, len))
 		return -EFAULT;
@@ -2596,6 +2598,8 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len)
 	void __iomem *baseAddr, *ofsAddr;
 	int retval, port, i;
 
+	if(len < 0 || len > sizeof(moxaBuff))
+		return -EINVAL;
 	if(copy_from_user(moxaBuff, tmp, len))
 		return -EFAULT;
 	baseAddr = moxa_boards[cardno].basemem;
#9 lore raw
In reply to dann frazier
Quoted 48 lines · On Mon, 30 Apr 2007 16:48:29 -0600 dann frazier <[email protected]> wrote:

hey,
I noticed that the moxa input checking security bug described by
CVE-2005-0504 appears to remain unfixed upstream.

The issue is described here:
http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2005-0504

Debian has been shipping the following patch from Andres Salomon. I tried contacting the listed maintainer a few months ago but received no response.

I've tested that this still applies to and compiles against 2.6.21.

drivers/char/moxa.c +4 -2
index 7dbaee8..e0d35c2 100644
@@ -1582,7 +1582,7 @@ copy:
 
 	if(copy_from_user(&dltmp, argp, sizeof(struct dl_str)))
 		return -EFAULT;
-	if(dltmp.cardno < 0 || dltmp.cardno >= MAX_BOARDS)
+	if(dltmp.cardno < 0 || dltmp.cardno >= MAX_BOARDS || dltmp.len < 0)
 		return -EINVAL;
 
 	switch(cmd)
@@ -2529,6 +2529,8 @@ static int moxaloadbios(int cardno, unsigned char __user *tmp, int len)
 	void __iomem *baseAddr;
 	int i;
 
+	if(len < 0 || len > sizeof(moxaBuff))
+		return -EINVAL;
 	if(copy_from_user(moxaBuff, tmp, len))
 		return -EFAULT;
 	baseAddr = moxa_boards[cardno].basemem;
@@ -2576,7 +2578,7 @@ static int moxaload320b(int cardno, unsigned char __user *tmp, int len)
 	void __iomem *baseAddr;
 	int i;
 
-	if(len > sizeof(moxaBuff))
+	if(len < 0 || len > sizeof(moxaBuff))
 		return -EINVAL;
 	if(copy_from_user(moxaBuff, tmp, len))
 		return -EFAULT;

drivers/char/moxa.c static int moxaloadcode(int cardno, unsigned char __user *tmp, int len) · line 2605

Quoted 8 lines
drivers/char/moxa.c +2 -0
@@ -2596,6 +2598,8 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len)
 	void __iomem *baseAddr, *ofsAddr;
 	int retval, port, i;
 
+	if(len < 0 || len > sizeof(moxaBuff))
+		return -EINVAL;
 	if(copy_from_user(moxaBuff, tmp, len))
 		return -EFAULT;
 	baseAddr = moxa_boards[cardno].basemem;

I'm seeing copies of this patch floating around the internet from the 2.6.10 timeframe at least.

Could people please be more diligent about getting bugfixes back into mainline?