nfnetlink: do not ack malformed messages
authorJiri Benc <jbenc@redhat.com>
Thu, 7 Nov 2013 18:59:19 +0000 (19:59 +0100)
committerDavid S. Miller <davem@davemloft.net>
Fri, 8 Nov 2013 20:12:11 +0000 (15:12 -0500)
Commit 0628b123c96d ("netfilter: nfnetlink: add batch support and use it
from nf_tables") introduced a bug leading to various crashes in netlink_ack
when netlink message with invalid nlmsg_len was sent by an unprivileged
user.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/netfilter/nfnetlink.c

index 027f16af51a0f1bde86b1805259166b4befa18ff..046aa13b4fea6a570b990444b7ca4c6419824f8f 100644 (file)
@@ -363,13 +363,15 @@ static void nfnetlink_rcv(struct sk_buff *skb)
        struct net *net = sock_net(skb->sk);
        int msglen;
 
-       if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
-               return netlink_ack(skb, nlh, -EPERM);
-
        if (nlh->nlmsg_len < NLMSG_HDRLEN ||
            skb->len < nlh->nlmsg_len)
                return;
 
+       if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) {
+               netlink_ack(skb, nlh, -EPERM);
+               return;
+       }
+
        if (nlh->nlmsg_type == NFNL_MSG_BATCH_BEGIN) {
                struct nfgenmsg *nfgenmsg;