Hello Mike,

Thank you for addressing the framebuffer validation issues. I have a few
observations regarding the additional checks.

Reported by: Alperen Erkan <[email protected]>
---
 i386/i386at/immc.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/i386/i386at/immc.c b/i386/i386at/immc.c
index 6e4d9661..c9d6cf66 100644
--- a/i386/i386at/immc.c
+++ b/i386/i386at/immc.c
@@ -132,6 +132,11 @@ immc_putc(char c)
 #define IMMC_MAXCOLS 160
 #define IMMC_MAXROWS  60

+/* These unlikely minima ensure that the code functions without
+   breaking limits for assertions and so on. */
+#define IMMC_MINCOLS   1
+#define IMMC_MINROWS   2
+
 static uint8_t  immc_matrix[IMMC_MAXCOLS * IMMC_MAXROWS];
 static uint8_t *immc_fb_vaddr;

The introduction of explicit minimum dimensions is reasonable.

It would be useful to document the specific invariants that require at
least one column and two
rows, rather than referring to assertion limits in general.

@@ -169,6 +174,7 @@ immc_l2_table[NPTES] __aligned(PAGE_SIZE);
 static pt_entry_t
 immc_l1_tables[IMMC_FB_NUM_PAGETABLES][NPTES] __aligned(PAGE_SIZE);

+/* A successful initialisation results in a non-NULL fb_vaddr. */
 static void
 immc_enable_fb(const uint64_t paddr,
               const uint32_t pitch,
@@ -177,10 +183,13 @@ immc_enable_fb(const uint64_t paddr,
               const uint8_t  bpp)
 {
   uint64_t fb_size = ((uint64_t)pitch * (uint64_t)height);
-
   const uint64_t paddr_end = round_page (paddr + fb_size);
   uint64_t paddr_map = trunc_page (paddr);

+  /* Check for bogus input parameters. */
+  if (pitch == 0 || paddr_end < paddr_map)
+    return;
+
   memset (immc_l3_table, 0, sizeof (immc_l3_table));
   memset (immc_l2_table, 0, sizeof (immc_l2_table));

The zero-pitch check addresses the division-by-zero concern raised in patch
1/3.

However, the comparison between paddr_end and paddr_map does not
necessarily
detect all possible arithmetic wraparound cases.

Both the addition of paddr and fb_size and the subsequent page rounding are
performed
before the validation.

I suggest explicitly validating the addition against UINT64_MAX and
ensuring that sufficient
headroom remains for page rounding before evaluating round_page().

The width-times-bytes-per-pixel overflow concern raised in patch 1/3 also
remains applicable.

Minor documentation point: the function comment refers to fb_vaddr, whereas
the actual variable is
named immc_fb_vaddr.

@@ -236,7 +245,8 @@ immc_enable_fb(const uint64_t paddr,
           if (immc_cols > IMMC_MAXCOLS)
             immc_cols = IMMC_MAXCOLS;

-         if (fb_disp_set_dimensions (immc_cols, immc_rows, immc_matrix))
+         if (immc_cols >= IMMC_MINCOLS && immc_rows >= IMMC_MINROWS
+             && fb_disp_set_dimensions (immc_cols, immc_rows, immc_matrix))
             immc_fb_vaddr = IMMC_FB_VADDR;
         }

The explicit minimum dimension checks are appropriate and address the
original concern regarding
undersized framebuffer configurations.

Apart from the arithmetic validation concern above, the changes appear
reasonable.

This review is based on static analysis. I have not compiled or tested the
patch at runtime.

Best regards,
Alperen Erkan

On Tue, Dec 1, 2026 at 9:44 AM Mike Kelly <[email protected]> wrote:

> Reported by: Alperen Erkan <[email protected]>
> ---
>  i386/i386at/immc.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/i386/i386at/immc.c b/i386/i386at/immc.c
> index 6e4d9661..c9d6cf66 100644
> --- a/i386/i386at/immc.c
> +++ b/i386/i386at/immc.c
> @@ -132,6 +132,11 @@ immc_putc(char c)
>  #define IMMC_MAXCOLS 160
>  #define IMMC_MAXROWS  60
>
> +/* These unlikely minima ensure that the code functions without
> +   breaking limits for assertions and so on. */
> +#define IMMC_MINCOLS   1
> +#define IMMC_MINROWS   2
> +
>  static uint8_t  immc_matrix[IMMC_MAXCOLS * IMMC_MAXROWS];
>  static uint8_t *immc_fb_vaddr;
>
> @@ -169,6 +174,7 @@ immc_l2_table[NPTES] __aligned(PAGE_SIZE);
>  static pt_entry_t
>  immc_l1_tables[IMMC_FB_NUM_PAGETABLES][NPTES] __aligned(PAGE_SIZE);
>
> +/* A successful initialisation results in a non-NULL fb_vaddr. */
>  static void
>  immc_enable_fb(const uint64_t paddr,
>                const uint32_t pitch,
> @@ -177,10 +183,13 @@ immc_enable_fb(const uint64_t paddr,
>                const uint8_t  bpp)
>  {
>    uint64_t fb_size = ((uint64_t)pitch * (uint64_t)height);
> -
>    const uint64_t paddr_end = round_page (paddr + fb_size);
>    uint64_t paddr_map = trunc_page (paddr);
>
> +  /* Check for bogus input parameters. */
> +  if (pitch == 0 || paddr_end < paddr_map)
> +    return;
> +
>    memset (immc_l3_table, 0, sizeof (immc_l3_table));
>    memset (immc_l2_table, 0, sizeof (immc_l2_table));
>
> @@ -236,7 +245,8 @@ immc_enable_fb(const uint64_t paddr,
>           if (immc_cols > IMMC_MAXCOLS)
>             immc_cols = IMMC_MAXCOLS;
>
> -         if (fb_disp_set_dimensions (immc_cols, immc_rows, immc_matrix))
> +         if (immc_cols >= IMMC_MINCOLS && immc_rows >= IMMC_MINROWS
> +             && fb_disp_set_dimensions (immc_cols, immc_rows,
> immc_matrix))
>             immc_fb_vaddr = IMMC_FB_VADDR;
>         }
>
> --
> 2.47.3
>
>
>

Reply via email to