All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] commands/videoinfo: Prevent crash when run while video driver already active
@ 2023-08-11 21:30 Glenn Washburn
  2023-08-14 14:04 ` Daniel Kiper
  0 siblings, 1 reply; 2+ messages in thread
From: Glenn Washburn @ 2023-08-11 21:30 UTC (permalink / raw)
  To: grub-devel, Daniel Kiper; +Cc: Glenn Washburn

The videoinfo command will initialize all non-active video adapters. Video
drivers tend to zero out the global framebuffer object on initialization.
This is not a problem when there is no active video adapter. However, when
there is, then outputting to the video adapter will cause a crash because
methods in the framebuffer object are reinitialized. For example, this
comand sequence will cause a crash.

  terminal_output --append gfxterm; videoinfo

When running in a QEMU headless with GRUB built for the x86_64-efi target,
the first command initializes the Bochs video adapter, which, among
other things, sets the set_page() member function. Then when videoinfo is
run, all non-Bochs video adapters will be initialized, each one wiping
the framebuffer and thus setting set_page to NULL. Soon after the videoinfo
command finishes there will be a call to grub_refresh(), which will
ultimately call the framebuffer's set_page which will be NULL and cause
a crash when called.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 grub-core/commands/videoinfo.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/grub-core/commands/videoinfo.c b/grub-core/commands/videoinfo.c
index 5eb969748b0e..205ba78c9f7b 100644
--- a/grub-core/commands/videoinfo.c
+++ b/grub-core/commands/videoinfo.c
@@ -191,6 +191,11 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
 	  /* Don't worry about errors.  */
 	  grub_errno = GRUB_ERR_NONE;
       }
+    else if (id != GRUB_VIDEO_DRIVER_NONE)
+      {
+	grub_puts_ (N_("  A video driver is active, cannot initialize this driver until it is deactivated\n"));
+	continue;
+      }
     else
       {
 	if (adapter->init ())
-- 
2.34.1


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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] commands/videoinfo: Prevent crash when run while video driver already active
  2023-08-11 21:30 [PATCH] commands/videoinfo: Prevent crash when run while video driver already active Glenn Washburn
@ 2023-08-14 14:04 ` Daniel Kiper
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Kiper @ 2023-08-14 14:04 UTC (permalink / raw)
  To: Glenn Washburn; +Cc: grub-devel

On Fri, Aug 11, 2023 at 04:30:04PM -0500, Glenn Washburn wrote:
> The videoinfo command will initialize all non-active video adapters. Video
> drivers tend to zero out the global framebuffer object on initialization.
> This is not a problem when there is no active video adapter. However, when
> there is, then outputting to the video adapter will cause a crash because
> methods in the framebuffer object are reinitialized. For example, this
> comand sequence will cause a crash.
>
>   terminal_output --append gfxterm; videoinfo
>
> When running in a QEMU headless with GRUB built for the x86_64-efi target,
> the first command initializes the Bochs video adapter, which, among
> other things, sets the set_page() member function. Then when videoinfo is
> run, all non-Bochs video adapters will be initialized, each one wiping
> the framebuffer and thus setting set_page to NULL. Soon after the videoinfo
> command finishes there will be a call to grub_refresh(), which will
> ultimately call the framebuffer's set_page which will be NULL and cause
> a crash when called.
>
> Signed-off-by: Glenn Washburn <development@efficientek.com>

Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>

Daniel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-14 14:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-11 21:30 [PATCH] commands/videoinfo: Prevent crash when run while video driver already active Glenn Washburn
2023-08-14 14:04 ` Daniel Kiper

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.