]> asedeno.scripts.mit.edu Git - linux.git/commit
netfilter: ipt_CLUSTERIP: fix use-after-free of proc entry
authorSabrina Dubroca <sd@queasysnail.net>
Tue, 18 Jul 2017 12:56:17 +0000 (14:56 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 19 Jul 2017 09:53:25 +0000 (11:53 +0200)
commit3840538ad384fb7891adeeaf36624f870c51fc0e
treedbc5a3421471d450deb7bd525294a94da466a993
parent073dd5ad34b1d3aaadaa7e5e8cbe576d9545f163
netfilter: ipt_CLUSTERIP: fix use-after-free of proc entry

When we delete a netns with a CLUSTERIP rule, clusterip_net_exit() is
called first, removing /proc/net/ipt_CLUSTERIP.
Then clusterip_config_entry_put() is called from clusterip_tg_destroy(),
and tries to remove its entry under /proc/net/ipt_CLUSTERIP/.

Fix this by checking that the parent directory of the entry to remove
hasn't already been deleted.

The following triggers a KASAN splat (stealing the reproducer from
202f59afd441, thanks to Jianlin Shi and Xin Long):

    ip netns add test
    ip link add veth0_in type veth peer name veth0_out
    ip link set veth0_in netns test
    ip netns exec test ip link set lo up
    ip netns exec test ip link set veth0_in up
    ip netns exec test iptables -I INPUT -d 1.2.3.4 -i veth0_in -j     \
        CLUSTERIP --new --clustermac 89:d4:47:eb:9a:fa --total-nodes 3 \
        --local-node 1 --hashmode sourceip-sourceport
    ip netns del test

Fixes: ce4ff76c15a8 ("netfilter: ipt_CLUSTERIP: make proc directory per net namespace")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Reviewed-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/ipv4/netfilter/ipt_CLUSTERIP.c