All of lore.kernel.org
 help / color / mirror / Atom feed
From: Srish Srinivasan <ssrish@linux.ibm.com>
To: grub-devel@gnu.org
Cc: daniel.kiper@oracle.com, phcoder@gmail.com,
	sudhakar@linux.ibm.com, stefanb@linux.ibm.com,
	nayna@linux.ibm.com, sridharm@linux.ibm.com,
	ssrish@linux.ibm.com
Subject: [PATCH] kern: perform NULL check in unregister paths (command/extcmd)
Date: Mon,  8 Sep 2025 23:40:49 +0530	[thread overview]
Message-ID: <20250908181049.141996-1-ssrish@linux.ibm.com> (raw)

Many modules call grub_unregister_{command(), extcmd()} from
GRUB_MOD_FINI() without checking for a failure in registration.
This could lead to a NULL pointer dereference in unregistration.

Perform explicit NULL check in both the unregister helpers.

Signed-off-by: Srish Srinivasan <ssrish@linux.ibm.com>
---
 grub-core/commands/extcmd.c | 2 ++
 grub-core/kern/command.c    | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/grub-core/commands/extcmd.c b/grub-core/commands/extcmd.c
index c236be13a..f142305ed 100644
--- a/grub-core/commands/extcmd.c
+++ b/grub-core/commands/extcmd.c
@@ -139,6 +139,8 @@ grub_register_extcmd_lockdown (const char *name, grub_extcmd_func_t func,
 void
 grub_unregister_extcmd (grub_extcmd_t ext)
 {
+  if (!ext)
+    return;
   grub_unregister_command (ext->cmd);
   grub_free (ext);
 }
diff --git a/grub-core/kern/command.c b/grub-core/kern/command.c
index 5812e131c..3ab93ce20 100644
--- a/grub-core/kern/command.c
+++ b/grub-core/kern/command.c
@@ -104,6 +104,8 @@ grub_register_command_lockdown (const char *name,
 void
 grub_unregister_command (grub_command_t cmd)
 {
+  if (!cmd)
+    return;
   if ((cmd->prio & GRUB_COMMAND_FLAG_ACTIVE) && (cmd->next))
     cmd->next->prio |= GRUB_COMMAND_FLAG_ACTIVE;
   grub_list_remove (GRUB_AS_LIST (cmd));
-- 
2.48.1


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

             reply	other threads:[~2025-09-08 19:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-08 18:10 Srish Srinivasan [this message]
2025-09-09  5:01 ` [PATCH] kern: perform NULL check in unregister paths (command/extcmd) Sudhakar Kuppusamy
2025-09-09  6:51   ` Srish Srinivasan

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=20250908181049.141996-1-ssrish@linux.ibm.com \
    --to=ssrish@linux.ibm.com \
    --cc=daniel.kiper@oracle.com \
    --cc=grub-devel@gnu.org \
    --cc=nayna@linux.ibm.com \
    --cc=phcoder@gmail.com \
    --cc=sridharm@linux.ibm.com \
    --cc=stefanb@linux.ibm.com \
    --cc=sudhakar@linux.ibm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.