linux-stable/net/sched
Davide Caratti bf92255468 net/sched: fix idr leak in the error path of tcf_skbmod_init()
[ Upstream commit f29cdfbe33 ]

tcf_skbmod_init() can fail after the idr has been successfully reserved.
When this happens, every subsequent attempt to configure skbmod 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 skbmod swap mac index 100
 RTNETLINK answers: Cannot allocate memory
 We have an error talking to the kernel
 # tc action add action skbmod swap mac index 100
 RTNETLINK answers: No space left on device
 We have an error talking to the kernel
 # tc action add action skbmod swap mac index 100
 RTNETLINK answers: No space left on device
 We have an error talking to the kernel
 ...

Fix this in tcf_skbmod_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_skbmod module:

 # rmmod act_skbmod; modprobe act_skbmod
 # tc action add action skbmod swap mac index 100
 # tc action add action skbmod swap mac continue index 100
 RTNETLINK answers: File exists
 We have an error talking to the kernel
 # tc action replace action skbmod swap mac continue index 100
 RTNETLINK answers: Cannot allocate memory
 We have an error talking to the kernel
 # tc action list action skbmod
 #
 # rmmod  act_skbmod
 rmmod: ERROR: Module act_skbmod is in use

Fixes: 65a206c01e ("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>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-05-30 07:52:18 +02:00
..
act_api.c net sched actions: fix dumping which requires several messages to user space 2018-04-12 12:32:23 +02:00
act_bpf.c net/sched: fix idr leak on the error path of tcf_bpf_init() 2018-05-30 07:52:18 +02:00
act_connmark.c Revert "net_sched: hold netns refcnt for each action" 2017-11-09 10:03:09 +09:00
act_csum.c net: accept UFO datagrams from tuntap and packet 2017-12-17 15:07:58 +01:00
act_gact.c net/sched: Fix update of lastuse in act modules implementing stats_update 2018-01-17 09:45:22 +01:00
act_ife.c net: sched: ife: handle malformed tlv length 2018-04-29 11:33:13 +02:00
act_ipt.c net/sched: fix idr leak in the error path of __tcf_ipt_init() 2018-05-30 07:52:18 +02:00
act_meta_mark.c
act_meta_skbprio.c
act_meta_skbtcindex.c
act_mirred.c net/sched: Fix update of lastuse in act modules implementing stats_update 2018-01-17 09:45:22 +01:00
act_nat.c Revert "net_sched: hold netns refcnt for each action" 2017-11-09 10:03:09 +09:00
act_pedit.c net/sched: fix idr leak in the error path of tcp_pedit_init() 2018-05-30 07:52:18 +02:00
act_police.c net/sched: fix idr leak in the error path of tcf_act_police_init() 2018-05-30 07:52:18 +02:00
act_sample.c net/sched: fix NULL dereference in the error path of tcf_sample_init() 2018-05-30 07:52:16 +02:00
act_simple.c net/sched: fix idr leak in the error path of tcf_simp_init() 2018-05-30 07:52:18 +02:00
act_skbedit.c Revert "net_sched: hold netns refcnt for each action" 2017-11-09 10:03:09 +09:00
act_skbmod.c net/sched: fix idr leak in the error path of tcf_skbmod_init() 2018-05-30 07:52:18 +02:00
act_tunnel_key.c net/sched: fix NULL dereference in the error path of tunnel_key_init() 2018-04-12 12:32:26 +02:00
act_vlan.c net/sched: fix refcnt leak in the error path of tcf_vlan_init() 2018-05-25 16:17:23 +02:00
cls_api.c net: sched: fix error path in tcf_proto_create() when modules are not configured 2018-05-19 10:20:26 +02:00
cls_basic.c cls_basic: use tcf_exts_get_net() before call_rcu() 2017-11-09 10:03:09 +09:00
cls_bpf.c cls_bpf: don't decrement net's refcount when offload fails 2017-12-17 15:07:59 +01:00
cls_cgroup.c cls_cgroup: use tcf_exts_get_net() before call_rcu() 2017-11-09 10:03:09 +09:00
cls_flow.c cls_flow: use tcf_exts_get_net() before call_rcu() 2017-11-09 10:03:09 +09:00
cls_flower.c cls_flower: use tcf_exts_get_net() before call_rcu() 2017-11-09 10:03:09 +09:00
cls_fw.c cls_fw: use tcf_exts_get_net() before call_rcu() 2017-11-09 10:03:09 +09:00
cls_matchall.c cls_matchall: use tcf_exts_get_net() before call_rcu() 2017-11-09 10:03:10 +09:00
cls_route.c cls_route: use tcf_exts_get_net() before call_rcu() 2017-11-09 10:03:10 +09:00
cls_rsvp.c
cls_rsvp.h cls_rsvp: use tcf_exts_get_net() before call_rcu() 2017-11-09 10:03:10 +09:00
cls_rsvp6.c
cls_tcindex.c cls_tcindex: use tcf_exts_get_net() before call_rcu() 2017-11-09 10:03:10 +09:00
cls_u32.c cls_u32: fix use after free in u32_destroy_key() 2018-03-08 22:41:16 -08:00
em_canid.c
em_cmp.c
em_ipset.c
em_meta.c
em_nbyte.c
em_text.c
em_u32.c
ematch.c
Kconfig
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sch_api.c net_sched: avoid matching qdisc with zero handle 2017-10-29 17:55:03 +09:00
sch_atm.c net_sched: remove tc class reference counting 2017-08-25 17:19:10 -07:00
sch_blackhole.c
sch_cbq.c net: sched: cbq: create block for q->link.block 2017-12-17 15:07:58 +01:00
sch_choke.c net_sched: red: Avoid illegal values 2018-02-25 11:07:59 +01:00
sch_codel.c
sch_drr.c net_sched: remove tc class reference counting 2017-08-25 17:19:10 -07:00
sch_dsmark.c net_sched: remove tc class reference counting 2017-08-25 17:19:10 -07:00
sch_fifo.c
sch_fq.c net_sched: fq: take care of throttled flows before reuse 2018-05-19 10:20:24 +02:00
sch_fq_codel.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-09-01 17:42:05 -07:00
sch_generic.c net: sched: drop qdisc_reset from dev_graft_qdisc 2018-03-19 08:42:54 +01:00
sch_gred.c net_sched: red: Avoid illegal values 2018-02-25 11:07:59 +01:00
sch_hfsc.c net_sched/hfsc: fix curve activation in hfsc_change_class() 2017-09-21 11:56:32 -07:00
sch_hhf.c sch_hhf: fix null pointer dereference on init failure 2017-08-30 15:26:11 -07:00
sch_htb.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-09-01 17:42:05 -07:00
sch_ingress.c net: sched: fix static key imbalance in case of ingress/clsact_init error 2018-01-02 20:31:12 +01:00
sch_mq.c net_sched: remove tc class reference counting 2017-08-25 17:19:10 -07:00
sch_mqprio.c net_sched: remove tc class reference counting 2017-08-25 17:19:10 -07:00
sch_multiq.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-09-01 17:42:05 -07:00
sch_netem.c sch_netem: fix skb leak in netem_enqueue() 2018-03-31 18:10:40 +02:00
sch_pie.c
sch_plug.c
sch_prio.c sched: Use __qdisc_drop instead of kfree_skb in sch_prio and sch_qfq 2017-09-06 21:20:07 -07:00
sch_qfq.c sched: Use __qdisc_drop instead of kfree_skb in sch_prio and sch_qfq 2017-09-06 21:20:07 -07:00
sch_red.c net: sched: red: avoid hashing NULL child 2018-05-25 16:17:23 +02:00
sch_sfb.c net_sched: remove tc class reference counting 2017-08-25 17:19:10 -07:00
sch_sfq.c net_sched: red: Avoid illegal values 2018-02-25 11:07:59 +01:00
sch_tbf.c net: sched: red: avoid hashing NULL child 2018-05-25 16:17:23 +02:00
sch_teql.c