Skip to contentSkip to conversation

alpha: kernel: module: Adding branch statements after allocating memory for kmalloc

PATCH New Li kunyu 1 participant 1 message Mar 24, 2023 Alpha port

lore
Share & tools
lore

Li kunyu

author
#0 lore raw

PATCH 1/1 alpha: kernel: module: Adding branch statements after allocating memory for kmalloc

After looking at the process_reloc_for_got function and where it is called, I decided to use a branch statement to increase the robustness of the pointer g.

If pointer g allocation fails, when 'chains [i]. next' is executed, it can avoid crashes caused by wild pointers.

---
 arch/alpha/kernel/module.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
arch/alpha/kernel/module.c +9 -5
index cbefa5a77384..8c97f10347a7 100644
@@ -47,11 +47,15 @@ process_reloc_for_got(Elf64_Rela *rela,
 		}
 
 	g = kmalloc (sizeof (*g), GFP_KERNEL);
-	g->next = chains[r_sym].next;
-	g->r_addend = r_addend;
-	g->got_offset = *poffset;
-	*poffset += 8;
-	chains[r_sym].next = g;
+	if (g) {
+		g->next = chains[r_sym].next;
+		g->r_addend = r_addend;
+		g->got_offset = *poffset;
+		*poffset += 8;
+		chains[r_sym].next = g;
+	}
+	else
+		chains[r_sym].next = NULL;
 
  found_entry:
 	/* Trick: most of the ELF64_R_TYPE field is unused.  There are
Signature · 1 line
2.18.2