Commit e7e48f38 authored by Yihang Li's avatar Yihang Li Committed by Slim6882
Browse files

[Backport]scsi: hisi_sas: Adjust priority of registering and exiting debugfs for security

mainline inclusion
from mainline-v6.12-rc1
commit e6702e3919328b24757872cbf7f02c51894624d7
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBCN9K
CVE: NA
Reference: https://lore.kernel.org/r/20241008021822.2617339-2-liyihang9@huawei.com



------------------------------------------------------------------

To be safe, we should register debugfs at the last stage of driver
initialization and then unregister debugfs at the first stage of driver
uninstallation.

Signed-off-by: default avatarYihang Li <liyihang9@huawei.com>
Link: https://lore.kernel.org/r/20241008021822.2617339-2-liyihang9@huawei.com


Reviewed-by: default avatarXiang Chen <chenxiang66@hisilicon.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: default avatarSlim6882 <yangjunshuo@huawei.com>
parent dd14d8eb
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -2946,10 +2946,10 @@ static __init int hisi_sas_init(void)

static __exit void hisi_sas_exit(void)
{
	sas_release_transport(hisi_sas_stt);

	if (hisi_sas_debugfs_enable)
		debugfs_remove(hisi_sas_debugfs_dir);

	sas_release_transport(hisi_sas_stt);
}

module_init(hisi_sas_init);
+10 −14
Original line number Diff line number Diff line
@@ -4882,7 +4882,7 @@ hisi_sas_v3_probe(struct pci_dev *pdev, const struct pci_device_id *id)
	if (!hisi_hba->regs) {
		dev_err(dev, "cannot map register\n");
		rc = -ENOMEM;
		goto err_out_ha;
		goto err_out_free_host;
	}

	phy_nr = port_nr = hisi_hba->n_phy;
@@ -4891,7 +4891,7 @@ hisi_sas_v3_probe(struct pci_dev *pdev, const struct pci_device_id *id)
	arr_port = devm_kcalloc(dev, port_nr, sizeof(void *), GFP_KERNEL);
	if (!arr_phy || !arr_port) {
		rc = -ENOMEM;
		goto err_out_ha;
		goto err_out_free_host;
	}

	sha->sas_phy = arr_phy;
@@ -4927,16 +4927,13 @@ hisi_sas_v3_probe(struct pci_dev *pdev, const struct pci_device_id *id)
					    SHOST_DIX_GUARD_CRC);
	}

	if (hisi_sas_debugfs_enable)
		debugfs_init_v3_hw(hisi_hba);

	rc = interrupt_preinit_v3_hw(hisi_hba);
	if (rc)
		goto err_out_debugfs;
	dev_err(dev, "%d hw queues\n", shost->nr_hw_queues);
		goto err_out_free_host;

	rc = scsi_add_host(shost, dev);
	if (rc)
		goto err_out_debugfs;
		goto err_out_free_host;

	rc = sas_register_ha(sha);
	if (rc)
@@ -4947,6 +4944,8 @@ hisi_sas_v3_probe(struct pci_dev *pdev, const struct pci_device_id *id)
		goto err_out_hw_init;

	scsi_scan_host(shost);
	if (hisi_sas_debugfs_enable)
		debugfs_init_v3_hw(hisi_hba);

	pm_runtime_set_autosuspend_delay(dev, 5000);
	pm_runtime_use_autosuspend(dev);
@@ -4967,10 +4966,7 @@ hisi_sas_v3_probe(struct pci_dev *pdev, const struct pci_device_id *id)
	sas_unregister_ha(sha);
err_out_register_ha:
	scsi_remove_host(shost);
err_out_debugfs:
	if (hisi_sas_debugfs_enable)
		debugfs_exit_v3_hw(hisi_hba);
err_out_ha:
err_out_free_host:
	hisi_sas_free(hisi_hba);
	scsi_host_put(shost);
err_out_regions:
@@ -5005,6 +5001,8 @@ static void hisi_sas_v3_remove(struct pci_dev *pdev)
	struct Scsi_Host *shost = sha->core.shost;

	pm_runtime_get_noresume(dev);
	if (hisi_sas_debugfs_enable)
		debugfs_exit_v3_hw(hisi_hba);

	sas_unregister_ha(sha);
	flush_workqueue(hisi_hba->wq);
@@ -5014,8 +5012,6 @@ static void hisi_sas_v3_remove(struct pci_dev *pdev)
	pci_release_regions(pdev);
	pci_disable_device(pdev);
	hisi_sas_free(hisi_hba);
	if (hisi_sas_debugfs_enable)
		debugfs_exit_v3_hw(hisi_hba);
	scsi_host_put(shost);
}