From: "Màxim Pedraza Padilla" <maximpedraza@gmail.com>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Ard Biesheuvel <ardb@kernel.org>,
Jonathan Corbet <corbet@lwn.net>, Helge Deller <deller@gmx.de>,
Peter Jones <pjones@redhat.com>
Cc: Francesco Valla <francesco@valla.it>,
Jani Nikula <jani.nikula@linux.intel.com>,
Mario Limonciello <mario.limonciello@amd.com>,
Javier Martinez Canillas <javierm@redhat.com>,
Jocelyn Falempe <jfalempe@redhat.com>,
Sam Ravnborg <sam@ravnborg.org>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
linux-efi@vger.kernel.org, linux-fbdev@vger.kernel.org,
linux-doc@vger.kernel.org, linux-embedded@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v6 03/15] fbdev: efifb: move the BMP headers to <video/bmp.h>
Date: Tue, 27 Oct 2026 14:53:30 +0100 [thread overview]
Message-ID: <20261027135342.2003632-4-maximpedraza@gmail.com> (raw)
In-Reply-To: <20261027135342.2003632-1-maximpedraza@gmail.com>
The DRM splash client parses the same BMP headers as efifb. Rather than
keep a second copy of the structures, move them to include/video/bmp.h
with the magic number.
BMP is little endian whatever the CPU, so the header gives the fields
as __le16 and __le32, and efifb now reads them with
get_unaligned_le16() and get_unaligned_le32(). Width and height are
read signed, as the format has them. No change on the little endian
systems EFI runs on.
Suggested-by: Thomas Zimmermann <tzimmermann@suse.de>
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Màxim Pedraza Padilla <maximpedraza@gmail.com>
---
Notes:
TODO for the efifb maintainers, not changed here so that this patch
only moves the headers: the bound check
if ((bitmap_offset + bmp_pitch * bmp_height) > bgrt_image_size)
is done in u32 and can wrap with a crafted BGRT image, for instance
with a bitmap_offset close to 4 GiB, and so can round_up(3 * bmp_width,
4) and the product with a huge width; image_offset_x + bmp_width against
lfb_width is a u32 sum too. efifb_copy_bmp() would then read outside the
mapped image. The DRM splash client checks the same headers with
check_add_overflow() and check_mul_overflow(). I can send a separate fix
if wanted.
drivers/video/fbdev/efifb.c | 49 ++++++++++++++-----------------------
include/video/bmp.h | 40 ++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 31 deletions(-)
create mode 100644 include/video/bmp.h
diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c
index 3411be06d3e6..fd348a72f780 100644
--- a/drivers/video/fbdev/efifb.c
+++ b/drivers/video/fbdev/efifb.c
@@ -16,32 +16,13 @@
#include <linux/platform_device.h>
#include <linux/printk.h>
#include <linux/sysfb.h>
+#include <linux/unaligned.h>
+#include <video/bmp.h>
#include <video/vga.h>
#include <asm/efi.h>
#include <drm/drm_connector.h> /* For DRM_MODE_PANEL_ORIENTATION_* */
#include <drm/drm_panel_quirks.h> /* For drm_get_panel_orientation_quirk */
-struct bmp_file_header {
- u16 id;
- u32 file_size;
- u32 reserved;
- u32 bitmap_offset;
-} __packed;
-
-struct bmp_dib_header {
- u32 dib_header_size;
- s32 width;
- s32 height;
- u16 planes;
- u16 bpp;
- u32 compression;
- u32 bitmap_size;
- u32 horz_resolution;
- u32 vert_resolution;
- u32 colors_used;
- u32 colors_important;
-} __packed;
-
static bool use_bgrt = true;
static bool request_mem_succeeded = false;
static u64 mem_flags = EFI_MEMORY_WC | EFI_MEMORY_UC;
@@ -145,9 +126,10 @@ static bool efifb_bgrt_sanity_check(const struct screen_info *si, u32 bmp_width)
static void efifb_show_boot_graphics(struct fb_info *info, const struct screen_info *si)
{
- u32 bmp_width, bmp_height, bmp_pitch, dst_x, y, src_y;
+ u32 bmp_width, bmp_height, bmp_pitch, bitmap_offset, dst_x, y, src_y;
struct bmp_file_header *file_header;
struct bmp_dib_header *dib_header;
+ s32 width, height;
void *bgrt_image = NULL;
u8 *dst = info->screen_base;
@@ -186,20 +168,25 @@ static void efifb_show_boot_graphics(struct fb_info *info, const struct screen_i
goto error;
file_header = bgrt_image;
- if (file_header->id != 0x4d42 || file_header->reserved != 0)
+ if (get_unaligned_le16(&file_header->id) != BMP_FILE_MAGIC_ID ||
+ get_unaligned_le32(&file_header->reserved) != 0)
goto error;
+ bitmap_offset = get_unaligned_le32(&file_header->bitmap_offset);
dib_header = bgrt_image + sizeof(*file_header);
- if (dib_header->dib_header_size != 40 || dib_header->width < 0 ||
- dib_header->planes != 1 || dib_header->bpp != 24 ||
- dib_header->compression != 0)
+ width = get_unaligned_le32(&dib_header->width);
+ height = get_unaligned_le32(&dib_header->height);
+ if (get_unaligned_le32(&dib_header->dib_header_size) != 40 ||
+ width < 0 || get_unaligned_le16(&dib_header->planes) != 1 ||
+ get_unaligned_le16(&dib_header->bpp) != 24 ||
+ get_unaligned_le32(&dib_header->compression) != 0)
goto error;
- bmp_width = dib_header->width;
- bmp_height = abs(dib_header->height);
+ bmp_width = width;
+ bmp_height = abs(height);
bmp_pitch = round_up(3 * bmp_width, 4);
- if ((file_header->bitmap_offset + bmp_pitch * bmp_height) >
+ if ((bitmap_offset + bmp_pitch * bmp_height) >
bgrt_image_size)
goto error;
@@ -222,12 +209,12 @@ static void efifb_show_boot_graphics(struct fb_info *info, const struct screen_i
src_y = y - bgrt_tab.image_offset_y;
/* Positive header height means upside down row order */
- if (dib_header->height > 0)
+ if (height > 0)
src_y = (bmp_height - 1) - src_y;
memset(dst, 0, bgrt_tab.image_offset_x * 4);
dst_x = bgrt_tab.image_offset_x;
- efifb_copy_bmp(bgrt_image + file_header->bitmap_offset +
+ efifb_copy_bmp(bgrt_image + bitmap_offset +
src_y * bmp_pitch,
(u32 *)dst + dst_x, bmp_width, si);
dst_x += bmp_width;
diff --git a/include/video/bmp.h b/include/video/bmp.h
new file mode 100644
index 000000000000..8aa249f2302f
--- /dev/null
+++ b/include/video/bmp.h
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _VIDEO_BMP_H
+#define _VIDEO_BMP_H
+
+#include <linux/types.h>
+
+/* "BM", the first two bytes of a BMP file */
+#define BMP_FILE_MAGIC_ID 0x4d42
+
+/*
+ * The headers at the start of a BMP file. Every field is little endian,
+ * whatever the CPU, and the headers need not be aligned in memory: read them
+ * with get_unaligned_le16() and get_unaligned_le32().
+ */
+struct bmp_file_header {
+ __le16 id;
+ __le32 file_size;
+ __le32 reserved;
+ __le32 bitmap_offset;
+} __packed;
+
+/*
+ * BITMAPINFOHEADER. Width and height are signed: a negative width means
+ * nothing, and a negative height that the rows go top to bottom.
+ */
+struct bmp_dib_header {
+ __le32 dib_header_size;
+ __le32 width;
+ __le32 height;
+ __le16 planes;
+ __le16 bpp;
+ __le32 compression;
+ __le32 bitmap_size;
+ __le32 horz_resolution;
+ __le32 vert_resolution;
+ __le32 colors_used;
+ __le32 colors_important;
+} __packed;
+
+#endif /* _VIDEO_BMP_H */
--
2.39.5
next prev parent reply other threads:[~2026-10-27 13:53 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 13:53 [PATCH v6 00/15] Add splash DRM client Màxim Pedraza Padilla
2026-10-27 13:53 ` [PATCH v6 01/15] drm/clients: Kconfig: indent DRM_CLIENT_DEFAULT with tabs Màxim Pedraza Padilla
2026-10-27 13:53 ` [PATCH v6 02/15] efi: bgrt: add accessors for the boot graphics Màxim Pedraza Padilla
2026-10-27 13:53 ` Màxim Pedraza Padilla [this message]
2026-10-27 13:53 ` [PATCH v6 04/15] drm: client: add splash client Màxim Pedraza Padilla
2026-10-27 13:53 ` [PATCH v6 05/15] MAINTAINERS: add entry for DRM " Màxim Pedraza Padilla
2026-10-27 13:53 ` [PATCH v6 06/15] drm: docs: remove bootsplash from TODO Màxim Pedraza Padilla
2026-10-27 13:53 ` [PATCH v6 07/15] dt-bindings: display: add a boot logo node under /chosen Màxim Pedraza Padilla
2026-10-27 18:59 ` Rob Herring (Arm)
2026-10-27 13:53 ` [PATCH v6 08/15] drm/client: splash: pick the image source in one place Màxim Pedraza Padilla
2026-10-27 13:53 ` [PATCH v6 09/15] drm/client: splash: add a device tree image source Màxim Pedraza Padilla
2026-10-27 13:53 ` [PATCH v6 10/15] drm/client: splash: place the device tree image where it asks Màxim Pedraza Padilla
2026-10-27 13:53 ` [PATCH v6 11/15] drm/client: splash: turn the device tree image as " Màxim Pedraza Padilla
2026-10-27 13:53 ` [PATCH v6 12/15] drm/client: splash: take the background colour from the image source Màxim Pedraza Padilla
2026-10-27 13:53 ` [PATCH v6 13/15] drm/client: splash: turn the BGRT image on panels mounted turned Màxim Pedraza Padilla
2026-10-27 13:53 ` [PATCH v6 14/15] drm/client: splash: follow the connector's orientation Màxim Pedraza Padilla
2026-10-27 13:53 ` [PATCH v6 15/15] drm/client: splash: document the image sources Màxim Pedraza Padilla
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=20261027135342.2003632-4-maximpedraza@gmail.com \
--to=maximpedraza@gmail.com \
--cc=airlied@gmail.com \
--cc=ardb@kernel.org \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=deller@gmx.de \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=francesco@valla.it \
--cc=ilias.apalodimas@linaro.org \
--cc=jani.nikula@linux.intel.com \
--cc=javierm@redhat.com \
--cc=jfalempe@redhat.com \
--cc=krzk+dt@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-embedded@vger.kernel.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mario.limonciello@amd.com \
--cc=mripard@kernel.org \
--cc=pjones@redhat.com \
--cc=rdunlap@infradead.org \
--cc=robh@kernel.org \
--cc=sam@ravnborg.org \
--cc=simona@ffwll.ch \
--cc=skhan@linuxfoundation.org \
--cc=tzimmermann@suse.de \
/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®