Commit 622ab656 authored by Edward Cree's avatar Edward Cree Committed by Jakub Kicinski

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: default avatarkernel test robot <lkp@intel.com>
Reported-by: default avatarDan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/r/202305200745.xmIlkqjH-lkp@intel.com/
Fixes: d902e1a7 ("sfc: bare bones TC offload on EF100")
Fixes: 17654d84 ("sfc: add offloading of 'foreign' TC (decap) rules")
Signed-off-by: default avatarEdward Cree <ecree.xilinx@gmail.com>
Reviewed-by: default avatarSimon Horman <simon.horman@corigine.com>
Link: https://lore.kernel.org/r/20230530202527.53115-1-edward.cree@amd.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 448a5ce1
...@@ -624,13 +624,12 @@ static int efx_tc_flower_replace_foreign(struct efx_nic *efx, ...@@ -624,13 +624,12 @@ static int efx_tc_flower_replace_foreign(struct efx_nic *efx,
if (!found) { /* We don't care. */ if (!found) { /* We don't care. */
netif_dbg(efx, drv, efx->net_dev, netif_dbg(efx, drv, efx->net_dev,
"Ignoring foreign filter that doesn't egdev us\n"); "Ignoring foreign filter that doesn't egdev us\n");
rc = -EOPNOTSUPP; return -EOPNOTSUPP;
goto release;
} }
rc = efx_mae_match_check_caps(efx, &match.mask, NULL); rc = efx_mae_match_check_caps(efx, &match.mask, NULL);
if (rc) if (rc)
goto release; return rc;
if (efx_tc_match_is_encap(&match.mask)) { if (efx_tc_match_is_encap(&match.mask)) {
enum efx_encap_type type; enum efx_encap_type type;
...@@ -639,8 +638,7 @@ static int efx_tc_flower_replace_foreign(struct efx_nic *efx, ...@@ -639,8 +638,7 @@ static int efx_tc_flower_replace_foreign(struct efx_nic *efx,
if (type == EFX_ENCAP_TYPE_NONE) { if (type == EFX_ENCAP_TYPE_NONE) {
NL_SET_ERR_MSG_MOD(extack, NL_SET_ERR_MSG_MOD(extack,
"Egress encap match on unsupported tunnel device"); "Egress encap match on unsupported tunnel device");
rc = -EOPNOTSUPP; return -EOPNOTSUPP;
goto release;
} }
rc = efx_mae_check_encap_type_supported(efx, type); rc = efx_mae_check_encap_type_supported(efx, type);
...@@ -648,25 +646,24 @@ static int efx_tc_flower_replace_foreign(struct efx_nic *efx, ...@@ -648,25 +646,24 @@ static int efx_tc_flower_replace_foreign(struct efx_nic *efx,
NL_SET_ERR_MSG_FMT_MOD(extack, NL_SET_ERR_MSG_FMT_MOD(extack,
"Firmware reports no support for %s encap match", "Firmware reports no support for %s encap match",
efx_tc_encap_type_name(type)); efx_tc_encap_type_name(type));
goto release; return rc;
} }
rc = efx_tc_flower_record_encap_match(efx, &match, type, rc = efx_tc_flower_record_encap_match(efx, &match, type,
extack); extack);
if (rc) if (rc)
goto release; return rc;
} else { } else {
/* This is not a tunnel decap rule, ignore it */ /* This is not a tunnel decap rule, ignore it */
netif_dbg(efx, drv, efx->net_dev, netif_dbg(efx, drv, efx->net_dev,
"Ignoring foreign filter without encap match\n"); "Ignoring foreign filter without encap match\n");
rc = -EOPNOTSUPP; return -EOPNOTSUPP;
goto release;
} }
rule = kzalloc(sizeof(*rule), GFP_USER); rule = kzalloc(sizeof(*rule), GFP_USER);
if (!rule) { if (!rule) {
rc = -ENOMEM; rc = -ENOMEM;
goto release; goto out_free;
} }
INIT_LIST_HEAD(&rule->acts.list); INIT_LIST_HEAD(&rule->acts.list);
rule->cookie = tc->cookie; rule->cookie = tc->cookie;
...@@ -678,7 +675,7 @@ static int efx_tc_flower_replace_foreign(struct efx_nic *efx, ...@@ -678,7 +675,7 @@ static int efx_tc_flower_replace_foreign(struct efx_nic *efx,
"Ignoring already-offloaded rule (cookie %lx)\n", "Ignoring already-offloaded rule (cookie %lx)\n",
tc->cookie); tc->cookie);
rc = -EEXIST; rc = -EEXIST;
goto release; goto out_free;
} }
act = kzalloc(sizeof(*act), GFP_USER); act = kzalloc(sizeof(*act), GFP_USER);
...@@ -843,6 +840,7 @@ static int efx_tc_flower_replace_foreign(struct efx_nic *efx, ...@@ -843,6 +840,7 @@ static int efx_tc_flower_replace_foreign(struct efx_nic *efx,
efx_tc_match_action_ht_params); efx_tc_match_action_ht_params);
efx_tc_free_action_set_list(efx, &rule->acts, false); efx_tc_free_action_set_list(efx, &rule->acts, false);
} }
out_free:
kfree(rule); kfree(rule);
if (match.encap) if (match.encap)
efx_tc_flower_release_encap_match(efx, match.encap); efx_tc_flower_release_encap_match(efx, match.encap);
...@@ -899,8 +897,7 @@ static int efx_tc_flower_replace(struct efx_nic *efx, ...@@ -899,8 +897,7 @@ static int efx_tc_flower_replace(struct efx_nic *efx,
return rc; return rc;
if (efx_tc_match_is_encap(&match.mask)) { if (efx_tc_match_is_encap(&match.mask)) {
NL_SET_ERR_MSG_MOD(extack, "Ingress enc_key matches not supported"); NL_SET_ERR_MSG_MOD(extack, "Ingress enc_key matches not supported");
rc = -EOPNOTSUPP; return -EOPNOTSUPP;
goto release;
} }
if (tc->common.chain_index) { if (tc->common.chain_index) {
...@@ -924,9 +921,9 @@ static int efx_tc_flower_replace(struct efx_nic *efx, ...@@ -924,9 +921,9 @@ static int efx_tc_flower_replace(struct efx_nic *efx,
if (old) { if (old) {
netif_dbg(efx, drv, efx->net_dev, netif_dbg(efx, drv, efx->net_dev,
"Already offloaded rule (cookie %lx)\n", tc->cookie); "Already offloaded rule (cookie %lx)\n", tc->cookie);
rc = -EEXIST;
NL_SET_ERR_MSG_MOD(extack, "Rule already offloaded"); NL_SET_ERR_MSG_MOD(extack, "Rule already offloaded");
goto release; kfree(rule);
return -EEXIST;
} }
/* Parse actions */ /* Parse actions */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment