• Taehee Yoo's avatar
    mld: change lockdep annotation for ip6_sf_socklist and ipv6_mc_socklist · 4b4b8446
    Taehee Yoo authored
    struct ip6_sf_socklist and ipv6_mc_socklist are per-socket MLD data.
    These data are protected by rtnl lock, socket lock, and RCU.
    So, when these are used, it verifies whether rtnl lock is acquired or not.
    
    ip6_mc_msfget() is called by do_ipv6_getsockopt().
    But caller doesn't acquire rtnl lock.
    So, when these data are used in the ip6_mc_msfget() lockdep warns about it.
    But accessing these is actually safe because socket lock was acquired by
    do_ipv6_getsockopt().
    
    So, it changes lockdep annotation from rtnl lock to socket lock.
    (rtnl_dereference -> sock_dereference)
    
    Locking graph for mld data is like below:
    
    When writing mld data:
    do_ipv6_setsockopt()
        rtnl_lock
        lock_sock
        (mld functions)
            idev->mc_lock(if per-interface mld data is modified)
    
    When reading mld data:
    do_ipv6_getsockopt()
        lock_sock
        ip6_mc_msfget()
    
    Splat looks like:
    =============================
    WARNING: suspicious RCU usage
    5.12.0-rc4+ #503 Not tainted
    -----------------------------
    net/ipv6/mcast.c:610 suspicious rcu_dereference_protected() usage!
    
    other info that might help us debug this:
    
    rcu_scheduler_active = 2, debug_locks = 1
    1 lock held by mcast-listener-/923:
     #0: ffff888007958a70 (sk_lock-AF_INET6){+.+.}-{0:0}, at:
    ipv6_get_msfilter+0xaf/0x190
    
    stack backtrace:
    CPU: 1 PID: 923 Comm: mcast-listener- Not tainted 5.12.0-rc4+ #503
    Call Trace:
     dump_stack+0xa4/0xe5
     ip6_mc_msfget+0x553/0x6c0
     ? ipv6_sock_mc_join_ssm+0x10/0x10
     ? lockdep_hardirqs_on_prepare+0x3e0/0x3e0
     ? mark_held_locks+0xb7/0x120
     ? lockdep_hardirqs_on_prepare+0x27c/0x3e0
     ? __local_bh_enable_ip+0xa5/0xf0
     ? lock_sock_nested+0x82/0xf0
     ipv6_get_msfilter+0xc3/0x190
     ? compat_ipv6_get_msfilter+0x300/0x300
     ? lock_downgrade+0x690/0x690
     do_ipv6_getsockopt.isra.6.constprop.13+0x1809/0x29e0
     ? do_ipv6_mcast_group_source+0x150/0x150
     ? register_lock_class+0x1750/0x1750
     ? kvm_sched_clock_read+0x14/0x30
     ? sched_clock+0x5/0x10
     ? sched_clock_cpu+0x18/0x170
     ? find_held_lock+0x3a/0x1c0
     ? lock_downgrade+0x690/0x690
     ? ipv6_getsockopt+0xdb/0x1b0
     ipv6_getsockopt+0xdb/0x1b0
    [ ... ]
    
    Fixes: 88e2ca30 ("mld: convert ifmcaddr6 to RCU")
    Reported-by: default avatarEric Dumazet <edumazet@google.com>
    Signed-off-by: default avatarTaehee Yoo <ap420073@gmail.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    4b4b8446
mcast.c 75.9 KB