• Ido Schimmel's avatar
    net: ipv4: Fix memory leak in network namespace dismantle · c05bd0be
    Ido Schimmel authored
    [ Upstream commit f97f4dd8 ]
    
    IPv4 routing tables are flushed in two cases:
    
    1. In response to events in the netdev and inetaddr notification chains
    2. When a network namespace is being dismantled
    
    In both cases only routes associated with a dead nexthop group are
    flushed. However, a nexthop group will only be marked as dead in case it
    is populated with actual nexthops using a nexthop device. This is not
    the case when the route in question is an error route (e.g.,
    'blackhole', 'unreachable').
    
    Therefore, when a network namespace is being dismantled such routes are
    not flushed and leaked [1].
    
    To reproduce:
    # ip netns add blue
    # ip -n blue route add unreachable 192.0.2.0/24
    # ip netns del blue
    
    Fix this by not skipping error routes that are not marked with
    RTNH_F_DEAD when flushing the routing tables.
    
    To prevent the flushing of such routes in case #1, add a parameter to
    fib_table_flush() that indicates if the table is flushed as part of
    namespace dismantle or not.
    
    Note that this problem does not exist in IPv6 since error routes are
    associated with the loopback device.
    
    [1]
    unreferenced object 0xffff888066650338 (size 56):
      comm "ip", pid 1206, jiffies 4294786063 (age 26.235s)
      hex dump (first 32 bytes):
        00 00 00 00 00 00 00 00 b0 1c 62 61 80 88 ff ff  ..........ba....
        e8 8b a1 64 80 88 ff ff 00 07 00 08 fe 00 00 00  ...d............
      backtrace:
        [<00000000856ed27d>] inet_rtm_newroute+0x129/0x220
        [<00000000fcdfc00a>] rtnetlink_rcv_msg+0x397/0xa20
        [<00000000cb85801a>] netlink_rcv_skb+0x132/0x380
        [<00000000ebc991d2>] netlink_unicast+0x4c0/0x690
        [<0000000014f62875>] netlink_sendmsg+0x929/0xe10
        [<00000000bac9d967>] sock_sendmsg+0xc8/0x110
        [<00000000223e6485>] ___sys_sendmsg+0x77a/0x8f0
        [<000000002e94f880>] __sys_sendmsg+0xf7/0x250
        [<00000000ccb1fa72>] do_syscall_64+0x14d/0x610
        [<00000000ffbe3dae>] entry_SYSCALL_64_after_hwframe+0x49/0xbe
        [<000000003a8b605b>] 0xffffffffffffffff
    unreferenced object 0xffff888061621c88 (size 48):
      comm "ip", pid 1206, jiffies 4294786063 (age 26.235s)
      hex dump (first 32 bytes):
        6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b  kkkkkkkkkkkkkkkk
        6b 6b 6b 6b 6b 6b 6b 6b d8 8e 26 5f 80 88 ff ff  kkkkkkkk..&_....
      backtrace:
        [<00000000733609e3>] fib_table_insert+0x978/0x1500
        [<00000000856ed27d>] inet_rtm_newroute+0x129/0x220
        [<00000000fcdfc00a>] rtnetlink_rcv_msg+0x397/0xa20
        [<00000000cb85801a>] netlink_rcv_skb+0x132/0x380
        [<00000000ebc991d2>] netlink_unicast+0x4c0/0x690
        [<0000000014f62875>] netlink_sendmsg+0x929/0xe10
        [<00000000bac9d967>] sock_sendmsg+0xc8/0x110
        [<00000000223e6485>] ___sys_sendmsg+0x77a/0x8f0
        [<000000002e94f880>] __sys_sendmsg+0xf7/0x250
        [<00000000ccb1fa72>] do_syscall_64+0x14d/0x610
        [<00000000ffbe3dae>] entry_SYSCALL_64_after_hwframe+0x49/0xbe
        [<000000003a8b605b>] 0xffffffffffffffff
    
    Fixes: 8cced9ef ("[NETNS]: Enable routing configuration in non-initial namespace.")
    Signed-off-by: 's avatarIdo Schimmel <idosch@mellanox.com>
    Reviewed-by: 's avatarDavid Ahern <dsahern@gmail.com>
    Signed-off-by: 's avatarDavid S. Miller <davem@davemloft.net>
    Signed-off-by: 's avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    c05bd0be
Name
Last commit
Last update
..
9p Loading commit data...
bluetooth Loading commit data...
caif Loading commit data...
iucv Loading commit data...
netfilter Loading commit data...
netns Loading commit data...
nfc Loading commit data...
phonet Loading commit data...
sctp Loading commit data...
tc_act Loading commit data...
6lowpan.h Loading commit data...
Space.h Loading commit data...
act_api.h Loading commit data...
addrconf.h Loading commit data...
af_ieee802154.h Loading commit data...
af_rxrpc.h Loading commit data...
af_unix.h Loading commit data...
af_vsock.h Loading commit data...
ah.h Loading commit data...
arp.h Loading commit data...
atmclip.h Loading commit data...
ax25.h Loading commit data...
ax88796.h Loading commit data...
bond_3ad.h Loading commit data...
bond_alb.h Loading commit data...
bond_options.h Loading commit data...
bonding.h Loading commit data...
busy_poll.h Loading commit data...
calipso.h Loading commit data...
cfg80211-wext.h Loading commit data...
cfg80211.h Loading commit data...
cfg802154.h Loading commit data...
checksum.h Loading commit data...
cipso_ipv4.h Loading commit data...
cls_cgroup.h Loading commit data...
codel.h Loading commit data...
codel_impl.h Loading commit data...
codel_qdisc.h Loading commit data...
compat.h Loading commit data...
datalink.h Loading commit data...
dcbevent.h Loading commit data...
dcbnl.h Loading commit data...
devlink.h Loading commit data...
dn.h Loading commit data...
dn_dev.h Loading commit data...
dn_fib.h Loading commit data...
dn_neigh.h Loading commit data...
dn_nsp.h Loading commit data...
dn_route.h Loading commit data...
dsa.h Loading commit data...
dsfield.h Loading commit data...
dst.h Loading commit data...
dst_cache.h Loading commit data...
dst_metadata.h Loading commit data...
dst_ops.h Loading commit data...
erspan.h Loading commit data...
esp.h Loading commit data...
ethoc.h Loading commit data...
failover.h Loading commit data...
fib_notifier.h Loading commit data...
fib_rules.h Loading commit data...
firewire.h Loading commit data...
flow.h Loading commit data...
flow_dissector.h Loading commit data...
fou.h Loading commit data...
fq.h Loading commit data...
fq_impl.h Loading commit data...
garp.h Loading commit data...
gen_stats.h Loading commit data...
genetlink.h Loading commit data...
geneve.h Loading commit data...
gre.h Loading commit data...
gro_cells.h Loading commit data...
gtp.h Loading commit data...
gue.h Loading commit data...
hwbm.h Loading commit data...
icmp.h Loading commit data...
ieee80211_radiotap.h Loading commit data...
ieee802154_netdev.h Loading commit data...
if_inet6.h Loading commit data...
ife.h Loading commit data...
ila.h Loading commit data...
inet6_connection_sock.h Loading commit data...
inet6_hashtables.h Loading commit data...
inet_common.h Loading commit data...
inet_connection_sock.h Loading commit data...
inet_ecn.h Loading commit data...
inet_frag.h Loading commit data...
inet_hashtables.h Loading commit data...
inet_sock.h Loading commit data...
inet_timewait_sock.h Loading commit data...
inetpeer.h Loading commit data...
ip.h Loading commit data...
ip6_checksum.h Loading commit data...
ip6_fib.h Loading commit data...
ip6_route.h Loading commit data...
ip6_tunnel.h Loading commit data...
ip_fib.h Loading commit data...
ip_tunnels.h Loading commit data...
ip_vs.h Loading commit data...
ipcomp.h Loading commit data...
ipconfig.h Loading commit data...
ipv6.h Loading commit data...
ipv6_frag.h Loading commit data...
ipx.h Loading commit data...
iw_handler.h Loading commit data...
kcm.h Loading commit data...
l3mdev.h Loading commit data...
lag.h Loading commit data...
lapb.h Loading commit data...
lib80211.h Loading commit data...
llc.h Loading commit data...
llc_c_ac.h Loading commit data...
llc_c_ev.h Loading commit data...
llc_c_st.h Loading commit data...
llc_conn.h Loading commit data...
llc_if.h Loading commit data...
llc_pdu.h Loading commit data...
llc_s_ac.h Loading commit data...
llc_s_ev.h Loading commit data...
llc_s_st.h Loading commit data...
llc_sap.h Loading commit data...
lwtunnel.h Loading commit data...
mac80211.h Loading commit data...
mac802154.h Loading commit data...
mip6.h Loading commit data...
mld.h Loading commit data...
mpls.h Loading commit data...
mpls_iptunnel.h Loading commit data...
mrp.h Loading commit data...
ncsi.h Loading commit data...
ndisc.h Loading commit data...
neighbour.h Loading commit data...
net_failover.h Loading commit data...
net_namespace.h Loading commit data...
net_ratelimit.h Loading commit data...
netevent.h Loading commit data...
netlabel.h Loading commit data...
netlink.h Loading commit data...
netprio_cgroup.h Loading commit data...
netrom.h Loading commit data...
nexthop.h Loading commit data...
nl802154.h Loading commit data...
nsh.h Loading commit data...
p8022.h Loading commit data...
page_pool.h Loading commit data...
ping.h Loading commit data...
pkt_cls.h Loading commit data...
pkt_sched.h Loading commit data...
pptp.h Loading commit data...
protocol.h Loading commit data...
psample.h Loading commit data...
psnap.h Loading commit data...
raw.h Loading commit data...
rawv6.h Loading commit data...
red.h Loading commit data...
regulatory.h Loading commit data...
request_sock.h Loading commit data...
rose.h Loading commit data...
route.h Loading commit data...
rsi_91x.h Loading commit data...
rtnetlink.h Loading commit data...
sch_generic.h Loading commit data...
scm.h Loading commit data...
secure_seq.h Loading commit data...
seg6.h Loading commit data...
seg6_hmac.h Loading commit data...
seg6_local.h Loading commit data...
slhc_vj.h Loading commit data...
smc.h Loading commit data...
snmp.h Loading commit data...
sock.h Loading commit data...
sock_reuseport.h Loading commit data...
stp.h Loading commit data...
strparser.h Loading commit data...
switchdev.h Loading commit data...
tcp.h Loading commit data...
tcp_states.h Loading commit data...
timewait_sock.h Loading commit data...
tipc.h Loading commit data...
tls.h Loading commit data...
transp_v6.h Loading commit data...
tso.h Loading commit data...
tun_proto.h Loading commit data...
udp.h Loading commit data...
udp_tunnel.h Loading commit data...
udplite.h Loading commit data...
vsock_addr.h Loading commit data...
vxlan.h Loading commit data...
wext.h Loading commit data...
wimax.h Loading commit data...
x25.h Loading commit data...
x25device.h Loading commit data...
xdp.h Loading commit data...
xdp_sock.h Loading commit data...
xfrm.h Loading commit data...