Skip to content

Commit 622ab65

Browse files
Edward Creekuba-moo
authored andcommitted
sfc: fix error unwinds in TC offload
Failure ladders weren't exactly unwinding what the function had done up to that point; most seriously, when we encountered an already offloaded rule, the failure path tried to remove the new rule from the hashtable, which would in fact remove the already-present 'old' rule (since it has the same key) from the table, and leak its resources. Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <error27@gmail.com> Closes: https://lore.kernel.org/r/202305200745.xmIlkqjH-lkp@intel.com/ Fixes: d902e1a ("sfc: bare bones TC offload on EF100") Fixes: 17654d8 ("sfc: add offloading of 'foreign' TC (decap) rules") Signed-off-by: Edward Cree <ecree.xilinx@gmail.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> Link: https://lore.kernel.org/r/20230530202527.53115-1-edward.cree@amd.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 448a5ce commit 622ab65

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

  • drivers/net/ethernet/sfc

drivers/net/ethernet/sfc/tc.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -624,13 +624,12 @@ static int efx_tc_flower_replace_foreign(struct efx_nic *efx,
624624
if (!found) { /* We don't care. */
625625
netif_dbg(efx, drv, efx->net_dev,
626626
"Ignoring foreign filter that doesn't egdev us\n");
627-
rc = -EOPNOTSUPP;
628-
goto release;
627+
return -EOPNOTSUPP;
629628
}
630629

631630
rc = efx_mae_match_check_caps(efx, &match.mask, NULL);
632631
if (rc)
633-
goto release;
632+
return rc;
634633

635634
if (efx_tc_match_is_encap(&match.mask)) {
636635
enum efx_encap_type type;
@@ -639,34 +638,32 @@ static int efx_tc_flower_replace_foreign(struct efx_nic *efx,
639638
if (type == EFX_ENCAP_TYPE_NONE) {
640639
NL_SET_ERR_MSG_MOD(extack,
641640
"Egress encap match on unsupported tunnel device");
642-
rc = -EOPNOTSUPP;
643-
goto release;
641+
return -EOPNOTSUPP;
644642
}
645643

646644
rc = efx_mae_check_encap_type_supported(efx, type);
647645
if (rc) {
648646
NL_SET_ERR_MSG_FMT_MOD(extack,
649647
"Firmware reports no support for %s encap match",
650648
efx_tc_encap_type_name(type));
651-
goto release;
649+
return rc;
652650
}
653651

654652
rc = efx_tc_flower_record_encap_match(efx, &match, type,
655653
extack);
656654
if (rc)
657-
goto release;
655+
return rc;
658656
} else {
659657
/* This is not a tunnel decap rule, ignore it */
660658
netif_dbg(efx, drv, efx->net_dev,
661659
"Ignoring foreign filter without encap match\n");
662-
rc = -EOPNOTSUPP;
663-
goto release;
660+
return -EOPNOTSUPP;
664661
}
665662

666663
rule = kzalloc(sizeof(*rule), GFP_USER);
667664
if (!rule) {
668665
rc = -ENOMEM;
669-
goto release;
666+
goto out_free;
670667
}
671668
INIT_LIST_HEAD(&rule->acts.list);
672669
rule->cookie = tc->cookie;
@@ -678,7 +675,7 @@ static int efx_tc_flower_replace_foreign(struct efx_nic *efx,
678675
"Ignoring already-offloaded rule (cookie %lx)\n",
679676
tc->cookie);
680677
rc = -EEXIST;
681-
goto release;
678+
goto out_free;
682679
}
683680

684681
act = kzalloc(sizeof(*act), GFP_USER);
@@ -843,6 +840,7 @@ static int efx_tc_flower_replace_foreign(struct efx_nic *efx,
843840
efx_tc_match_action_ht_params);
844841
efx_tc_free_action_set_list(efx, &rule->acts, false);
845842
}
843+
out_free:
846844
kfree(rule);
847845
if (match.encap)
848846
efx_tc_flower_release_encap_match(efx, match.encap);
@@ -899,8 +897,7 @@ static int efx_tc_flower_replace(struct efx_nic *efx,
899897
return rc;
900898
if (efx_tc_match_is_encap(&match.mask)) {
901899
NL_SET_ERR_MSG_MOD(extack, "Ingress enc_key matches not supported");
902-
rc = -EOPNOTSUPP;
903-
goto release;
900+
return -EOPNOTSUPP;
904901
}
905902

906903
if (tc->common.chain_index) {
@@ -924,9 +921,9 @@ static int efx_tc_flower_replace(struct efx_nic *efx,
924921
if (old) {
925922
netif_dbg(efx, drv, efx->net_dev,
926923
"Already offloaded rule (cookie %lx)\n", tc->cookie);
927-
rc = -EEXIST;
928924
NL_SET_ERR_MSG_MOD(extack, "Rule already offloaded");
929-
goto release;
925+
kfree(rule);
926+
return -EEXIST;
930927
}
931928

932929
/* Parse actions */

0 commit comments

Comments
 (0)