All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net 0/6] Ocelot VCAP fixes
@ 2022-05-03 11:57 Vladimir Oltean
  2022-05-03 11:57 ` [PATCH net 1/6] net: mscc: ocelot: don't use list_empty() on non-initialized list element Vladimir Oltean
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Vladimir Oltean @ 2022-05-03 11:57 UTC (permalink / raw)
  To: netdev
  Cc: Jakub Kicinski, David S. Miller, Paolo Abeni, Eric Dumazet,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver,
	Xiaoliang Yang, Colin Foster

This series fixes issues found while running
tools/testing/selftests/net/forwarding/tc_actions.sh on the ocelot
switch:

- NULL pointer dereference when failing to offload a filter
- NULL pointer dereference after deleting a trap
- filters still having effect after being deleted
- dropped packets still being seen by software
- statistics counters showing double the amount of hits
- statistics counters showing inexistent hits
- invalid configurations not rejected

Vladimir Oltean (6):
  net: mscc: ocelot: don't use list_empty() on non-initialized list
    element
  net: mscc: ocelot: avoid use after free with deleted tc-trap rules
  net: mscc: ocelot: fix last VCAP IS1/IS2 filter persisting in hardware
    when deleted
  net: mscc: ocelot: fix VCAP IS2 filters matching on both lookups
  net: mscc: ocelot: restrict tc-trap actions to VCAP IS2 lookup 0
  net: mscc: ocelot: avoid corrupting hardware counters when moving VCAP
    filters

 drivers/net/ethernet/mscc/ocelot_flower.c | 10 ++++++++--
 drivers/net/ethernet/mscc/ocelot_vcap.c   | 11 ++++++++++-
 2 files changed, 18 insertions(+), 3 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH net 1/6] net: mscc: ocelot: don't use list_empty() on non-initialized list element
  2022-05-03 11:57 [PATCH net 0/6] Ocelot VCAP fixes Vladimir Oltean
@ 2022-05-03 11:57 ` Vladimir Oltean
  2022-05-03 11:57 ` [PATCH net 2/6] net: mscc: ocelot: avoid use after free with deleted tc-trap rules Vladimir Oltean
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Vladimir Oltean @ 2022-05-03 11:57 UTC (permalink / raw)
  To: netdev
  Cc: Jakub Kicinski, David S. Miller, Paolo Abeni, Eric Dumazet,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver,
	Xiaoliang Yang, Colin Foster

Since the blamed commit, VCAP filters can appear on more than one list.
If their action is "trap", they are chained on ocelot->traps via
filter->trap_list.

Consequently, when we free a VCAP filter, we must remove it from all
lists it is a member of, including ocelot->traps.

Normally, conditionally removing an element from a list (depending on
whether it is present or not) involves traversing the list, but we
already have a reference to the element, so that isn't really necessary.
Moreover, the operation "list_del(&filter->trap_list)" operation is
fundamentally the same regardless of whether we've iterated through the
list or just happened to have the element. So I thought it would be ok
to check whether the element has been added to a list by calling
list_empty().

However, this does not do the correct thing. list_empty() checks whether
"head->next == head", but in our case, head->next == head->prev == NULL,
and head != NULL. This makes us proceed to call list_del(), which
modifies the prev pointer of the next element, and the next pointer of
the prev element. But the next and prev elements are NULL, so we
dereference those pointers and die.

It would appear that list_empty() is not the function to use to detect
that condition. But if we had previously called INIT_LIST_HEAD() on
&filter->trap_list, then we could use list_empty() to denote whether we
are members of a list (any list).

Although the more "natural" thing seems to be to iterate through
ocelot->traps and only remove the filter from the list if it was a
member of it, it seems pointless to do that.

So fix the bug by calling INIT_LIST_HEAD() on the non-head element.

Fixes: e42bd4ed09aa ("net: mscc: ocelot: keep traps in a list")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 drivers/net/ethernet/mscc/ocelot_flower.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/ethernet/mscc/ocelot_flower.c b/drivers/net/ethernet/mscc/ocelot_flower.c
index 03b5e59d033e..b8617e940063 100644
--- a/drivers/net/ethernet/mscc/ocelot_flower.c
+++ b/drivers/net/ethernet/mscc/ocelot_flower.c
@@ -793,6 +793,11 @@ static struct ocelot_vcap_filter
 		filter->egress_port.mask = GENMASK(key_length - 1, 0);
 	}
 
+	/* Allow the filter to be removed from ocelot->traps
+	 * without traversing the list
+	 */
+	INIT_LIST_HEAD(&filter->trap_list);
+
 	return filter;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net 2/6] net: mscc: ocelot: avoid use after free with deleted tc-trap rules
  2022-05-03 11:57 [PATCH net 0/6] Ocelot VCAP fixes Vladimir Oltean
  2022-05-03 11:57 ` [PATCH net 1/6] net: mscc: ocelot: don't use list_empty() on non-initialized list element Vladimir Oltean
@ 2022-05-03 11:57 ` Vladimir Oltean
  2022-05-04 21:10   ` Vladimir Oltean
  2022-05-03 11:57 ` [PATCH net 3/6] net: mscc: ocelot: fix last VCAP IS1/IS2 filter persisting in hardware when deleted Vladimir Oltean
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 8+ messages in thread
From: Vladimir Oltean @ 2022-05-03 11:57 UTC (permalink / raw)
  To: netdev
  Cc: Jakub Kicinski, David S. Miller, Paolo Abeni, Eric Dumazet,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver,
	Xiaoliang Yang, Colin Foster

The error path of ocelot_flower_parse() removes a VCAP filter from
ocelot->traps, but the main deletion path - ocelot_vcap_filter_del() -
does not.

So functions such as felix_update_trapping_destinations() can still
access the freed VCAP filter via ocelot->traps.

Fix this bug by removing the filter from ocelot->traps when it gets
deleted.

Fixes: e42bd4ed09aa ("net: mscc: ocelot: keep traps in a list")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 drivers/net/ethernet/mscc/ocelot_vcap.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/mscc/ocelot_vcap.c b/drivers/net/ethernet/mscc/ocelot_vcap.c
index 1e74bdb215ec..571d43e59f63 100644
--- a/drivers/net/ethernet/mscc/ocelot_vcap.c
+++ b/drivers/net/ethernet/mscc/ocelot_vcap.c
@@ -1232,6 +1232,8 @@ static void ocelot_vcap_block_remove_filter(struct ocelot *ocelot,
 		if (ocelot_vcap_filter_equal(filter, tmp)) {
 			ocelot_vcap_filter_del_aux_resources(ocelot, tmp);
 			list_del(&tmp->list);
+			if (!list_empty(&tmp->trap_list))
+				list_del(&tmp->trap_list);
 			kfree(tmp);
 		}
 	}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net 3/6] net: mscc: ocelot: fix last VCAP IS1/IS2 filter persisting in hardware when deleted
  2022-05-03 11:57 [PATCH net 0/6] Ocelot VCAP fixes Vladimir Oltean
  2022-05-03 11:57 ` [PATCH net 1/6] net: mscc: ocelot: don't use list_empty() on non-initialized list element Vladimir Oltean
  2022-05-03 11:57 ` [PATCH net 2/6] net: mscc: ocelot: avoid use after free with deleted tc-trap rules Vladimir Oltean
@ 2022-05-03 11:57 ` Vladimir Oltean
  2022-05-03 11:57 ` [PATCH net 4/6] net: mscc: ocelot: fix VCAP IS2 filters matching on both lookups Vladimir Oltean
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Vladimir Oltean @ 2022-05-03 11:57 UTC (permalink / raw)
  To: netdev
  Cc: Jakub Kicinski, David S. Miller, Paolo Abeni, Eric Dumazet,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver,
	Xiaoliang Yang, Colin Foster

ocelot_vcap_filter_del() works by moving the next filters over the
current one, and then deleting the last filter by calling vcap_entry_set()
with a del_filter which was specially created by memsetting its memory
to zeroes. vcap_entry_set() then programs this to the TCAM and action
RAM via the cache registers.

The problem is that vcap_entry_set() is a dispatch function which looks
at del_filter->block_id. But since del_filter is zeroized memory, the
block_id is 0, or otherwise said, VCAP_ES0. So practically, what we do
is delete the entry at the same TCAM index from VCAP ES0 instead of IS1
or IS2.

The code was not always like this. vcap_entry_set() used to simply be
is2_entry_set(), and then, the logic used to work.

Restore the functionality by populating the block_id of the del_filter
based on the VCAP block of the filter that we're deleting. This makes
vcap_entry_set() know what to do.

Fixes: 1397a2eb52e2 ("net: mscc: ocelot: create TCAM skeleton from tc filter chains")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 drivers/net/ethernet/mscc/ocelot_vcap.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/mscc/ocelot_vcap.c b/drivers/net/ethernet/mscc/ocelot_vcap.c
index 571d43e59f63..469145205312 100644
--- a/drivers/net/ethernet/mscc/ocelot_vcap.c
+++ b/drivers/net/ethernet/mscc/ocelot_vcap.c
@@ -1248,7 +1248,11 @@ int ocelot_vcap_filter_del(struct ocelot *ocelot,
 	struct ocelot_vcap_filter del_filter;
 	int i, index;
 
+	/* Need to inherit the block_id so that vcap_entry_set()
+	 * does not get confused and knows where to install it.
+	 */
 	memset(&del_filter, 0, sizeof(del_filter));
+	del_filter.block_id = filter->block_id;
 
 	/* Gets index of the filter */
 	index = ocelot_vcap_block_get_filter_index(block, filter);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net 4/6] net: mscc: ocelot: fix VCAP IS2 filters matching on both lookups
  2022-05-03 11:57 [PATCH net 0/6] Ocelot VCAP fixes Vladimir Oltean
                   ` (2 preceding siblings ...)
  2022-05-03 11:57 ` [PATCH net 3/6] net: mscc: ocelot: fix last VCAP IS1/IS2 filter persisting in hardware when deleted Vladimir Oltean
@ 2022-05-03 11:57 ` Vladimir Oltean
  2022-05-03 11:57 ` [PATCH net 5/6] net: mscc: ocelot: restrict tc-trap actions to VCAP IS2 lookup 0 Vladimir Oltean
  2022-05-03 11:57 ` [PATCH net 6/6] net: mscc: ocelot: avoid corrupting hardware counters when moving VCAP filters Vladimir Oltean
  5 siblings, 0 replies; 8+ messages in thread
From: Vladimir Oltean @ 2022-05-03 11:57 UTC (permalink / raw)
  To: netdev
  Cc: Jakub Kicinski, David S. Miller, Paolo Abeni, Eric Dumazet,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver,
	Xiaoliang Yang, Colin Foster

The VCAP IS2 TCAM is looked up twice per packet, and each filter can be
configured to only match during the first, second lookup, or both, or
none.

The blamed commit wrote the code for making VCAP IS2 filters match only
on the given lookup. But right below that code, there was another line
that explicitly made the lookup a "don't care", and this is overwriting
the lookup we've selected. So the code had no effect.

Some of the more noticeable effects of having filters match on both
lookups:

- in "tc -s filter show dev swp0 ingress", we see each packet matching a
  VCAP IS2 filter counted twice. This throws off scripts such as
  tools/testing/selftests/net/forwarding/tc_actions.sh and makes them
  fail.

- a "tc-drop" action offloaded to VCAP IS2 needs a policer as well,
  because once the CPU port becomes a member of the destination port
  mask of a packet, nothing removes it, not even a PERMIT/DENY mask mode
  with a port mask of 0. But VCAP IS2 rules with the POLICE_ENA bit in
  the action vector can only appear in the first lookup. What happens
  when a filter matches both lookups is that the action vector is
  combined, and this makes the POLICE_ENA bit ineffective, since the
  last lookup in which it has appeared is the second one. In other
  words, "tc-drop" actions do not drop packets for the CPU port, dropped
  packets are still seen by software unless there was an FDB entry that
  directed those packets to some other place different from the CPU.

The last bit used to work, because in the initial commit b596229448dd
("net: mscc: ocelot: Add support for tcam"), we were writing the FIRST
field of the VCAP IS2 half key with a 1, not with a "don't care".
The change to "don't care" was made inadvertently by me in commit
c1c3993edb7c ("net: mscc: ocelot: generalize existing code for VCAP"),
which I just realized, and which needs a separate fix from this one,
for "stable" kernels that lack the commit blamed below.

Fixes: 226e9cd82a96 ("net: mscc: ocelot: only install TCAM entries into a specific lookup and PAG")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 drivers/net/ethernet/mscc/ocelot_vcap.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/ethernet/mscc/ocelot_vcap.c b/drivers/net/ethernet/mscc/ocelot_vcap.c
index 469145205312..a4e3ff160890 100644
--- a/drivers/net/ethernet/mscc/ocelot_vcap.c
+++ b/drivers/net/ethernet/mscc/ocelot_vcap.c
@@ -374,7 +374,6 @@ static void is2_entry_set(struct ocelot *ocelot, int ix,
 			 OCELOT_VCAP_BIT_0);
 	vcap_key_set(vcap, &data, VCAP_IS2_HK_IGR_PORT_MASK, 0,
 		     ~filter->ingress_port_mask);
-	vcap_key_bit_set(vcap, &data, VCAP_IS2_HK_FIRST, OCELOT_VCAP_BIT_ANY);
 	vcap_key_bit_set(vcap, &data, VCAP_IS2_HK_HOST_MATCH,
 			 OCELOT_VCAP_BIT_ANY);
 	vcap_key_bit_set(vcap, &data, VCAP_IS2_HK_L2_MC, filter->dmac_mc);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net 5/6] net: mscc: ocelot: restrict tc-trap actions to VCAP IS2 lookup 0
  2022-05-03 11:57 [PATCH net 0/6] Ocelot VCAP fixes Vladimir Oltean
                   ` (3 preceding siblings ...)
  2022-05-03 11:57 ` [PATCH net 4/6] net: mscc: ocelot: fix VCAP IS2 filters matching on both lookups Vladimir Oltean
@ 2022-05-03 11:57 ` Vladimir Oltean
  2022-05-03 11:57 ` [PATCH net 6/6] net: mscc: ocelot: avoid corrupting hardware counters when moving VCAP filters Vladimir Oltean
  5 siblings, 0 replies; 8+ messages in thread
From: Vladimir Oltean @ 2022-05-03 11:57 UTC (permalink / raw)
  To: netdev
  Cc: Jakub Kicinski, David S. Miller, Paolo Abeni, Eric Dumazet,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver,
	Xiaoliang Yang, Colin Foster

Once the CPU port was added to the destination port mask of a packet, it
can never be cleared, so even packets marked as dropped by the MASK_MODE
of a VCAP IS2 filter will still reach it. This is why we need the
OCELOT_POLICER_DISCARD to "kill dropped packets dead" and make software
stop seeing them.

We disallow policer rules from being put on any other chain than the one
for the first lookup, but we don't do this for "drop" rules, although we
should. This change is merely ascertaining that the rules dont't
(completely) work and letting the user know.

The blamed commit is the one that introduced the multi-chain architecture
in ocelot. Prior to that, we should have always offloaded the filters to
VCAP IS2 lookup 0, where they did work.

Fixes: 1397a2eb52e2 ("net: mscc: ocelot: create TCAM skeleton from tc filter chains")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 drivers/net/ethernet/mscc/ocelot_flower.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mscc/ocelot_flower.c b/drivers/net/ethernet/mscc/ocelot_flower.c
index b8617e940063..e598308ef09d 100644
--- a/drivers/net/ethernet/mscc/ocelot_flower.c
+++ b/drivers/net/ethernet/mscc/ocelot_flower.c
@@ -280,9 +280,10 @@ static int ocelot_flower_parse_action(struct ocelot *ocelot, int port,
 			filter->type = OCELOT_VCAP_FILTER_OFFLOAD;
 			break;
 		case FLOW_ACTION_TRAP:
-			if (filter->block_id != VCAP_IS2) {
+			if (filter->block_id != VCAP_IS2 ||
+			    filter->lookup != 0) {
 				NL_SET_ERR_MSG_MOD(extack,
-						   "Trap action can only be offloaded to VCAP IS2");
+						   "Trap action can only be offloaded to VCAP IS2 lookup 0");
 				return -EOPNOTSUPP;
 			}
 			if (filter->goto_target != -1) {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net 6/6] net: mscc: ocelot: avoid corrupting hardware counters when moving VCAP filters
  2022-05-03 11:57 [PATCH net 0/6] Ocelot VCAP fixes Vladimir Oltean
                   ` (4 preceding siblings ...)
  2022-05-03 11:57 ` [PATCH net 5/6] net: mscc: ocelot: restrict tc-trap actions to VCAP IS2 lookup 0 Vladimir Oltean
@ 2022-05-03 11:57 ` Vladimir Oltean
  5 siblings, 0 replies; 8+ messages in thread
From: Vladimir Oltean @ 2022-05-03 11:57 UTC (permalink / raw)
  To: netdev
  Cc: Jakub Kicinski, David S. Miller, Paolo Abeni, Eric Dumazet,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver,
	Xiaoliang Yang, Colin Foster

Given the following order of operations:

(1) we add filter A using tc-flower
(2) we send a packet that matches it
(3) we read the filter's statistics to find a hit count of 1
(4) we add a second filter B with a higher preference than A, and A
    moves one position to the right to make room in the TCAM for it
(5) we send another packet, and this matches the second filter B
(6) we read the filter statistics again.

When this happens, the hit count of filter A is 2 and of filter B is 1,
despite a single packet having matched each filter.

Furthermore, in an alternate history, reading the filter stats a second
time between steps (3) and (4) makes the hit count of filter A remain at
1 after step (6), as expected.

The reason why this happens has to do with the filter->stats.pkts field,
which is written to hardware through the call path below:

               vcap_entry_set
               /      |      \
              /       |       \
             /        |        \
            /         |         \
es0_entry_set   is1_entry_set   is2_entry_set
            \         |         /
             \        |        /
              \       |       /
        vcap_data_set(data.counter, ...)

The primary role of filter->stats.pkts is to transport the filter hit
counters from the last readout all the way from vcap_entry_get() ->
ocelot_vcap_filter_stats_update() -> ocelot_cls_flower_stats().
The reason why vcap_entry_set() writes it to hardware is so that the
counters (saturating and having a limited bit width) are cleared
after each user space readout.

The writing of filter->stats.pkts to hardware during the TCAM entry
movement procedure is an unintentional consequence of the code design,
because the hit count isn't up to date at this point.

So at step (4), when filter A is moved by ocelot_vcap_filter_add() to
make room for filter B, the hardware hit count is 0 (no packet matched
on it in the meantime), but filter->stats.pkts is 1, because the last
readout saw the earlier packet. The movement procedure programs the old
hit count back to hardware, so this creates the impression to user space
that more packets have been matched than they really were.

The bug can be seen when running the gact_drop_and_ok_test() from the
tc_actions.sh selftest.

Fix the issue by reading back the hit count to tmp->stats.pkts before
migrating the VCAP filter. Sure, this is a best-effort technique, since
the packets that hit the rule between vcap_entry_get() and
vcap_entry_set() won't be counted, but at least it allows the counters
to be reliably used for selftests where the traffic is under control.

The vcap_entry_get() name is a bit unintuitive, but it only reads back
the counter portion of the TCAM entry, not the entire entry.

The index from which we retrieve the counter is also a bit unintuitive
(i - 1 during add, i + 1 during del), but this is the way in which TCAM
entry movement works. The "entry index" isn't a stored integer for a
TCAM filter, instead it is dynamically computed by
ocelot_vcap_block_get_filter_index() based on the entry's position in
the &block->rules list. That position (as well as block->count) is
automatically updated by ocelot_vcap_filter_add_to_block() on add, and
by ocelot_vcap_block_remove_filter() on del. So "i" is the new filter
index, and "i - 1" or "i + 1" respectively are the old addresses of that
TCAM entry (we only support installing/deleting one filter at a time).

Fixes: b596229448dd ("net: mscc: ocelot: Add support for tcam")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 drivers/net/ethernet/mscc/ocelot_vcap.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/mscc/ocelot_vcap.c b/drivers/net/ethernet/mscc/ocelot_vcap.c
index a4e3ff160890..e98e7527da21 100644
--- a/drivers/net/ethernet/mscc/ocelot_vcap.c
+++ b/drivers/net/ethernet/mscc/ocelot_vcap.c
@@ -1212,6 +1212,8 @@ int ocelot_vcap_filter_add(struct ocelot *ocelot,
 		struct ocelot_vcap_filter *tmp;
 
 		tmp = ocelot_vcap_block_find_filter_by_index(block, i);
+		/* Read back the filter's counters before moving it */
+		vcap_entry_get(ocelot, i - 1, tmp);
 		vcap_entry_set(ocelot, i, tmp);
 	}
 
@@ -1266,6 +1268,8 @@ int ocelot_vcap_filter_del(struct ocelot *ocelot,
 		struct ocelot_vcap_filter *tmp;
 
 		tmp = ocelot_vcap_block_find_filter_by_index(block, i);
+		/* Read back the filter's counters before moving it */
+		vcap_entry_get(ocelot, i + 1, tmp);
 		vcap_entry_set(ocelot, i, tmp);
 	}
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH net 2/6] net: mscc: ocelot: avoid use after free with deleted tc-trap rules
  2022-05-03 11:57 ` [PATCH net 2/6] net: mscc: ocelot: avoid use after free with deleted tc-trap rules Vladimir Oltean
@ 2022-05-04 21:10   ` Vladimir Oltean
  0 siblings, 0 replies; 8+ messages in thread
From: Vladimir Oltean @ 2022-05-04 21:10 UTC (permalink / raw)
  To: netdev
  Cc: Jakub Kicinski, David S. Miller, Paolo Abeni, Eric Dumazet,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver,
	Xiaoliang Yang, Colin Foster

On Tue, May 03, 2022 at 02:57:24PM +0300, Vladimir Oltean wrote:
> The error path of ocelot_flower_parse() removes a VCAP filter from
> ocelot->traps, but the main deletion path - ocelot_vcap_filter_del() -
> does not.
> 
> So functions such as felix_update_trapping_destinations() can still
> access the freed VCAP filter via ocelot->traps.
> 
> Fix this bug by removing the filter from ocelot->traps when it gets
> deleted.
> 
> Fixes: e42bd4ed09aa ("net: mscc: ocelot: keep traps in a list")
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> ---
>  drivers/net/ethernet/mscc/ocelot_vcap.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/net/ethernet/mscc/ocelot_vcap.c b/drivers/net/ethernet/mscc/ocelot_vcap.c
> index 1e74bdb215ec..571d43e59f63 100644
> --- a/drivers/net/ethernet/mscc/ocelot_vcap.c
> +++ b/drivers/net/ethernet/mscc/ocelot_vcap.c
> @@ -1232,6 +1232,8 @@ static void ocelot_vcap_block_remove_filter(struct ocelot *ocelot,
>  		if (ocelot_vcap_filter_equal(filter, tmp)) {
>  			ocelot_vcap_filter_del_aux_resources(ocelot, tmp);
>  			list_del(&tmp->list);
> +			if (!list_empty(&tmp->trap_list))
> +				list_del(&tmp->trap_list);
>  			kfree(tmp);
>  		}
>  	}
> -- 
> 2.25.1
>

This change introduces other breakage, please drop this patch set and
allow me to come up with a different solution.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-05-04 21:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-03 11:57 [PATCH net 0/6] Ocelot VCAP fixes Vladimir Oltean
2022-05-03 11:57 ` [PATCH net 1/6] net: mscc: ocelot: don't use list_empty() on non-initialized list element Vladimir Oltean
2022-05-03 11:57 ` [PATCH net 2/6] net: mscc: ocelot: avoid use after free with deleted tc-trap rules Vladimir Oltean
2022-05-04 21:10   ` Vladimir Oltean
2022-05-03 11:57 ` [PATCH net 3/6] net: mscc: ocelot: fix last VCAP IS1/IS2 filter persisting in hardware when deleted Vladimir Oltean
2022-05-03 11:57 ` [PATCH net 4/6] net: mscc: ocelot: fix VCAP IS2 filters matching on both lookups Vladimir Oltean
2022-05-03 11:57 ` [PATCH net 5/6] net: mscc: ocelot: restrict tc-trap actions to VCAP IS2 lookup 0 Vladimir Oltean
2022-05-03 11:57 ` [PATCH net 6/6] net: mscc: ocelot: avoid corrupting hardware counters when moving VCAP filters Vladimir Oltean

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.