tty: vt: sanitize arguments of consw::con_clear()
authorJiri Slaby (SUSE) <jirislaby@kernel.org>
Mon, 22 Jan 2024 11:03:35 +0000 (12:03 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 28 Jan 2024 02:08:53 +0000 (18:08 -0800)
In consw::con_clear():
* Height is always 1, so drop it.
* Offsets and width are always unsigned values, so re-type them as such.

This needs a new __fbcon_clear() in the fbcon code to still handle
height which might not be 1 when called internally.

Note that tests for negative count/width are left in place -- they are
taken care of in the next patches.

And document the hook.

Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Cc: Helge Deller <deller@gmx.de>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: linux-fbdev@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
Cc: linux-parisc@vger.kernel.org
Tested-by: Helge Deller <deller@gmx.de> # parisc STI console
Link: https://lore.kernel.org/r/20240122110401.7289-22-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/vt/vt.c
drivers/video/console/dummycon.c
drivers/video/console/mdacon.c
drivers/video/console/newport_con.c
drivers/video/console/sticon.c
drivers/video/console/vgacon.c
drivers/video/fbdev/core/fbcon.c
include/linux/console.h

index fcb41c8724f3970f77390dc8e68949fdcffd266f..b6f1449421bc34c916949261a23774fce4ab03bf 100644 (file)
@@ -1585,7 +1585,7 @@ static void csi_X(struct vc_data *vc)
        vc_uniscr_clear_line(vc, vc->state.x, count);
        scr_memsetw((unsigned short *)vc->vc_pos, vc->vc_video_erase_char, 2 * count);
        if (con_should_update(vc))
-               vc->vc_sw->con_clear(vc, vc->state.y, vc->state.x, 1, count);
+               vc->vc_sw->con_clear(vc, vc->state.y, vc->state.x, count);
        vc->vc_need_wrap = 0;
 }
 
index f2cef9d9a4b509681421bf4fd1a13a46349840c1..0a69d5c216ee0e83e76863bdd4e2ff421cea906c 100644 (file)
@@ -109,8 +109,8 @@ static void dummycon_init(struct vc_data *vc, bool init)
 }
 
 static void dummycon_deinit(struct vc_data *vc) { }
-static void dummycon_clear(struct vc_data *vc, int sy, int sx, int height,
-                          int width) { }
+static void dummycon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx,
+                          unsigned int width) { }
 static void dummycon_cursor(struct vc_data *vc, int mode) { }
 
 static bool dummycon_scroll(struct vc_data *vc, unsigned int top,
index c5b255c9687947b89d360ccabec124e10e65a961..1ddbb6cd5b0ca8ec59786e84ef773de12cc8317b 100644 (file)
@@ -442,23 +442,18 @@ static void mdacon_putcs(struct vc_data *c, const unsigned short *s,
        }
 }
 
-static void mdacon_clear(struct vc_data *c, int y, int x, 
-                         int height, int width)
+static void mdacon_clear(struct vc_data *c, unsigned int y, unsigned int x,
+                        unsigned int width)
 {
        u16 *dest = mda_addr(x, y);
        u16 eattr = mda_convert_attr(c->vc_video_erase_char);
 
-       if (width <= 0 || height <= 0)
+       if (width <= 0)
                return;
 
-       if (x==0 && width==mda_num_columns) {
-               scr_memsetw(dest, eattr, height*width*2);
-       } else {
-               for (; height > 0; height--, dest+=mda_num_columns)
-                       scr_memsetw(dest, eattr, width*2);
-       }
+       scr_memsetw(dest, eattr, width * 2);
 }
-                        
+
 static int mdacon_switch(struct vc_data *c)
 {
        return 1;       /* redrawing needed */
index 12c64ef470877bb3030d2c7c128e93600db43f22..55c6106b3507b927feb81da0a44532f8920685dd 100644 (file)
@@ -346,12 +346,12 @@ static void newport_deinit(struct vc_data *c)
        }
 }
 
-static void newport_clear(struct vc_data *vc, int sy, int sx, int height,
-                         int width)
+static void newport_clear(struct vc_data *vc, unsigned int sy, unsigned int sx,
+                         unsigned int width)
 {
        int xend = ((sx + width) << 3) - 1;
        int ystart = ((sy << 4) + topscan) & 0x3ff;
-       int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff;
+       int yend = (((sy + 1) << 4) + topscan - 1) & 0x3ff;
 
        if (logo_active)
                return;
index 0bfeabc3f7c72ff4136f8c2d6f221c4bdf5c734f..d99c2a659bfd4b153ce069dfee3654916292c41a 100644 (file)
@@ -300,13 +300,13 @@ static void sticon_deinit(struct vc_data *c)
        sticon_set_def_font(i);
 }
 
-static void sticon_clear(struct vc_data *conp, int sy, int sx, int height,
-                        int width)
+static void sticon_clear(struct vc_data *conp, unsigned int sy, unsigned int sx,
+                        unsigned int width)
 {
-    if (!height || !width)
+    if (!width)
        return;
 
-    sti_clear(sticon_sti, sy, sx, height, width,
+    sti_clear(sticon_sti, sy, sx, 1, width,
              conp->vc_video_erase_char, font_data[conp->vc_num]);
 }
 
index 5d523753def87722bd028b8cbbcede09b71fffde..85f29dec2c3d4aa57f43ed37c7c286963bf8ce9b 100644 (file)
@@ -1191,8 +1191,8 @@ static bool vgacon_scroll(struct vc_data *c, unsigned int t, unsigned int b,
  *  The console `switch' structure for the VGA based console
  */
 
-static void vgacon_clear(struct vc_data *vc, int sy, int sx, int height,
-                        int width) { }
+static void vgacon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx,
+                        unsigned int width) { }
 static void vgacon_putc(struct vc_data *vc, int c, int ypos, int xpos) { }
 static void vgacon_putcs(struct vc_data *vc, const unsigned short *s,
                         int count, int ypos, int xpos) { }
index 939c5d893dfbe891b743a001d04fd47f65c3d77b..8a31a36483ea6b44a87150aeec96e3737699c152 100644 (file)
@@ -1235,8 +1235,8 @@ finished:
  *  restriction is simplicity & efficiency at the moment.
  */
 
-static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
-                       int width)
+static void __fbcon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx,
+                         unsigned int height, unsigned int width)
 {
        struct fb_info *info = fbcon_info_from_console(vc->vc_num);
        struct fbcon_ops *ops = info->fbcon_par;
@@ -1273,6 +1273,12 @@ static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
                ops->clear(vc, info, real_y(p, sy), sx, height, width);
 }
 
+static void fbcon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx,
+                       unsigned int width)
+{
+       __fbcon_clear(vc, sy, sx, 1, width);
+}
+
 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
                        int count, int ypos, int xpos)
 {
@@ -1760,7 +1766,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
                case SCROLL_MOVE:
                        fbcon_redraw_blit(vc, info, p, t, b - t - count,
                                     count);
-                       fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
+                       __fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
                        scr_memsetw((unsigned short *) (vc->vc_origin +
                                                        vc->vc_size_row *
                                                        (b - count)),
@@ -1783,7 +1789,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
                                            b - t - count, vc->vc_cols);
                        else
                                goto redraw_up;
-                       fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
+                       __fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
                        break;
 
                case SCROLL_PAN_REDRAW:
@@ -1801,7 +1807,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
                                                          vc->vc_rows - b, b);
                        } else
                                fbcon_redraw_move(vc, p, t + count, b - t - count, t);
-                       fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
+                       __fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
                        break;
 
                case SCROLL_PAN_MOVE:
@@ -1824,14 +1830,14 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
                                            b - t - count, vc->vc_cols);
                        else
                                goto redraw_up;
-                       fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
+                       __fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
                        break;
 
                case SCROLL_REDRAW:
                      redraw_up:
                        fbcon_redraw(vc, t, b - t - count,
                                     count * vc->vc_cols);
-                       fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
+                       __fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
                        scr_memsetw((unsigned short *) (vc->vc_origin +
                                                        vc->vc_size_row *
                                                        (b - count)),
@@ -1848,7 +1854,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
                case SCROLL_MOVE:
                        fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
                                     -count);
-                       fbcon_clear(vc, t, 0, count, vc->vc_cols);
+                       __fbcon_clear(vc, t, 0, count, vc->vc_cols);
                        scr_memsetw((unsigned short *) (vc->vc_origin +
                                                        vc->vc_size_row *
                                                        t),
@@ -1871,7 +1877,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
                                            b - t - count, vc->vc_cols);
                        else
                                goto redraw_down;
-                       fbcon_clear(vc, t, 0, count, vc->vc_cols);
+                       __fbcon_clear(vc, t, 0, count, vc->vc_cols);
                        break;
 
                case SCROLL_PAN_MOVE:
@@ -1893,7 +1899,7 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
                                            b - t - count, vc->vc_cols);
                        else
                                goto redraw_down;
-                       fbcon_clear(vc, t, 0, count, vc->vc_cols);
+                       __fbcon_clear(vc, t, 0, count, vc->vc_cols);
                        break;
 
                case SCROLL_PAN_REDRAW:
@@ -1910,14 +1916,14 @@ static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
                                        fbcon_redraw_move(vc, p, count, t, 0);
                        } else
                                fbcon_redraw_move(vc, p, t, b - t - count, t + count);
-                       fbcon_clear(vc, t, 0, count, vc->vc_cols);
+                       __fbcon_clear(vc, t, 0, count, vc->vc_cols);
                        break;
 
                case SCROLL_REDRAW:
                      redraw_down:
                        fbcon_redraw(vc, b - 1, b - t - count,
                                     -count * vc->vc_cols);
-                       fbcon_clear(vc, t, 0, count, vc->vc_cols);
+                       __fbcon_clear(vc, t, 0, count, vc->vc_cols);
                        scr_memsetw((unsigned short *) (vc->vc_origin +
                                                        vc->vc_size_row *
                                                        t),
@@ -2196,7 +2202,7 @@ static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
 
                oldc = vc->vc_video_erase_char;
                vc->vc_video_erase_char &= charmask;
-               fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
+               __fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
                vc->vc_video_erase_char = oldc;
        }
 }
index fc9450e0c78ff64c7aefb6bb63b0f01be09825c4..8fd96a5fca5f7acb76791fc05d9162e0780649ec 100644 (file)
@@ -38,6 +38,7 @@ enum vc_intensity;
  *
  * @con_init:   initialize the console on @vc. @init is true for the very first
  *             call on this @vc.
+ * @con_clear:  erase @count characters at [@x, @y] on @vc. @count >= 1.
  * @con_scroll: move lines from @top to @bottom in direction @dir by @lines.
  *             Return true if no generic handling should be done.
  *             Invoked by csi_M and printing to the console.
@@ -50,8 +51,8 @@ struct consw {
        const char *(*con_startup)(void);
        void    (*con_init)(struct vc_data *vc, bool init);
        void    (*con_deinit)(struct vc_data *vc);
-       void    (*con_clear)(struct vc_data *vc, int sy, int sx, int height,
-                       int width);
+       void    (*con_clear)(struct vc_data *vc, unsigned int y,
+                            unsigned int x, unsigned int count);
        void    (*con_putc)(struct vc_data *vc, int c, int ypos, int xpos);
        void    (*con_putcs)(struct vc_data *vc, const unsigned short *s,
                        int count, int ypos, int xpos);