linux-stable/net/openvswitch
Ilya Maximets 7438dc55c0 net: openvswitch: fix leak of nested actions
commit 1f30fb9166 upstream.

While parsing user-provided actions, openvswitch module may dynamically
allocate memory and store pointers in the internal copy of the actions.
So this memory has to be freed while destroying the actions.

Currently there are only two such actions: ct() and set().  However,
there are many actions that can hold nested lists of actions and
ovs_nla_free_flow_actions() just jumps over them leaking the memory.

For example, removal of the flow with the following actions will lead
to a leak of the memory allocated by nf_ct_tmpl_alloc():

  actions:clone(ct(commit),0)

Non-freed set() action may also leak the 'dst' structure for the
tunnel info including device references.

Under certain conditions with a high rate of flow rotation that may
cause significant memory leak problem (2MB per second in reporter's
case).  The problem is also hard to mitigate, because the user doesn't
have direct control over the datapath flows generated by OVS.

Fix that by iterating over all the nested actions and freeing
everything that needs to be freed recursively.

New build time assertion should protect us from this problem if new
actions will be added in the future.

Unfortunately, openvswitch module doesn't use NLA_F_NESTED, so all
attributes has to be explicitly checked.  sample() and clone() actions
are mixing extra attributes into the user-provided action list.  That
prevents some code generalization too.

Fixes: 34ae932a40 ("openvswitch: Make tunnel set action attach a metadata dst")
Link: https://mail.openvswitch.org/pipermail/ovs-dev/2022-March/392922.html
Reported-by: Stéphane Graber <stgraber@ubuntu.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Acked-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
[Backport for 4.19: Removed handling of OVS_ACTION_ATTR_DEC_TTL
 and OVS_ACTION_ATTR_CHECK_PKT_LEN as these actions do not exist
 in this version.  BUILD_BUG_ON condition adjusted accordingly.]
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-06-25 11:49:17 +02:00
..
actions.c net: openvswitch: fix misuse of the cached connection on tuple changes 2022-06-25 11:49:17 +02:00
conntrack.c net: openvswitch: fix misuse of the cached connection on tuple changes 2022-06-25 11:49:17 +02:00
conntrack.h openvswitch: Support conntrack zone limit 2018-05-25 16:45:19 -04:00
datapath.c openvswitch: remove another BUG_ON() 2019-12-05 09:21:31 +01:00
datapath.h openvswitch: Support conntrack zone limit 2018-05-25 16:45:19 -04:00
dp_notify.c openvswitch: reliable interface indentification in port dumps 2017-11-05 21:49:17 +09:00
flow.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-12-22 11:16:31 -05:00
flow.h openvswitch: enable NSH support 2017-11-08 16:12:33 +09:00
flow_netlink.c net: openvswitch: fix leak of nested actions 2022-06-25 11:49:17 +02:00
flow_netlink.h openvswitch: enable NSH support 2017-11-08 16:12:33 +09:00
flow_table.c
flow_table.h
Kconfig openvswitch: Support conntrack zone limit 2018-05-25 16:45:19 -04:00
Makefile openvswitch: Add meter infrastructure 2017-11-13 10:37:07 +09:00
meter.c openvswitch: meter: fix race when getting now_ms. 2021-06-03 08:38:11 +02:00
meter.h net: openvswitch: use u64 for meter bucket 2020-10-01 13:14:42 +02:00
vport-geneve.c
vport-gre.c
vport-internal_dev.c net: ovs: fix return type of ndo_start_xmit function 2019-11-24 08:19:17 +01:00
vport-internal_dev.h
vport-netdev.c
vport-netdev.h
vport-vxlan.c
vport.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
vport.h