]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
commands/videoinfo: Prevent crash when run while video driver already active
authorGlenn Washburn <development@efficientek.com>
Fri, 11 Aug 2023 21:30:04 +0000 (16:30 -0500)
committerDaniel Kiper <daniel.kiper@oracle.com>
Mon, 14 Aug 2023 16:04:04 +0000 (18:04 +0200)
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
command 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>
grub-core/commands/videoinfo.c

index 5eb969748b0ef8e0a46b8a43b0332177644aa0ae..205ba78c9f7bbaeb9fa4a08e1c9c5c5cbe307bb4 100644 (file)
@@ -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 ())