Skip to contentSkip to conversation

properly check arguments to netlink_bind()

FIX NETLINK Holger Eitzenberger 2 participants 5 messages Sep 18, 2007 – Sep 19, 2007

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

Hi,

while going through going netlink code I found out that netlink_bind() does not properly check bind parameters. I checked both 2.6.23-rc1 as well as 2.6.16.53, both are affected.

With a small test prog I wasn't able to crash my maschine though, but data was accessed out of bounds.

Please apply the attached patch.

Thanks.

/holger

#1 lore raw
Quoted 6 lines · Holger Eitzenberger

while going through going netlink code I found out that netlink_bind() does not properly check bind parameters. I checked both 2.6.23-rc1 as well as 2.6.16.53, both are affected.

With a small test prog I wasn't able to crash my maschine though, but data was accessed out of bounds.

See my attached patch, thanks.

/holger

[NETLINK] Check for correct bind parameters

Before this change it was possible to pass less than sockaddr_nl bytes, which might lead to arbitrary data being accessed in netlink_bind().

---
commit 53ba94ab22cc3338d915d684ba1012fa0419ff14
tree 3a1b1dc6cb5dacac99722b9f96fe3ba4b2d29bde
parent f695baf2df9e0413d3521661070103711545207a
author Holger Eitzenberger <[email protected]> Mon, 17 Sep 2007 22:15:37 +0200 committer Holger Eitzenberger <holger@elmo.(none)> Mon, 17 Sep 2007 22:15:37 +0200

 net/netlink/af_netlink.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
net/netlink/af_netlink.c +3 -0
index 5681ce3..425543d 100644
@@ -598,6 +598,9 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr, int addr_len
 	struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr;
 	int err;
 
+	if (addr < sizeof(struct sockaddr_nl))
+		return -EINVAL;
+
 	if (nladdr->nl_family != AF_NETLINK)
 		return -EINVAL;
 
#2 lore raw

The previous patchlet wasn't correct, please apply this one.

Sorry for the noise.

/holger

[NETLINK] Check for correct bind parameters

Before this change it was possible to pass less than sockaddr_nl bytes, which might lead to arbitrary data being accessed in netlink_bind().

Take two.

---
commit 3155c34167184c31afeac2a061c0e0b9cd401d56
tree b5efe4234a5835e823b6b024f8d96e56f4abfd18
parent f695baf2df9e0413d3521661070103711545207a
author Holger Eitzenberger <[email protected]> Tue, 18 Sep 2007 23:10:11 +0200 committer Holger Eitzenberger <holger@elmo.(none)> Tue, 18 Sep 2007 23:10:11 +0200

 net/netlink/af_netlink.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
net/netlink/af_netlink.c +3 -0
index 5681ce3..5aaa9a7 100644
@@ -598,6 +598,9 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr, int addr_len
 	struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr;
 	int err;
 
+	if (addr_len < sizeof(struct sockaddr_nl))
+		return -EINVAL;
+
 	if (nladdr->nl_family != AF_NETLINK)
 		return -EINVAL;
 
maintainer
#3 lore raw
In reply to Holger Eitzenberger

From: Holger Eitzenberger <[email protected]>
Date: Tue, 18 Sep 2007 23:05:52 +0200

Quoted 10 lines
Quoted 6 lines · Holger Eitzenberger

while going through going netlink code I found out that netlink_bind() does not properly check bind parameters. I checked both 2.6.23-rc1 as well as 2.6.16.53, both are affected.

With a small test prog I wasn't able to crash my maschine though, but data was accessed out of bounds.

See my attached patch, thanks.

Your patch is incorrect and also unnecessary.

Firstly, you patch compares the address _pointer_ against the minimum length. That's obviously wrong.

And if you check the call sites of the protocol ->bind() methods, they all use on-stack buffer for the address object which is at least MAX_SOCK_ADDR bytes in length so that the bind methods don't have to check the size if they don't want to.

#4 lore raw
Quoted 6 lines · David Miller
Quoted 3 lines
Quoted 3 lines

while going through going netlink code I found out that netlink_bind() does not properly check bind parameters. I checked both 2.6.23-rc1 as well as 2.6.16.53, both are affected.

Firstly, you patch compares the address _pointer_ against the minimum length. That's obviously wrong.

True, the message send later fixed that.

Quoted 4 lines

And if you check the call sites of the protocol ->bind() methods, they all use on-stack buffer for the address object which is at least MAX_SOCK_ADDR bytes in length so that the bind methods don't have to check the size if they don't want to.

Also true, but in that case you still end up accessing uninitialized data. Also note that e. g. inet_bind() checks explicitely for that and it's not clear to me why netlink_bind() is different. Maybe you just help me figuring out.

Another point is that simply calling

bind(nl_fd, (struct sockaddr *)&an_int, sizeof(int));

will not return EINVAL but depends on the randomn data after an_int.

/holger