• Maxim Mikityanskiy's avatar
    sch_api: Don't skip qdisc attach on ingress · de2d807b
    Maxim Mikityanskiy authored
    The attach callback of struct Qdisc_ops is used by only a few qdiscs:
    mq, mqprio and htb. qdisc_graft() contains the following logic
    (pseudocode):
    
        if (!qdisc->ops->attach) {
            if (ingress)
                do ingress stuff;
            else
                do egress stuff;
        }
        if (!ingress) {
            ...
            if (qdisc->ops->attach)
                qdisc->ops->attach(qdisc);
        } else {
            ...
        }
    
    As we see, the attach callback is not called if the qdisc is being
    attached to ingress (TC_H_INGRESS). That wasn't a problem for mq and
    mqprio, since they contain a check that they are attached to TC_H_ROOT,
    and they can't be attached to TC_H_INGRESS anyway.
    
    However, the commit cited below added the attach callback to htb. It is
    needed for the hardware offload, but in the non-offload mode it
    simulates the "do egress stuff" part of the pseudocode above. The
    problem is that when htb is attached to ingress, neither "do ingress
    stuff" nor attach() is called. It results in an inconsistency, and the
    following message is printed to dmesg:
    
    unregister_netdevice: waiting for lo to become free. Usage count = 2
    
    This commit addresses the issue by running "do ingress stuff" in the
    ingress flow even in the attach callback is present, which is fine,
    because attach isn't going to be called afterwards.
    
    The bug was found by syzbot and reported by Eric.
    
    Fixes: d03b195b ("sch_htb: Hierarchical QoS hardware offload")
    Signed-off-by: default avatarMaxim Mikityanskiy <maximmi@nvidia.com>
    Reported-by: default avatarEric Dumazet <edumazet@google.com>
    Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    de2d807b
sch_api.c 54.5 KB