Yonglong Liu (2): net: hns3: fix kernel crash when devlink reload during pf initialization net: hns3: fix kernel crash when devlink reload during initialization
.../ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c | 5 +++-- .../net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 12 +++++------- .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 10 ++++------ 3 files changed, 12 insertions(+), 15 deletions(-)
From: Yonglong Liu liuyonglong@huawei.com
driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I9TM2X CVE: CVE-2024-36021
----------------------------------------------------------------------
The devlink reload process will access the hardware resources, but the register operation is before the hardware initialize done, so, if process the devlink reload during initializetion, may lead the kernel crash. This patch check whether the NIC is initialized to fix the problem.
Fixes: 2cd7213c2dc4 ("net: hns3: add support for registering devlink for PF") Signed-off-by: Yonglong Liu liuyonglong@huawei.com Signed-off-by: Ye Bin yebin10@huawei.com --- drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c index 65802ecf848f..28079c246275 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c @@ -45,8 +45,9 @@ static int hclge_devlink_reload_down(struct devlink *devlink, bool netns_change, struct pci_dev *pdev = hdev->pdev; int ret;
- if (test_bit(HCLGE_STATE_RST_HANDLING, &hdev->state)) { - dev_err(&pdev->dev, "reset is handling\n"); + if (test_bit(HCLGE_STATE_RST_HANDLING, &hdev->state) || + !test_bit(HCLGE_STATE_NIC_REGISTERED, &hdev->state)) { + dev_err(&pdev->dev, "reset is handling or driver removed\n"); return -EBUSY; }
From: Yonglong Liu liuyonglong@huawei.com
mainline inclusion from mainline-v6.9 commit 35d92abfbad88cf947c010baf34b075e40566095 category: bugfix bugzilla: https://gitee.com/src-openeuler/kernel/issues/I9U3H2 CVE: CVE-2024-36900
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...
--------------------------------
The devlink reload process will access the hardware resources, but the register operation is done before the hardware is initialized. So, processing the devlink reload during initialization may lead to kernel crash.
This patch fixes this by registering the devlink after hardware initialization. Fixes: cd6242991d2e ("net: hns3: add support for registering devlink for VF") Fixes: 93305b77ffcb ("net: hns3: fix kernel crash when devlink reload during pf initialization") Signed-off-by: Yonglong Liu liuyonglong@huawei.com Signed-off-by: Jijie Shao shaojijie@huawei.com Signed-off-by: Paolo Abeni pabeni@redhat.com Conflicts: drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c [As 950aa4239989 ("net: hns3: release PTP resources if pf initialization failed") not merged] Signed-off-by: Ye Bin yebin10@huawei.com --- .../net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 12 +++++------- .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 10 ++++------ 2 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c index af366b9e6b7f..d2355575e5ea 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c @@ -12243,14 +12243,10 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev) if (ret) goto out;
- ret = hclge_devlink_init(hdev); - if (ret) - goto err_pci_uninit; - /* Firmware command queue initialize */ ret = hclge_comm_cmd_queue_init(hdev->pdev, &hdev->hw.hw); if (ret) - goto err_devlink_uninit; + goto err_pci_uninit;
/* Firmware command initialize */ ret = hclge_comm_cmd_init(hdev->ae_dev, &hdev->hw.hw, &hdev->fw_version, @@ -12423,6 +12419,10 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev) dev_warn(&pdev->dev, "failed to wake on lan init, ret = %d\n", ret);
+ ret = hclge_devlink_init(hdev); + if (ret) + goto err_sysfs_unregister; + hclge_state_init(hdev); hdev->last_reset_time = jiffies;
@@ -12444,8 +12444,6 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev) pci_free_irq_vectors(pdev); err_cmd_uninit: hclge_comm_cmd_uninit(hdev->ae_dev, &hdev->hw.hw); -err_devlink_uninit: - hclge_devlink_uninit(hdev); err_pci_uninit: pcim_iounmap(pdev, hdev->hw.hw.io_base); pci_clear_master(pdev); diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c index b5738a7e260a..cdd0c1583b9e 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c @@ -2952,10 +2952,6 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev) if (ret) return ret;
- ret = hclgevf_devlink_init(hdev); - if (ret) - goto err_devlink_init; - ret = hclge_comm_cmd_queue_init(hdev->pdev, &hdev->hw.hw); if (ret) goto err_cmd_queue_init; @@ -3050,6 +3046,10 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev)
hclgevf_init_rxd_adv_layout(hdev);
+ ret = hclgevf_devlink_init(hdev); + if (ret) + goto err_config; + set_bit(HCLGEVF_STATE_SERVICE_INITED, &hdev->state);
hdev->last_reset_time = jiffies; @@ -3068,8 +3068,6 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev) err_cmd_init: hclge_comm_cmd_uninit(hdev->ae_dev, &hdev->hw.hw); err_cmd_queue_init: - hclgevf_devlink_uninit(hdev); -err_devlink_init: hclgevf_pci_uninit(hdev); clear_bit(HCLGEVF_STATE_IRQ_INITED, &hdev->state); return ret;
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/8647 邮件列表地址:https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/I...
FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/8647 Mailing list address: https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/I...