netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] infinite recursion in netlink
@ 2007-04-25 18:38 Alexey Kuznetsov
  2007-04-25 19:59 ` Greg KH
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Alexey Kuznetsov @ 2007-04-25 18:38 UTC (permalink / raw)
  To: davem, security, greg, netdev; +Cc: jaco

Hello!

Reply to NETLINK_FIB_LOOKUP messages were misrouted back to kernel,
which resulted in infinite recursion and stack overflow.

The bug is present in all kernel versions since the feature appeared.

The patch also makes some minimal cleanup:

1. Return something consistent (-ENOENT) when fib table is missing
2. Do not crash when queue is empty (does not happen, but yet)
3. Put result of lookup

Signed-off-by: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>


diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index fc920f6..cac06c4 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -776,6 +776,8 @@ static void nl_fib_lookup(struct fib_res
 				       .nl_u = { .ip4_u = { .daddr = frn->fl_addr,
 							    .tos = frn->fl_tos,
 							    .scope = frn->fl_scope } } };
+
+	frn->err = -ENOENT;
 	if (tb) {
 		local_bh_disable();
 
@@ -787,6 +789,7 @@ static void nl_fib_lookup(struct fib_res
 			frn->nh_sel = res.nh_sel;
 			frn->type = res.type;
 			frn->scope = res.scope;
+			fib_res_put(&res);
 		}
 		local_bh_enable();
 	}
@@ -801,6 +804,9 @@ static void nl_fib_input(struct sock *sk
 	struct fib_table *tb;
 
 	skb = skb_dequeue(&sk->sk_receive_queue);
+	if (skb == NULL)
+		return;
+
 	nlh = (struct nlmsghdr *)skb->data;
 	if (skb->len < NLMSG_SPACE(0) || skb->len < nlh->nlmsg_len ||
 	    nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*frn))) {
@@ -813,7 +819,7 @@ static void nl_fib_input(struct sock *sk
 
 	nl_fib_lookup(frn, tb);
 
-	pid = nlh->nlmsg_pid;           /*pid of sending process */
+	pid = NETLINK_CB(skb).pid;       /* pid of sending process */
 	NETLINK_CB(skb).pid = 0;         /* from kernel */
 	NETLINK_CB(skb).dst_group = 0;  /* unicast */
 	netlink_unicast(sk, skb, pid, MSG_DONTWAIT);

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2007-04-26 16:13 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-25 18:38 [PATCH] infinite recursion in netlink Alexey Kuznetsov
2007-04-25 19:59 ` Greg KH
2007-04-25 20:05   ` David Miller
2007-04-25 22:21   ` Jaco Kroon
2007-04-25 20:09 ` David Miller
2007-04-25 20:15 ` [Security] " Linus Torvalds
2007-04-25 20:18   ` David Miller
2007-04-26  5:29   ` Greg KH
2007-04-26  5:32     ` David Miller
2007-04-26  5:44       ` Greg KH
2007-04-26  5:48         ` Greg KH
2007-04-26  5:52           ` Chris Wright
2007-04-26  6:26             ` Chris Wright
2007-04-26  6:31               ` David Miller
2007-04-26  6:51                 ` Greg KH
2007-04-26  7:02                   ` David Miller
2007-04-26  5:37     ` Chris Wright
2007-04-26 15:44     ` [PATCH] [IPV4] nl_fib_lookup: Initialise res.r before fib_res_put(&res) Sergey Vlasov
2007-04-26 16:11       ` Alexey Kuznetsov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).