Skip to contentSkip to conversation

4 bytes kernel memory disclosure in SO_BSDCOMPAT gsopt try #2

PATCH Applied Clement LECIGNE 2 participants 2 messages Feb 12, 2009 – Feb 13, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 4 bytes kernel memory disclosure in SO_BSDCOMPAT gsopt try #2

Hi,

In function sock_getsockopt() located in net/core/sock.c, optval v.val is not correctly initialized and directly returned in userland in case we have SO_BSDCOMPAT option set.

This dummy code should trigger the bug:

int main(void)

{
	unsigned char buf[4] = { 0, 0, 0, 0 };
	int len;
	int sock;
	sock = socket(33, 2, 2);
	getsockopt(sock, 1, SO_BSDCOMPAT, &buf, &len);
	printf("%x%x%x%x\n", buf[0], buf[1], buf[2], buf[3]);
	close(sock);
}

Here is a patch that fix this bug by initalizing v.val just after its declaration.

net/core/sock.c renamed from net/core/sock.c.orig +2 -0
@@ -695,6 +695,8 @@ int sock_getsockopt(struct socket *sock,
 	if (len < 0)
 		return -EINVAL;
 
+	v.val = 0;
+
 	switch(optname) {
 	case SO_DEBUG:
 		v.val = sock_flag(sk, SOCK_DBG);
Signature · 2 lines
Clément LECIGNE,
"In Python, how do you create a string of random characters?" -- "Read a Perl file!"
maintainer Applied
#1 lore raw

From: Clement LECIGNE <[email protected]>
Date: Thu, 12 Feb 2009 13:35:45 +0100

Quoted 17 lines

In function sock_getsockopt() located in net/core/sock.c, optval v.val is not correctly initialized and directly returned in userland in case we have SO_BSDCOMPAT option set.

This dummy code should trigger the bug:

int main(void)

{
	unsigned char buf[4] = { 0, 0, 0, 0 };
	int len;
	int sock;
	sock = socket(33, 2, 2);
	getsockopt(sock, 1, SO_BSDCOMPAT, &buf, &len);
	printf("%x%x%x%x\n", buf[0], buf[1], buf[2], buf[3]);
	close(sock);
}
Quoted 1 line

Here is a patch that fix this bug by initalizing v.val just after its declaration.

Applied, thank you.