net: hns3: Add error handling for VLAN filter hardware configuration
Subsystems (5)
PATCH 1/1 net: hns3: Add error handling for VLAN filter hardware configuration
The hclge_rm_vport_vlan_table() calls hclge_set_vlan_filter_hw() but does not check the return value. This could lead to execution with potentially invalid data. A proper implementation can be found in hclge_add_vport_all_vlan_table().
Add error handling after calling hclge_set_vlan_filter_hw(). If hclge_set_vlan_filter_hw() fails, log an error message via dev_err() and return.
--- .../hisilicon/hns3/hns3pf/hclge_main.c | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +14 -6
@@ -10141,15 +10141,23 @@ static void hclge_rm_vport_vlan_table(struct hclge_vport *vport, u16 vlan_id, {struct hclge_vport_vlan_cfg *vlan, *tmp;struct hclge_dev *hdev = vport->back; +int ret;list_for_each_entry_safe (vlan, tmp, &vport->vlan_list, node) {if (vlan->vlan_id == vlan_id) { -if (is_write_tbl && vlan->hd_tbl_status) -hclge_set_vlan_filter_hw (hdev, -htons (ETH_P_8021Q ), - vport->vport_id, - vlan_id, - true); +if (is_write_tbl && vlan->hd_tbl_status) { + ret =hclge_set_vlan_filter_hw (hdev, +htons (ETH_P_8021Q ), + vport->vport_id, + vlan_id, + true); +if (ret) { +dev_err (&hdev->pdev->dev, +"restore vport vlan list failed, ret=%d\n" , + ret); +return ; + } + }list_del (&vlan->node);kfree (vlan);
Signature · 1 line
2.42.0.windows.2
Jijie Shao
maintainerQuoted 3 lines · Wentao Liang
The
hclge_rm_vport_vlan_table()callshclge_set_vlan_filter_hw()but does not check the return value. This could lead to execution with potentially invalid data. A proper implementation can be found in
Hi:
Are there any real functional problems?
Would you please tell me your test cases? I'm going to try to reproduce the problem.
Thanks,
Jijie Shao
Quoted 47 lines
hclge_add_vport_all_vlan_table().Add error handling after calling
hclge_set_vlan_filter_hw(). Ifhclge_set_vlan_filter_hw()fails, log an error message viadev_err()and return.Fixes c6075b193462 ("net: hns3: Record VF vlan tables")Cc [email protected] # v5.1Signed-off-by Wentao Liang <[email protected]>--- .../hisilicon/hns3/hns3pf/hclge_main.c | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +14
-6@@ -10141,15 +10141,23 @@ static void hclge_rm_vport_vlan_table(struct hclge_vport *vport, u16 vlan_id, {struct hclge_vport_vlan_cfg *vlan, *tmp;struct hclge_dev *hdev = vport->back; +int ret;list_for_each_entry_safe (vlan, tmp, &vport->vlan_list, node) {if (vlan->vlan_id == vlan_id) { -if (is_write_tbl && vlan->hd_tbl_status) -hclge_set_vlan_filter_hw (hdev, -htons (ETH_P_8021Q ), - vport->vport_id, - vlan_id, - true); +if (is_write_tbl && vlan->hd_tbl_status) { + ret =hclge_set_vlan_filter_hw (hdev, +htons (ETH_P_8021Q ), + vport->vport_id, + vlan_id, + true); +if (ret) { +dev_err (&hdev->pdev->dev, +"restore vport vlan list failed, ret=%d\n" , + ret); +return ; + } + }list_del (&vlan->node);kfree (vlan);
A message that is not in the archive (sent off-list or not yet received): [email protected]
Simon Horman
reviewerRe: [PATCH] net: hns3: Add error handling for VLAN filter hardwareconfiguration
Quoted 6 lines · Wentao Liang
Quoted 2 lines
Are there any real functional problems?
Would you please tell me your test cases? I'm going to try to reproduce the problem.Hi,
I found this problem by static analysis and manual auditing. I believe there should be add a check just like the other call of
hclge_set_vlan_filter_hw(). If the check is useless, could you please tell me the detailed reason.
Thanks,
I think it would be useful for the patch description to state that the problem was found using static analysis.
But let's wait for more feedback from Jijie on if this check is, at least theoretically, required.
Jijie Shao
maintainerRe: [PATCH] net: hns3: Add error handling for VLAN filter hardwareconfiguration
In reply to a message not in the archiveQuoted 9 lines · Wentao Liang
Quoted 4 lines
Are there any real functional problems?
Would you please tell me your test cases? I'm going to try to reproduce the problem.
Hi,
I found this problem by static analysis and manual auditing. I believe there should be add a check just like the other call of
hclge_set_vlan_filter_hw(). If the check is useless, could you please tell me the detailed reason.
Hi Wentao,
Thanks for your reply.
I checked the code, and found that the purpose of all two places called hclge_rm_vport_vlan_table() now is just to update the vlan list, never do clear the vlan entry in hardware. So I prefer to remove the parameter 'is_write_tbl' from hclge_rm_vport_vlan_table(), and remove the hclge_set_vlan_filter_hw() calling in it.
Thanks,
Jijie Shao
Quoted 4 lines
Thanks,
Wentao Liang.