linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fbcon: Out-Of-Bounds write in sys_imageblit, add range check
@ 2021-07-26 11:32 tcs_kernel(腾讯云内核开发者)
  2021-07-26 13:00 ` gregkh
       [not found] ` <YP68cQ4WVVusCv0N@ravnborg.org>
  0 siblings, 2 replies; 4+ messages in thread
From: tcs_kernel(腾讯云内核开发者) @ 2021-07-26 11:32 UTC (permalink / raw)
  To: gregkh, daniel.vetter, yepeilin.cs, penguin-kernel, tzimmermann,
	george.kennedy, ducheng2, sam
  Cc: dri-devel, linux-fbdev, linux-kernel

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.


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--;
 }


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fbcon: Out-Of-Bounds write in sys_imageblit, add range check
  2021-07-26 11:32 [PATCH] fbcon: Out-Of-Bounds write in sys_imageblit, add range check tcs_kernel(腾讯云内核开发者)
@ 2021-07-26 13:00 ` gregkh
       [not found] ` <YP68cQ4WVVusCv0N@ravnborg.org>
  1 sibling, 0 replies; 4+ messages in thread
From: gregkh @ 2021-07-26 13:00 UTC (permalink / raw)
  To: tcs_kernel(腾讯云内核开发者)
  Cc: daniel.vetter, yepeilin.cs, penguin-kernel@I-love.SAKURA.ne.jp,
	tzimmermann, george.kennedy, ducheng2, sam, dri-devel,
	linux-fbdev, linux-kernel

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.
> 
> 
> 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--;
>  }
> 

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- Your patch is malformed (tabs converted to spaces, linewrapped, etc.)
  and can not be applied.  Please read the file,
  Documentation/email-clients.txt in order to fix this.

- Your patch does not have a Signed-off-by: line.  Please read the
  kernel file, Documentation/SubmittingPatches and resend it after
  adding that line.  Note, the line needs to be in the body of the
  email, before the patch, not at the bottom of the patch or in the
  email signature.

- You did not specify a description of why the patch is needed, or
  possibly, any description at all, in the email body.  Please read the
  section entitled "The canonical patch format" in the kernel file,
  Documentation/SubmittingPatches for what is needed in order to
  properly describe the change.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Internet]Re: [PATCH] fbcon: Out-Of-Bounds write in sys_imageblit, add range check
       [not found] ` <YP68cQ4WVVusCv0N@ravnborg.org>
@ 2021-07-27  1:53   ` tcs_kernel(腾讯云内核开发者)
  2021-07-27  5:35     ` gregkh
  0 siblings, 1 reply; 4+ messages in thread
From: tcs_kernel(腾讯云内核开发者) @ 2021-07-27  1:53 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: gregkh, daniel.vetter, yepeilin.cs,
	penguin-kernel@I-love.SAKURA.ne.jp, tzimmermann, george.kennedy,
	ducheng2, dri-devel, linux-fbdev, linux-kernel

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--;
    >  }
    > 



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Internet]Re: [PATCH] fbcon: Out-Of-Bounds write in sys_imageblit, add range check
  2021-07-27  1:53   ` [Internet]Re: " tcs_kernel(腾讯云内核开发者)
@ 2021-07-27  5:35     ` gregkh
  0 siblings, 0 replies; 4+ messages in thread
From: gregkh @ 2021-07-27  5:35 UTC (permalink / raw)
  To: tcs_kernel(腾讯云内核开发者)
  Cc: Sam Ravnborg, daniel.vetter, yepeilin.cs,
	penguin-kernel@I-love.SAKURA.ne.jp, tzimmermann, george.kennedy,
	ducheng2, dri-devel, linux-fbdev, linux-kernel

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-27  5:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-26 11:32 [PATCH] fbcon: Out-Of-Bounds write in sys_imageblit, add range check tcs_kernel(腾讯云内核开发者)
2021-07-26 13:00 ` gregkh
     [not found] ` <YP68cQ4WVVusCv0N@ravnborg.org>
2021-07-27  1:53   ` [Internet]Re: " tcs_kernel(腾讯云内核开发者)
2021-07-27  5:35     ` gregkh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).