* [PATCH] kern: perform NULL check in unregister paths (command/extcmd)
@ 2025-09-08 18:10 Srish Srinivasan
2025-09-09 5:01 ` Sudhakar Kuppusamy
0 siblings, 1 reply; 3+ messages in thread
From: Srish Srinivasan @ 2025-09-08 18:10 UTC (permalink / raw)
To: grub-devel
Cc: daniel.kiper, phcoder, sudhakar, stefanb, nayna, sridharm, ssrish
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] kern: perform NULL check in unregister paths (command/extcmd)
2025-09-08 18:10 [PATCH] kern: perform NULL check in unregister paths (command/extcmd) Srish Srinivasan
@ 2025-09-09 5:01 ` Sudhakar Kuppusamy
2025-09-09 6:51 ` Srish Srinivasan
0 siblings, 1 reply; 3+ messages in thread
From: Sudhakar Kuppusamy @ 2025-09-09 5:01 UTC (permalink / raw)
To: Srish Srinivasan
Cc: grub-devel, daniel.kiper, phcoder, stefanb, nayna, sridharm
> On 8 Sep 2025, at 11:40 PM, Srish Srinivasan <ssrish@linux.ibm.com> wrote:
>
> 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)
For pointer, use ext == NULL
> + return;
It would be nice if add empty line here
> 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)
For pointer, use cmd == NULL
> + return;
It would be nice if add empty line here
Thanks,
Sudhakar
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kern: perform NULL check in unregister paths (command/extcmd)
2025-09-09 5:01 ` Sudhakar Kuppusamy
@ 2025-09-09 6:51 ` Srish Srinivasan
0 siblings, 0 replies; 3+ messages in thread
From: Srish Srinivasan @ 2025-09-09 6:51 UTC (permalink / raw)
To: The development of GNU GRUB, Sudhakar Kuppusamy
Cc: daniel.kiper, phcoder, stefanb, nayna, sridharm
On 9/9/25 10:31 AM, Sudhakar Kuppusamy wrote:
>
>> On 8 Sep 2025, at 11:40 PM, Srish Srinivasan <ssrish@linux.ibm.com> wrote:
>>
>> 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)
> For pointer, use ext == NULL
>> + return;
> It would be nice if add empty line here
>> 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)
> For pointer, use cmd == NULL
>> + return;
> It would be nice if add empty line here
>
> Thanks,
> Sudhakar
Hi Sudhakar,
Thanks for the review.
Will send out v2 with the fixes.
>> 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
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-09 6:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-08 18:10 [PATCH] kern: perform NULL check in unregister paths (command/extcmd) Srish Srinivasan
2025-09-09 5:01 ` Sudhakar Kuppusamy
2025-09-09 6:51 ` Srish Srinivasan
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.