Skip to contentSkip to conversation

Fix buffer overflow in Omnikey CardMan 4040 driver

PATCH In review Marcel Holtmann 2 participants 2 messages Mar 6, 2007 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix buffer overflow in Omnikey CardMan 4040 driver

Hi Linus,

the attached patch fixes a buffer overflow in the Omnikey CardMan 4040 driver that could lead to a potential arbitrary code execution with kernel privileges.

Regards

Marcel

[PATCH] Fix buffer overflow in Omnikey CardMan 4040 driver (CVE-2007-0005)

Based on a patch from Don Howard <[email protected]>

When calling write() with a buffer larger than 512 bytes, the driver's write buffer overflows, allowing to overwrite the EIP and execute arbitrary code with kernel privileges.

In read(), there exists a similar problem, but coming from the device. A malicous or buggy device sending more than 512 bytes can overflow of the driver's read buffer, with the same effects as above.

---
commit 5be3f29dbb70cf7b3eaa5e1be6dfa553c98ea1ad
tree 158eb27c16e372650d7bc8c6536b46f052932148
parent c3442e296517aee733d62fc3fe03211598902c7d
author Marcel Holtmann <[email protected]> Tue, 06 Mar 2007 22:02:23 +0100 committer Marcel Holtmann <[email protected]> Tue, 06 Mar 2007 22:02:23 +0100

 drivers/char/pcmcia/cm4040_cs.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/char/pcmcia/cm4040_cs.c +2 -1
index 0e82968..f2e4ec4 100644
@@ -273,6 +273,7 @@ static ssize_t cm4040_read(struct file *filp, char __user *buf,
 	DEBUGP(6, dev, "BytesToRead=%lu\n", bytes_to_read);
 
 	min_bytes_to_read = min(count, bytes_to_read + 5);
+	min_bytes_to_read = min_t(size_t, min_bytes_to_read, READ_WRITE_BUFFER_SIZE);
 
 	DEBUGP(6, dev, "Min=%lu\n", min_bytes_to_read);
 
@@ -340,7 +341,7 @@ static ssize_t cm4040_write(struct file *filp, const char __user *buf,
 		return 0;
 	}
 
-	if (count < 5) {
+	if ((count < 5) || (count > READ_WRITE_BUFFER_SIZE)) {
 		DEBUGP(2, dev, "<- cm4040_write buffersize=%Zd < 5\n", count);
 		return -EIO;
 	}
#1 lore raw
Quoted 10 lines · Marcel Holtmann

Hi Linus,

the attached patch fixes a buffer overflow in the Omnikey CardMan 4040 driver that could lead to a potential arbitrary code execution with kernel privileges.

Regards

Marcel

- if (count < 5) {

+	if ((count < 5) || (count > READ_WRITE_BUFFER_SIZE)) {
		DEBUGP(2, dev, "<- cm4040_write buffersize=%Zd < 5\n", count);
		return -EIO;
	}

That debug message needs to be changed too since count won't always be < 5 when it's used.

Signature · 1 line
Simon Arlott