net: sched: fix action overwrite reference counting
authorVlad Buslov <vladbu@nvidia.com>
Wed, 7 Apr 2021 15:36:03 +0000 (18:36 +0300)
committerDavid S. Miller <davem@davemloft.net>
Thu, 8 Apr 2021 20:47:33 +0000 (13:47 -0700)
commit87c750e8c38bce706eb32e4d8f1e3402f2cebbd4
tree4d5c73cbd7a1b764b7af10521233a872b36c42c7
parent4ba86128ba077fbb7d86516ae24ed642e6c3adef
net: sched: fix action overwrite reference counting

Action init code increments reference counter when it changes an action.
This is the desired behavior for cls API which needs to obtain action
reference for every classifier that points to action. However, act API just
needs to change the action and releases the reference before returning.
This sequence breaks when the requested action doesn't exist, which causes
act API init code to create new action with specified index, but action is
still released before returning and is deleted (unless it was referenced
concurrently by cls API).

Reproduction:

$ sudo tc actions ls action gact
$ sudo tc actions change action gact drop index 1
$ sudo tc actions ls action gact

Extend tcf_action_init() to accept 'init_res' array and initialize it with
action->ops->init() result. In tcf_action_add() remove pointers to created
actions from actions array before passing it to tcf_action_put_many().

Fixes: cae422f379f3 ("net: sched: use reference counting action init")
Reported-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Vlad Buslov <vladbu@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/act_api.h
net/sched/act_api.c
net/sched/cls_api.c