• Jiri Benc's avatar
    ipv6: prevent race between address creation and removal · 8a226b2c
    Jiri Benc authored
    There's a race in IPv6 automatic addess assignment. The address is created
    with zero lifetime when it's added to various address lists. Before it gets
    assigned the correct lifetime, there's a window where a new address may be
    configured. This causes the semi-initiated address to be deleted in
    addrconf_verify.
    
    This was discovered as a reference leak caused by concurrent run of
    __ipv6_ifa_notify for both RTM_NEWADDR and RTM_DELADDR with the same
    address.
    
    Fix this by setting the lifetime before the address is added to
    inet6_addr_lst.
    
    A few notes:
    
    1. In addrconf_prefix_rcv, by setting update_lft to zero, the
       if (update_lft) { ... } condition is no longer executed for newly
       created addresses. This is okay, as the ifp fields are set in
       ipv6_add_addr now and ipv6_ifa_notify is called (and has been called)
       through addrconf_dad_start.
    
    2. The removal of the whole block under ifp->lock in inet6_addr_add is okay,
       too, as tstamp is initialized to jiffies in ipv6_add_addr.
    Signed-off-by: default avatarJiri Benc <jbenc@redhat.com>
    Signed-off-by: default avatarJiri Pirko <jiri@resnulli.us>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    8a226b2c
addrconf.c 125 KB