netfilter: x_tables: fix cgroup matching on non-full sks
authorDaniel Borkmann <[email protected]>
Fri, 27 Mar 2015 18:37:41 +0000 (19:37 +0100)
committerPablo Neira Ayuso <[email protected]>
Wed, 1 Apr 2015 09:26:42 +0000 (11:26 +0200)
While originally only being intended for outgoing traffic, commit
a00e76349f35 ("netfilter: x_tables: allow to use cgroup match for
LOCAL_IN nf hooks") enabled xt_cgroups for the NF_INET_LOCAL_IN hook
as well, in order to allow for nfacct accounting.

Besides being currently limited to early demuxes only, commit
a00e76349f35 forgot to add a check if we deal with full sockets,
i.e. in this case not with time wait sockets. TCP time wait sockets
do not have the same memory layout as full sockets, a lower memory
footprint and consequently also don't have a sk_classid member;
probing for sk_classid member there could potentially lead to a
crash.

Fixes: a00e76349f35 ("netfilter: x_tables: allow to use cgroup match for LOCAL_IN nf hooks")
Cc: Alexey Perevalov <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Signed-off-by: Pablo Neira Ayuso <[email protected]>
net/netfilter/xt_cgroup.c

index 7198d660b4dea1e9e79c6f9a13f4e6669bca569d..a1d126f2946305a10ccc04ce92e469b1255f60f9 100644 (file)
@@ -39,7 +39,7 @@ cgroup_mt(const struct sk_buff *skb, struct xt_action_param *par)
 {
        const struct xt_cgroup_info *info = par->matchinfo;
 
-       if (skb->sk == NULL)
+       if (skb->sk == NULL || !sk_fullsock(skb->sk))
                return false;
 
        return (info->id == skb->sk->sk_classid) ^ info->invert;