]> git.baikalelectronics.ru Git - kernel.git/commit
net/sched: fix idr leak in the error path of tcf_vlan_init()
authorDavide Caratti <dcaratti@redhat.com>
Mon, 19 Mar 2018 14:31:27 +0000 (15:31 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 21 Mar 2018 22:12:27 +0000 (18:12 -0400)
commit0420f1470c56d31b379e818000b3235b41766d97
tree0d896a8d0fef849b6e1ce071ad81a99bb24cc8e0
parent1912471d0dbaf11d4c17d1db19a5e1299977aed0
net/sched: fix idr leak in the error path of tcf_vlan_init()

tcf_vlan_init() can fail after the idr has been successfully reserved.
When this happens, every subsequent attempt to configure vlan rules using
the same idr value will systematically fail with -ENOSPC, unless the first
attempt was done using the 'replace' keyword.

 # tc action add action vlan pop index 100
 RTNETLINK answers: Cannot allocate memory
 We have an error talking to the kernel
 # tc action add action vlan pop index 100
 RTNETLINK answers: No space left on device
 We have an error talking to the kernel
 # tc action add action vlan pop index 100
 RTNETLINK answers: No space left on device
 We have an error talking to the kernel
 ...

Fix this in tcf_vlan_init(), ensuring that tcf_idr_release() is called on
the error path when the idr has been reserved, but not yet inserted. Also,
don't test 'ovr' in the error path, to avoid a 'replace' failure implicitly
become a 'delete' that leaks refcount in act_vlan module:

 # rmmod act_vlan; modprobe act_vlan
 # tc action add action vlan push id 5 index 100
 # tc action replace action vlan push id 7 index 100
 RTNETLINK answers: Cannot allocate memory
 We have an error talking to the kernel
 # tc action list action vlan
 #
 # rmmod act_vlan
 rmmod: ERROR: Module act_vlan is in use

Fixes: f73c778d9e02 ("act_vlan: VLAN action rewrite to use RCU lock/unlock and update")
Fixes: de823360b9cf ("net/sched: Change act_api and act_xxx modules to use IDR")
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/sched/act_vlan.c