• J
    netlink: disable IRQs for netlink_lock_table() · 1e29968e
    Johannes Berg 提交于
    stable inclusion
    from stable-v5.10.44
    commit 1d6d43d4805da9b3fa0f5841e8b1083c89868f35
    bugzilla: https://bugzilla.openeuler.org/show_bug.cgi?id=369
    CVE: NA
    
    -------------------------------------------------
    
    [ Upstream commit 1d482e66 ]
    
    Syzbot reports that in mac80211 we have a potential deadlock
    between our "local->stop_queue_reasons_lock" (spinlock) and
    netlink's nl_table_lock (rwlock). This is because there's at
    least one situation in which we might try to send a netlink
    message with this spinlock held while it is also possible to
    take the spinlock from a hardirq context, resulting in the
    following deadlock scenario reported by lockdep:
    
           CPU0                    CPU1
           ----                    ----
      lock(nl_table_lock);
                                   local_irq_disable();
                                   lock(&local->queue_stop_reason_lock);
                                   lock(nl_table_lock);
      <Interrupt>
        lock(&local->queue_stop_reason_lock);
    
    This seems valid, we can take the queue_stop_reason_lock in
    any kind of context ("CPU0"), and call ieee80211_report_ack_skb()
    with the spinlock held and IRQs disabled ("CPU1") in some
    code path (ieee80211_do_stop() via ieee80211_free_txskb()).
    
    Short of disallowing netlink use in scenarios like these
    (which would be rather complex in mac80211's case due to
    the deep callchain), it seems the only fix for this is to
    disable IRQs while nl_table_lock is held to avoid hitting
    this scenario, this disallows the "CPU0" portion of the
    reported deadlock.
    
    Note that the writer side (netlink_table_grab()) already
    disables IRQs for this lock.
    
    Unfortunately though, this seems like a huge hammer, and
    maybe the whole netlink table locking should be reworked.
    
    Reported-by: syzbot+69ff9dff50dcfe14ddd4@syzkaller.appspotmail.com
    Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
    Signed-off-by: NDavid S. Miller <davem@davemloft.net>
    Signed-off-by: NSasha Levin <sashal@kernel.org>
    Signed-off-by: NYuan yi Qi <yuanyi_qh@163.com>
    Reviewed-by: Jian Cheng <cj.chengjian(a)huawei.com>
    Signed-off-by: NWang ShaoBo <bobo.shaobowang@huawei.com>
    1e29968e
af_netlink.c 68.0 KB