History

[NETLINK]: Synchronous message processing.

Let's recap the problem. The current asynchronous netlink kernel message processing is vulnerable to these attacks: 1) Hit and run: Attacker sends one or more messages and then exits before they're processed. This may confuse/disable the next netlink user that gets the netlink address of the attacker since it may receive the responses to the attacker's messages. Proposed solutions: a) Synchronous processing. b) Stream mode socket. c) Restrict/prohibit binding. 2) Starvation: Because various netlink rcv functions were written to not return until all messages have been processed on a socket, it is possible for these functions to execute for an arbitrarily long period of time. If this is successfully exploited it could also be used to hold rtnl forever. Proposed solutions: a) Synchronous processing. b) Stream mode socket. Firstly let's cross off solution c). It only solves the first problem and it has user-visible impacts. In particular, it'll break user space applications that expect to bind or communicate with specific netlink addresses (pid's). So we're left with a choice of synchronous processing versus SOCK_STREAM for netlink. For the moment I'm sticking with the synchronous approach as suggested by Alexey since it's simpler and I'd rather spend my time working on other things. However, it does have a number of deficiencies compared to the stream mode solution: 1) User-space to user-space netlink communication is still vulnerable. 2) Inefficient use of resources. This is especially true for rtnetlink since the lock is shared with other users such as networking drivers. The latter could hold the rtnl while communicating with hardware which causes the rtnetlink user to wait when it could be doing other things. 3) It is still possible to DoS all netlink users by flooding the kernel netlink receive queue. The attacker simply fills the receive socket with a single netlink message that fills up the entire queue. The attacker then continues to call sendmsg with the same message in a loop. Point 3) can be countered by retransmissions in user-space code, however it is pretty messy. In light of these problems (in particular, point 3), we should implement stream mode netlink at some point. In the mean time, here is a patch that implements synchronous processing.

Herbert Xu committed 21 years ago

Commit 2a0a6eb1 parent 96c36027 files · +55 −48Browse files

Showing the changes to kernel (1 of 7 files). Show all

Unified · Split

kernel/audit.c+8−11
@@ -427,7 +427,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · 426 unmodified lines
427427 /* Get message from skb (based on rtnetlink_rcv_skb). Each message is
428428 * processed by audit_receive_msg. Malformed skbs with wrong length are
429429 * discarded silently. */
430−static int audit_receive_skb(struct sk_buff *skb)
430+static void audit_receive_skb(struct sk_buff *skb)
431431 {
432432 int err;
433433 struct nlmsghdr *nlh;
@@ -436,7 +436,7 @@ static int audit_receive_skb(struct sk_buff *skb) · 2 unmodified lines
436436 while (skb->len >= NLMSG_SPACE(0)) {
437437 nlh = (struct nlmsghdr *)skb->data;
438438 if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len)
439− return 0;
439+ return;
440440 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
441441 if (rlen > skb->len)
442442 rlen = skb->len;
@@ -446,23 +446,20 @@ static int audit_receive_skb(struct sk_buff *skb) · 3 unmodified lines
446446 netlink_ack(skb, nlh, 0);
447447 skb_pull(skb, rlen);
448448 }
449− return 0;
450449 }
451450
452451 /* Receive messages from netlink socket. */
453452 static void audit_receive(struct sock *sk, int length)
454453 {
455454 struct sk_buff *skb;
455+ unsigned int qlen;
456456
457− if (down_trylock(&audit_netlink_sem))
458− return;
457+ down(&audit_netlink_sem);
459458
460− /* FIXME: this must not cause starvation */
461− while ((skb = skb_dequeue(&sk->sk_receive_queue))) {
462− if (audit_receive_skb(skb) && skb->len)
463− skb_queue_head(&sk->sk_receive_queue, skb);
464− else
465− kfree_skb(skb);
459+ for (qlen = skb_queue_len(&sk->sk_receive_queue); qlen; qlen--) {
460+ skb = skb_dequeue(&sk->sk_receive_queue);
461+ audit_receive_skb(skb);
462+ kfree_skb(skb);
466463 }
467464 up(&audit_netlink_sem);
468465 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t