linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
To: Kai Jiang <b18973@freescale.com>
Cc: linux-fbdev-devel@lists.sourceforge.net
Subject: Re:  [linux-fbdev-devel][PATCH]fb_pan_display:add x/yoffset check
Date: Mon, 06 Jul 2009 16:12:50 +0200	[thread overview]
Message-ID: <4A520662.1030504@gmx.de> (raw)
In-Reply-To: <4A5168D3.3050502@freescale.com>

Kai Jiang schrieb:
> Florian Tobias Schandinat wrote:
>> Ville Syrjälä schrieb:
>>>> So here we have to check the whether the x/yoffset is smaller than 
>>>> zero. If the offset is smaller than zero, in the driver, we should 
>>>> not move the virtual screen any more.
>>>
>>> Checking for overflow will catch you buggy application's negative
>>> values too.
>>
>> That's true, but the problem lies in the current implementation first 
>> adding the resolution, which results in small negative [0 to 
>> -resolution] values (=large positives) being accepted as they overflow 
>> during add and become small positive values.
>> I'd recommend changing
>>
>> var->yoffset + yres > info->var.yres_virtual ||
>> var->xoffset + info->var.xres > info->var.xres_virtual
>>
>> to
>>
>> var->yoffset > info->var.yres_virtual - yres ||
>> var->xoffset > info->var.xres_virtual - info->var.xres
>>
> I am not sure why do we have these change. Could you give a detail 
> description or an example?

A small program to illustrate it:

#include <stdio.h>
int main()
{
         unsigned int    a = -1;
         printf( "%X\n%X\n", a, a+1 );
         return 0;
}

It starts with "-1" in an u32 being represented as "0xFFFFFFFF", which 
would be caught by ">". The problem in the current code is it first adds 
the resolution before comparison and this causes an overflow.
Let's say the virtual resolution matches the real resolution:
yoffset + yres > yres
There the left side is evaluated at first:
(yoffset + yres)
You accept everything that is <=yres. In classical mathematics you would 
say yoffset has to be 0, but unfortunately this codes accept many more 
as it can overflow. You get
yoffset = -1:	(yres-1) > yres
offset = -yres:	0 > yres
So as you noticed, the current code will not just accept 0 as yoffset, 
but the whole range [-yres..0]. This can be fixed by moving the 
calculation to the right side, where we have trusted values, that do not 
cause an overflow.

Hope this helps.


Greetings,

Florian Tobias Schandinat

------------------------------------------------------------------------------

  reply	other threads:[~2009-07-06 14:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-29  3:49 [linux-fbdev-devel][PATCH]fb_pan_display:add x/yoffset check Kai Jiang
2009-06-29 10:39 ` Ville Syrjälä
2009-06-30  3:25   ` Kai Jiang
2009-07-03 15:30     ` Ville Syrjälä
2009-07-03 16:11       ` Florian Tobias Schandinat
2009-07-06  3:00         ` Kai Jiang
2009-07-06 14:12           ` Florian Tobias Schandinat [this message]
2009-07-07  2:43             ` Kai Jiang
2009-07-07  4:01               ` Florian Tobias Schandinat
2009-07-10  8:22                 ` Kai Jiang
2009-08-03 18:58                   ` [PATCH] fb: fix fb_pan_display range check Florian Tobias Schandinat
2009-07-06  2:54       ` [linux-fbdev-devel][PATCH]fb_pan_display:add x/yoffset check Kai Jiang

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=4A520662.1030504@gmx.de \
    --to=florianschandinat@gmx.de \
    --cc=b18973@freescale.com \
    --cc=linux-fbdev-devel@lists.sourceforge.net \
    /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;
as well as URLs for NNTP newsgroup(s).