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: Tue, 07 Jul 2009 06:01:10 +0200	[thread overview]
Message-ID: <4A52C886.4090605@gmx.de> (raw)
In-Reply-To: <4A52B63D.2050000@freescale.com>

Kai Jiang schrieb:
> While, I suppose when the patch is applied, it should avoid what you 
> mentioned. Following is the code applied patch.
> (And the x/yres and x/yres_virtual have fix value which are defined and 
> checked in the driver.)

That's true as my explanation described the problem with the current 
code you encountered.
I also think that your patch will fix it:

> fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var)
> {      ......
>         int xoffset = var->xoffset;                 // here transfer 
> x/yoffset to "int" type for comparison
>         int yoffset = var->yoffset;
>        ......
>         if (err || !info->fbops->fb_pan_display ||
>             var->yoffset + yres > info->var.yres_virtual ||        
>             var->xoffset + info->var.xres > info->var.xres_virtual ||    
>             xoffset < 0 || yoffset < 0)             // insure the 
> x/yoffset is large than 0. I think this line can avoid what you concerned.
>                 return -EINVAL;
>        ......
> }

I only wanted to highlight, that as far as I can see the same behavior 
you want to archive can be archived by changing the current code to:

fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var)
{
        ......
         if (err || !info->fbops->fb_pan_display ||
             var->yoffset > info->var.yres_virtual - yres ||
             var->xoffset > info->var.xres_virtual - info->var.xres)
                 return -EINVAL;
        ......
}

> Do you think so? I am happy to know your comments.

I think your patch is fine as it fixes the accepted invalid value.
There are only a few small disadvantages:
- its a bit odd to convert unsigned to signed value to check its validity
- it adds 2 extra compares
- although not practically relevant, as virtual resolutions>2^31 would 
require an enormous amount of video memory, it would be too strict on 
this side (by checking for signedness in u32 you half the range of 
allowed numbers)

I first got Ville Syrjälä second email a bit wrong (sorry for that). He 
suggests to change your check to an overflow check:

fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var)
{
        ......
         if (err || !info->fbops->fb_pan_display ||
             var->yoffset + yres > info->var.yres_virtual ||
             var->xoffset + info->var.xres > info->var.xres_virtual ||
             var->yoffset + yres < yres ||
             var->xoffset + info->var.xres < info->var.xres)
                 return -EINVAL;
      ......
}

while my approach is to prevent the overflow.
I hope that after my last e-mail you understand, that all 3 suggested 
approaches (yours, mine, Ville Syrjälä) should fix (at least in my 
opinion) your problem. (as negative values don't exist in unsigned types 
or are actually very large positive integers)


Greetings,

Florian Tobias Schandinat

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have 
the opportunity to enter the BlackBerry Developer Challenge. See full prize 
details at: http://p.sf.net/sfu/blackberry

  reply	other threads:[~2009-07-07  4:06 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
2009-07-07  2:43             ` Kai Jiang
2009-07-07  4:01               ` Florian Tobias Schandinat [this message]
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=4A52C886.4090605@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).