Skip to content

Commit cdc15a8

Browse files
KobaKoNvidianirmoy
authored andcommitted
NVIDIA: SAUCE: vfio/nvgrace-egm: Add null pointer checks after memory allocations
Add missing null pointer checks after vzalloc() calls in the NVIDIA Grace GPU driver's EGM (External GPU Memory) handling code. This prevents potential null pointer dereferences in the memory failure handling and bad page fetching functions, providing proper error handling for allocation failures. Signed-off-by: Koba Ko <kobak@nvidia.com> Acked-by: Matthew R. Ochs <mochs@nvidia.com> Acked-by: Carol L. Soto <csoto@nvidia.com> Signed-off-by: Matthew R. Ochs <mochs@nvidia.com> (cherry picked from commit 63127e2 https://github.com/NVIDIA/NV-Kernels/tree/24.04_linux-nvidia-adv-6.11-next) Signed-off-by: Nirmoy Das <nirmoyd@nvidia.com>
1 parent 4cfef70 commit cdc15a8

File tree

1 file changed

+4
-0
lines changed
  • drivers/vfio/pci/nvgrace-gpu

1 file changed

+4
-0
lines changed

drivers/vfio/pci/nvgrace-gpu/egm.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ nvgrace_egm_pfn_memory_failure(struct pfn_address_space *pfn_space,
6262
* MM has called to notify a poisoned page. Track that in the hastable.
6363
*/
6464
ecc = (struct h_node *)(vzalloc(sizeof(struct h_node)));
65+
if (!ecc)
66+
return; /* Silently fail on allocation error */
6567
ecc->mem_offset = mem_offset;
6668
hash_add(region->htbl, &ecc->node, ecc->mem_offset);
6769
}
@@ -349,6 +351,8 @@ static void nvgrace_egm_fetch_bad_pages(struct pci_dev *pdev,
349351
* apps.
350352
*/
351353
retired_page = (struct h_node *)(vzalloc(sizeof(struct h_node)));
354+
if (!retired_page)
355+
continue; /* Skip this entry on allocation failure */
352356
retired_page->mem_offset = *((u64 *)memaddr + index + 1) -
353357
region->egmphys;
354358
hash_add(region->htbl, &retired_page->node, retired_page->mem_offset);

0 commit comments

Comments
 (0)