linux-stable/drivers/iommu
Alexander Lobakin 73ce2046e0 iommu/vt-d: avoid invalid memory access via node_online(NUMA_NO_NODE)
[ Upstream commit b0b0b77ea6 ]

KASAN reports:

[ 4.668325][ T0] BUG: KASAN: wild-memory-access in dmar_parse_one_rhsa (arch/x86/include/asm/bitops.h:214 arch/x86/include/asm/bitops.h:226 include/asm-generic/bitops/instrumented-non-atomic.h:142 include/linux/nodemask.h:415 drivers/iommu/intel/dmar.c:497)
[    4.676149][    T0] Read of size 8 at addr 1fffffff85115558 by task swapper/0/0
[    4.683454][    T0]
[    4.685638][    T0] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.19.0-rc3-00004-g0e862838f290 #1
[    4.694331][    T0] Hardware name: Supermicro SYS-5018D-FN4T/X10SDV-8C-TLN4F, BIOS 1.1 03/02/2016
[    4.703196][    T0] Call Trace:
[    4.706334][    T0]  <TASK>
[ 4.709133][ T0] ? dmar_parse_one_rhsa (arch/x86/include/asm/bitops.h:214 arch/x86/include/asm/bitops.h:226 include/asm-generic/bitops/instrumented-non-atomic.h:142 include/linux/nodemask.h:415 drivers/iommu/intel/dmar.c:497)

after converting the type of the first argument (@nr, bit number)
of arch_test_bit() from `long` to `unsigned long`[0].

Under certain conditions (for example, when ACPI NUMA is disabled
via command line), pxm_to_node() can return %NUMA_NO_NODE (-1).
It is valid 'magic' number of NUMA node, but not valid bit number
to use in bitops.
node_online() eventually descends to test_bit() without checking
for the input, assuming it's on caller side (which might be good
for perf-critical tasks). There, -1 becomes %ULONG_MAX which leads
to an insane array index when calculating bit position in memory.

For now, add an explicit check for @node being not %NUMA_NO_NODE
before calling test_bit(). The actual logics didn't change here
at all.

[0] 0e862838f2

Fixes: ee34b32d8c ("dmar: support for parsing Remapping Hardware Static Affinity structure")
Cc: stable@vger.kernel.org # 2.6.33+
Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-08-17 14:42:22 +02:00
..
amd iommu/amd: Increase timeout waiting for GA log enablement 2022-06-09 10:30:37 +02:00
arm iommu/arm-smmu: qcom_iommu: Add of_node_put() when breaking out of loop 2022-08-17 14:42:08 +02:00
intel iommu/vt-d: avoid invalid memory access via node_online(NUMA_NO_NODE) 2022-08-17 14:42:22 +02:00
Kconfig iommu/sva: Rename CONFIG_IOMMU_SVA_LIB to CONFIG_IOMMU_SVA 2022-02-14 19:17:46 +01:00
Makefile iommu/sva: Rename CONFIG_IOMMU_SVA_LIB to CONFIG_IOMMU_SVA 2022-02-14 19:17:46 +01:00
apple-dart.c iommu/dart: Add missing module owner to ops structure 2022-05-04 10:36:25 +02:00
dma-iommu.c iommu/dma: Fix iova map result check bug 2022-06-09 10:30:51 +02:00
exynos-iommu.c iommu/exynos: Handle failed IOMMU device registration properly 2022-08-17 14:42:06 +02:00
fsl_pamu.c
fsl_pamu.h
fsl_pamu_domain.c iommu: Split struct iommu_ops 2022-02-28 13:25:49 +01:00
fsl_pamu_domain.h
hyperv-iommu.c
io-pgfault.c
io-pgtable-arm-v7s.c iommu/io-pgtable-arm-v7s: Add error handle for page table allocation failure 2021-12-14 14:45:35 +00:00
io-pgtable-arm.c iommu/io-pgtable-arm: Fix table descriptor paddr formatting 2021-12-06 13:03:01 +01:00
io-pgtable-arm.h
io-pgtable.c
ioasid.c iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit 2022-02-15 11:31:35 +01:00
iommu-debugfs.c
iommu-sva-lib.c iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit 2022-02-15 11:31:35 +01:00
iommu-sva-lib.h iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit 2022-02-15 11:31:35 +01:00
iommu-sysfs.c
iommu-traces.c
iommu.c iommu: Make sysfs robust for non-API groups 2022-05-04 15:13:39 +02:00
iova.c iommu/iova: Improve 32-bit free space estimate 2022-03-04 10:40:40 +01:00
ipmmu-vmsa.c iommu/ipmmu-vmsa: Fix compatible for rcar-gen4 2022-06-29 09:04:34 +02:00
irq_remapping.c
irq_remapping.h
msm_iommu.c iommu/msm: Fix an incorrect NULL check on list iterator 2022-06-09 10:30:51 +02:00
msm_iommu.h
msm_iommu_hw-8xxx.h
mtk_iommu.c iommu/mediatek: Fix NULL pointer dereference when printing dev_name 2022-06-09 10:30:35 +02:00
mtk_iommu.h iommu/mediatek: Add mutex for m4u_group and m4u_dom in data 2022-06-09 10:30:35 +02:00
mtk_iommu_v1.c iommu/mediatek: Fix NULL pointer dereference when printing dev_name 2022-06-09 10:30:35 +02:00
of_iommu.c
omap-iommu-debug.c
omap-iommu.c iommu/omap: Fix regression in probe for NULL pointer dereference 2022-04-08 11:16:29 +02:00
omap-iommu.h
omap-iopgtable.h
rockchip-iommu.c Merge branches 'arm/mediatek', 'arm/msm', 'arm/renesas', 'arm/rockchip', 'arm/smmu', 'x86/vt-d' and 'x86/amd' into next 2022-03-08 12:21:31 +01:00
s390-iommu.c iommu: Split struct iommu_ops 2022-02-28 13:25:49 +01:00
sprd-iommu.c iommu: Split struct iommu_ops 2022-02-28 13:25:49 +01:00
sun50i-iommu.c iommu: Split struct iommu_ops 2022-02-28 13:25:49 +01:00
tegra-gart.c iommu: Split struct iommu_ops 2022-02-28 13:25:49 +01:00
tegra-smmu.c Merge branches 'arm/mediatek', 'arm/msm', 'arm/renesas', 'arm/rockchip', 'arm/smmu', 'x86/vt-d' and 'x86/amd' into next 2022-03-08 12:21:31 +01:00
virtio-iommu.c iommu: Split struct iommu_ops 2022-02-28 13:25:49 +01:00