Skip to contentSkip to conversation

fib: Fix out of bound access of fib_props[]

IPv4 Applied Thomas Graf 3 participants 6 messages Mar 24, 2007 – Apr 16, 2007

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

Fixes a typo which caused fib_props[] to have the wrong size and makes sure the value used to index the array which is provided by userspace via netlink is checked to avoid out of bound access.

net/ipv4/fib_frontend.c +5 -0
Index: net-2.6/net/ipv4/fib_frontend.c
===================================================================
@@ -493,6 +493,11 @@ static int rtm_to_fib_config(struct sk_b
 	cfg->fc_nlinfo.pid = NETLINK_CB(skb).pid;
 	cfg->fc_nlinfo.nlh = nlh;
 
+	if (cfg->fc_type > RTN_MAX) {
+		err = -EINVAL;
+		goto errout;
+	}
+
 	nlmsg_for_each_attr(attr, nlh, sizeof(struct rtmsg), remaining) {
 		switch (attr->nla_type) {
 		case RTA_DST:
net/ipv4/fib_semantics.c +1 -1
Index: net-2.6/net/ipv4/fib_semantics.c
===================================================================
@@ -89,7 +89,7 @@ static const struct
 {
 	int	error;
 	u8	scope;
-} fib_props[RTA_MAX + 1] = {
+} fib_props[RTN_MAX + 1] = {
 	{
 		.error	= 0,
 		.scope	= RT_SCOPE_NOWHERE,
maintainer Applied
#1 lore raw

From: Thomas Graf <[email protected]>
Date: Sat, 24 Mar 2007 16:34:36 +0100

Quoted 6 lines

Fixes a typo which caused fib_props[] to have the wrong size and makes sure the value used to index the array which is provided by userspace via netlink is checked to avoid out of bound access.

Applied, thanks.

#2 lore raw
Quoted 11 lines · David Miller

From: Thomas Graf <[email protected]>
Date: Sat, 24 Mar 2007 16:34:36 +0100

Quoted 6 lines

Fixes a typo which caused fib_props[] to have the wrong size and makes sure the value used to index the array which is provided by userspace via netlink is checked to avoid out of bound access.

Applied, thanks.

Thomas, David, it seems to me that 2.4 needs the same fix for the typo, but I see no place where we may add the check for > RTN_MAX. Maybe this last one is not needed. If someone could enlighten me, or at least provide a means to test if the bug it present, it would help me.

Thanks in advance,
Willy

#3 lore raw
Quoted 11 lines · Willy Tarreau
Quoted 10 lines · David Miller

From: Thomas Graf <[email protected]>
Date: Sat, 24 Mar 2007 16:34:36 +0100

Quoted 6 lines

Fixes a typo which caused fib_props[] to have the wrong size and makes sure the value used to index the array which is provided by userspace via netlink is checked to avoid out of bound access.

Quoted 7 lines
Quoted 1 line

Applied, thanks.

Thomas, David, it seems to me that 2.4 needs the same fix for the typo, but I see no place where we may add the check for > RTN_MAX. Maybe this last one is not needed. If someone could enlighten me, or at least provide a means to test if the bug it present, it would help me.

Finally, I think I have the correct fix below. Please someone confirm or tell me I'm nuts.

Thanks in advance,
Willy

Quoted 1 line

From 230c62b9e7000cfb407a079a21ad0f077f164b21 Mon Sep 17 00:00:00 2001

From: Willy Tarreau <[email protected]>
Date: Sat, 14 Apr 2007 17:44:03 +0200
Subject: [IPv4] fib: Fix out of bound access of fib_props[]

Backported from 2.6. Bug found and fixed by Thomas Graf :

Fixes a typo which caused fib_props[] to have the wrong size and makes sure the value used to index the array which is provided by userspace via netlink is checked to avoid out of bound access.

---
 net/ipv4/fib_semantics.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
net/ipv4/fib_semantics.c +6 -1
index afdf4bb..b930371 100644
@@ -83,7 +83,7 @@ static struct
 {
 	int	error;
 	u8	scope;
-} fib_props[RTA_MAX+1] = {
+} fib_props[RTN_MAX+1] = {
         { 0, RT_SCOPE_NOWHERE},		/* RTN_UNSPEC */
 	{ 0, RT_SCOPE_UNIVERSE},	/* RTN_UNICAST */
 	{ 0, RT_SCOPE_HOST},		/* RTN_LOCAL */
@@ -431,6 +431,11 @@ fib_create_info(const struct rtmsg *r, struct kern_rta *rta,
 	const int nhs = 1;
 #endif
 
+	if (r->rtm_type > RTN_MAX) {
+		err = -EINVAL;
+		goto errout;
+	}
+
 	/* Fast check to catch the most weird cases */
 	if (fib_props[r->rtm_type].scope > r->rtm_scope)
 		goto err_inval;
Signature · 1 line
1.4.4.4
#4 lore raw

* Willy Tarreau <[email protected]> 2007-04-14 17:48

Quoted 2 lines

Finally, I think I have the correct fix below. Please someone confirm or tell me I'm nuts.

Looks good, same is needed for DECnet

#5 lore raw
Quoted 5 lines · Thomas Graf

* Willy Tarreau <[email protected]> 2007-04-14 17:48

Quoted 2 lines

Finally, I think I have the correct fix below. Please someone confirm or tell me I'm nuts.

Looks good, same is needed for DECnet

Thank you Thomas.
The DECnet stuff was already merged, it was (expectedly) the same code.

Regards,
Willy