nf_conntrack: avoid kernel pointer value leak in slab name
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 14 May 2016 18:11:44 +0000 (11:11 -0700)
committerBen Hutchings <ben@decadent.org.uk>
Wed, 15 Jun 2016 20:28:14 +0000 (21:28 +0100)
commit 31b0b385f69d8d5491a4bca288e25e63f1d945d0 upstream.

The slab name ends up being visible in the directory structure under
/sys, and even if you don't have access rights to the file you can see
the filenames.

Just use a 64-bit counter instead of the pointer to the 'net' structure
to generate a unique name.

This code will go away in 4.7 when the conntrack code moves to a single
kmemcache, but this is the backportable simple solution to avoiding
leaking kernel pointers to user space.

Fixes: 5b3501faa874 ("netfilter: nf_conntrack: per netns nf_conntrack_cachep")
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
net/netfilter/nf_conntrack_core.c

index 7489bd3..c855673 100644 (file)
@@ -1493,6 +1493,7 @@ err_proto:
 
 static int nf_conntrack_init_net(struct net *net)
 {
 
 static int nf_conntrack_init_net(struct net *net)
 {
+       static atomic64_t unique_id;
        int ret;
 
        atomic_set(&net->ct.count, 0);
        int ret;
 
        atomic_set(&net->ct.count, 0);
@@ -1504,7 +1505,8 @@ static int nf_conntrack_init_net(struct net *net)
                goto err_stat;
        }
 
                goto err_stat;
        }
 
-       net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
+       net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%llu",
+                               (u64)atomic64_inc_return(&unique_id));
        if (!net->ct.slabname) {
                ret = -ENOMEM;
                goto err_slabname;
        if (!net->ct.slabname) {
                ret = -ENOMEM;
                goto err_slabname;