perf/x86/intel/uncore: Fix integer overflow on 23 bit left shift of a u32
Subsystems (3)
PATCH 1/1 perf/x86/intel/uncore: Fix integer overflow on 23 bit left shift of a u32
From: Colin Ian King <[email protected]>
The u32 variable pci_dword is being masked with 0x1fffffff and then left shifted 23 places. The shift is a u32 operation,so a value of 0x200 or more in pci_dword will overflow the u32 and only the bottow 32 bits are assigned to addr. I don't believe this was the original intent. Fix this by casting pci_dword to a resource_size_t to ensure no overflow occurs.
Note that the mask and 12 bit left shift operation does not need this because the mask SNR_IMC_MMIO_MEM0_MASK and shift is always a 32 bit value.
Addresses-Coverity: ("Unintentional integer overflow")
--- arch/x86/events/intel/uncore_snbep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/events/intel/uncore_snbep.c +1 -1
@@ -4827,7 +4827,7 @@ static int snr_uncore_mmio_map(struct intel_uncore_box *box,return -ENODEV ;pci_read_config_dword (pdev,SNR_IMC_MMIO_BASE_OFFSET , &pci_dword); - addr = (pci_dword &SNR_IMC_MMIO_BASE_MASK ) <<23 ; + addr = ((resource_size_t )pci_dword &SNR_IMC_MMIO_BASE_MASK ) <<23 ;pci_read_config_dword (pdev, mem_offset, &pci_dword); addr |= (pci_dword &SNR_IMC_MMIO_MEM0_MASK ) <<12 ;
Signature · 1 line
2.31.1
Quoted 9 lines · Colin King
From: Colin Ian King <[email protected]>
The u32 variable
pci_dwordis being masked with0x1fffffffand then left shifted 23 places. The shift is a u32 operation,so a value of0x200or more inpci_dwordwill overflow the u32 and only the bottow 32 bits are assigned to addr. I don't believe this was the original intent. Fix this by castingpci_dwordto aresource_size_tto ensure no overflow occurs.
Quoted 6 lines
Note that the mask and 12 bit left shift operation does not need this because the mask
SNR_IMC_MMIO_MEM0_MASKand shift is always a 32 bit value.Fixes ee49532b38dd ("perf/x86/intel/uncore: Add IMC uncore support for Snow Ridge")Addresses-Coverity: ("Unintentional integer overflow")
Thanks for the fix.
Thanks,
Kan
Quoted 19 lines
Signed-off-by Colin Ian King <[email protected]>--- arch/x86/events/intel/uncore_snbep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/events/intel/uncore_snbep.c +1
-1@@ -4827,7 +4827,7 @@ static int snr_uncore_mmio_map(struct intel_uncore_box *box,return -ENODEV ;pci_read_config_dword (pdev,SNR_IMC_MMIO_BASE_OFFSET , &pci_dword); - addr = (pci_dword &SNR_IMC_MMIO_BASE_MASK ) <<23 ; + addr = ((resource_size_t )pci_dword &SNR_IMC_MMIO_BASE_MASK ) <<23 ;pci_read_config_dword (pdev, mem_offset, &pci_dword); addr |= (pci_dword &SNR_IMC_MMIO_MEM0_MASK ) <<12 ;
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 92279a3b11a0a8486ce6b92384ddc0849eb4060f Gitweb: https://git.kernel.org/tip/92279a3b11a0a8486ce6b92384ddc0849eb4060f Author: Colin Ian King <[email protected]> AuthorDate: Tue, 06 Jul 2021 12:45:53 +01:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 16 Jul 2021 18:46:48 +02:00
perf/x86/intel/uncore: Fix integer overflow on 23 bit left shift of a u32
The u32 variable pci_dword is being masked with 0x1fffffff and then left shifted 23 places. The shift is a u32 operation,so a value of 0x200 or more in pci_dword will overflow the u32 and only the bottow 32 bits are assigned to addr. I don't believe this was the original intent. Fix this by casting pci_dword to a resource_size_t to ensure no overflow occurs.
Note that the mask and 12 bit left shift operation does not need this because the mask SNR_IMC_MMIO_MEM0_MASK and shift is always a 32 bit value.
Addresses-Coverity: ("Unintentional integer overflow")
--- arch/x86/events/intel/uncore_snbep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/events/intel/uncore_snbep.c +1 -1
@@ -4834,7 +4834,7 @@ static int snr_uncore_mmio_map(struct intel_uncore_box *box,return -ENODEV ;pci_read_config_dword (pdev,SNR_IMC_MMIO_BASE_OFFSET , &pci_dword); - addr = (pci_dword &SNR_IMC_MMIO_BASE_MASK ) <<23 ; + addr = ((resource_size_t )pci_dword &SNR_IMC_MMIO_BASE_MASK ) <<23 ;pci_read_config_dword (pdev, mem_offset, &pci_dword); addr |= (pci_dword &SNR_IMC_MMIO_MEM0_MASK ) <<12 ;
The following commit has been merged into the perf/urgent branch of tip:
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: 0b3a8738b76fe2087f7bc2bd59f4c78504c79180 Gitweb: https://git.kernel.org/tip/0b3a8738b76fe2087f7bc2bd59f4c78504c79180 Author: Colin Ian King <[email protected]> AuthorDate: Tue, 06 Jul 2021 12:45:53 +01:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Thu, 26 Aug 2021 08:58:02 +02:00
perf/x86/intel/uncore: Fix integer overflow on 23 bit left shift of a u32
The u32 variable pci_dword is being masked with 0x1fffffff and then left shifted 23 places. The shift is a u32 operation,so a value of 0x200 or more in pci_dword will overflow the u32 and only the bottow 32 bits are assigned to addr. I don't believe this was the original intent. Fix this by casting pci_dword to a resource_size_t to ensure no overflow occurs.
Note that the mask and 12 bit left shift operation does not need this because the mask SNR_IMC_MMIO_MEM0_MASK and shift is always a 32 bit value.
Addresses-Coverity: ("Unintentional integer overflow")
--- arch/x86/events/intel/uncore_snbep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/events/intel/uncore_snbep.c +1 -1
@@ -4811,7 +4811,7 @@ static void __snr_uncore_mmio_init_box(struct intel_uncore_box *box,return ;pci_read_config_dword (pdev,SNR_IMC_MMIO_BASE_OFFSET , &pci_dword); - addr = (pci_dword &SNR_IMC_MMIO_BASE_MASK ) <<23 ; + addr = ((resource_size_t )pci_dword &SNR_IMC_MMIO_BASE_MASK ) <<23 ;pci_read_config_dword (pdev, mem_offset, &pci_dword); addr |= (pci_dword &SNR_IMC_MMIO_MEM0_MASK ) <<12 ;