diff mbox series

fbcon: Out-Of-Bounds write in sys_imageblit, add range check

Message ID D5DF8A1C-5FA2-426B-AAB4-3199AEA0A02E@tencent.com (mailing list archive)
State New, archived
Headers show
Series fbcon: Out-Of-Bounds write in sys_imageblit, add range check | expand

Commit Message

tcs_kernel(腾讯云内核开发者) July 26, 2021, 11:32 a.m. UTC
yres and vyres can be controlled by user mode paramaters, and cause p->vrows to become a negative value. While this value be passed to real_y function, the ypos will be out of screen range.
This is an out-of-bounds write bug.

Comments

tcs_kernel(腾讯云内核开发者) July 27, 2021, 1:53 a.m. UTC | #1
yres and vyres can be controlled by user mode paramaters, and cause p->vrows to become a negative value. While this value be passed to real_y function, the ypos will be out of screen range.
This is an out-of-bounds write bug.
I think updatescrollmode is the right place to validate values supplied by a user ioctl, because only here makes --operation,and 0 is a legal value before that.

Signed-off-by: Tencent Cloud System tcs_kernel@tencent.com

diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
index 22bb3892f6bd..0970de46782f 100644
--- a/drivers/video/fbdev/core/fbcon.c
+++ b/drivers/video/fbdev/core/fbcon.c
@@ -1956,11 +1956,12 @@ static void updatescrollmode(struct fbcon_display *p,
        int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
        int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
                                   info->var.xres_virtual);
+       int rows = vc->vc_rows;
 
        p->vrows = vyres/fh;
-       if (yres > (fh * (vc->vc_rows + 1)))
-               p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
-       if ((yres % fh) && (vyres % fh < yres % fh))
+       if ((yres > (fh * (rows + 1))) && (vyres >= (yres - (fh * rows))) && p->vrows)
+               p->vrows -= (yres - (fh * rows)) / fh;
+       if ((yres % fh) && (vyres % fh < yres % fh) && p->vrows)
                p->vrows--;
 }

在 2021/7/26 21:45,“Sam Ravnborg”<sam@ravnborg.org> 写入:

    Hi,
    On Mon, Jul 26, 2021 at 11:32:37AM +0000, tcs_kernel(腾讯云内核开发者) wrote:
    > yres and vyres can be controlled by user mode paramaters, and cause p->vrows to become a negative value. While this value be passed to real_y function, the ypos will be out of screen range.
    > This is an out-of-bounds write bug.

    Please investigate if you can validate the user-supplied values for yres
    and vyres earlier so the code never reaches the below statements.
    This would also make it much more explicit what is going on.

    	Sam

    > 
    > 
    > diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
    > index 22bb3892f6bd..0970de46782f 100644
    > --- a/drivers/video/fbdev/core/fbcon.c
    > +++ b/drivers/video/fbdev/core/fbcon.c
    > @@ -1956,11 +1956,12 @@ static void updatescrollmode(struct fbcon_display *p,
    >         int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
    >         int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
    >                                    info->var.xres_virtual);
    > +       int rows = vc->vc_rows;
    >  
    >         p->vrows = vyres/fh;
    > -       if (yres > (fh * (vc->vc_rows + 1)))
    > -               p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
    > -       if ((yres % fh) && (vyres % fh < yres % fh))
    > +       if ((yres > (fh * (rows + 1))) && (vyres >= (yres - (fh * rows))) && p->vrows)
    > +               p->vrows -= (yres - (fh * rows)) / fh;
    > +       if ((yres % fh) && (vyres % fh < yres % fh) && p->vrows)
    >                 p->vrows--;
    >  }
    >
Greg KH July 27, 2021, 5:35 a.m. UTC | #2
On Tue, Jul 27, 2021 at 01:53:13AM +0000, tcs_kernel(腾讯云内核开发者) wrote:
> yres and vyres can be controlled by user mode paramaters, and cause p->vrows to become a negative value. While this value be passed to real_y function, the ypos will be out of screen range.
> This is an out-of-bounds write bug.
> I think updatescrollmode is the right place to validate values supplied by a user ioctl, because only here makes --operation,and 0 is a legal value before that.

Please wrap your changelog text.

> 
> Signed-off-by: Tencent Cloud System tcs_kernel@tencent.com

That is not the name of a person :(

And the format isn't correct, so there's nothing we can do with this
patch, and the patch itself is corrupted and could not be applied :(

Also, what about checking these values earlier?  How can the value be 0
earlier and be acceptable?  Putting bounds on the user-provided values
would be much easier, right?

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
index 22bb3892f6bd..0970de46782f 100644
--- a/drivers/video/fbdev/core/fbcon.c
+++ b/drivers/video/fbdev/core/fbcon.c
@@ -1956,11 +1956,12 @@  static void updatescrollmode(struct fbcon_display *p,
        int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
        int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
                                   info->var.xres_virtual);
+       int rows = vc->vc_rows;
 
        p->vrows = vyres/fh;
-       if (yres > (fh * (vc->vc_rows + 1)))
-               p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
-       if ((yres % fh) && (vyres % fh < yres % fh))
+       if ((yres > (fh * (rows + 1))) && (vyres >= (yres - (fh * rows))) && p->vrows)
+               p->vrows -= (yres - (fh * rows)) / fh;
+       if ((yres % fh) && (vyres % fh < yres % fh) && p->vrows)
                p->vrows--;
 }