From: Li kunyu <kunyu@nfschina.com>
To: richard.henderson@linaro.org, ink@jurassic.park.msu.ru,
mattst88@gmail.com, aurxenon@lunos.org
Cc: linux-kernel@vger.kernel.org, Li kunyu <kunyu@nfschina.com>
Subject: [PATCH] alpha: kernel: module: Adding branch statements after allocating memory for kmalloc
Date: Sun, 26 Mar 2023 03:25:30 +0800 [thread overview]
Message-ID: <20230325192530.3298-1-kunyu@nfschina.com> (raw)
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.
Signed-off-by: Li kunyu <kunyu@nfschina.com>
---
arch/alpha/kernel/module.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
index cbefa5a77384..8c97f10347a7 100644
--- a/arch/alpha/kernel/module.c
+++ b/arch/alpha/kernel/module.c
@@ -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
--
2.18.2
reply other threads:[~2023-03-24 2:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230325192530.3298-1-kunyu@nfschina.com \
--to=kunyu@nfschina.com \
--cc=aurxenon@lunos.org \
--cc=ink@jurassic.park.msu.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=mattst88@gmail.com \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®