• Vlad Buslov's avatar
    net: sched: fix err handler in tcf_action_init() · b3650bf7
    Vlad Buslov authored
    With recent changes that separated action module load from action
    initialization tcf_action_init() function error handling code was modified
    to manually release the loaded modules if loading/initialization of any
    further action in same batch failed. For the case when all modules
    successfully loaded and some of the actions were initialized before one of
    them failed in init handler. In this case for all previous actions the
    module will be released twice by the error handler: First time by the loop
    that manually calls module_put() for all ops, and second time by the action
    destroy code that puts the module after destroying the action.
    
    Reproduction:
    
    $ sudo tc actions add action simple sdata \"2\" index 2
    $ sudo tc actions add action simple sdata \"1\" index 1 \
                          action simple sdata \"2\" index 2
    RTNETLINK answers: File exists
    We have an error talking to the kernel
    $ sudo tc actions ls action simple
    total acts 1
    
            action order 0: Simple <"2">
             index 2 ref 1 bind 0
    $ sudo tc actions flush action simple
    $ sudo tc actions ls action simple
    $ sudo tc actions add action simple sdata \"2\" index 2
    Error: Failed to load TC action module.
    We have an error talking to the kernel
    $ lsmod | grep simple
    act_simple             20480  -1
    
    Fix the issue by modifying module reference counting handling in action
    initialization code:
    
    - Get module reference in tcf_idr_create() and put it in tcf_idr_release()
    instead of taking over the reference held by the caller.
    
    - Modify users of tcf_action_init_1() to always release the module
    reference which they obtain before calling init function instead of
    assuming that created action takes over the reference.
    
    - Finally, modify tcf_action_init_1() to not release the module reference
    when overwriting existing action as this is no longer necessary since both
    upper and lower layers obtain and manage their own module references
    independently.
    
    Fixes: d349f997 ("net_sched: fix RTNL deadlock again caused by request_module()")
    Suggested-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
    Signed-off-by: default avatarVlad Buslov <vladbu@nvidia.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    b3650bf7
cls_api.c 96.5 KB