
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IC03L1 -------------------------------- Before checking smmu->flag, it is necessary to first verify whether the smmu pointer is valid. Otherwise, when an iommu_group is not attached with any SMMU device yet, the smmu pointer will be NULL, which can lead to a memory access exception: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000018 Call trace: arm_smmu_group_get_mpam+0x30/0x150 iommu_group_get_qos_params+0x70/0xb0 resctrl_arch_match_iommu_closid+0x38/0x98 show_rdt_iommu+0xc8/0xe0 show_rdt_tasks+0x110/0x150 rdtgroup_tasks_show+0x38/0x68 rdtgroup_seqfile_show+0x38/0x58 kernfs_seq_show+0x34/0x48 seq_read_iter+0x1d4/0x4e8 kernfs_fop_read_iter+0x40/0x58 new_sync_read+0xa4/0x110 vfs_read+0x19c/0x200 Fixes: b5b8955197cf ("iommu/arm-smmu-v3: Add mpam helpers to query and set state") Signed-off-by: Zeng Heng <zengheng4@huawei.com> --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index dbe13f6e5f1c..0f923cd53858 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -4020,6 +4020,10 @@ static int arm_smmu_group_set_mpam(struct iommu_group *group, u16 partid, domain = iommu_get_domain_for_group(group); smmu_domain = to_smmu_domain(domain); + + if (!smmu_domain || !smmu_domain->smmu) + return -EINVAL; + if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_MPAM)) return -EIO; smmu = smmu_domain->smmu; @@ -4065,6 +4069,10 @@ static int arm_smmu_group_get_mpam(struct iommu_group *group, u16 *partid, domain = iommu_get_domain_for_group(group); smmu_domain = to_smmu_domain(domain); + + if (!smmu_domain || !smmu_domain->smmu) + return 0; + if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_MPAM)) return -EIO; -- 2.25.1