* [PATCH 0/3] drm: A few misc patches
@ 2012-05-24 17:53 ville.syrjala
2012-05-24 17:53 ` [PATCH 1/3] drm: Use stdint types for consistency ville.syrjala
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: ville.syrjala @ 2012-05-24 17:53 UTC (permalink / raw)
To: dri-devel
Just a few small items caught in my net while trawling the code.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] drm: Use stdint types for consistency
2012-05-24 17:53 [PATCH 0/3] drm: A few misc patches ville.syrjala
@ 2012-05-24 17:53 ` ville.syrjala
2012-05-24 17:53 ` [PATCH 2/3] drm: Be more paranoid with integer overflows ville.syrjala
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: ville.syrjala @ 2012-05-24 17:53 UTC (permalink / raw)
To: dri-devel
From: Ville Syrjälä <ville.syrjala@linux.intel.com>
The rest of the code uses stdint types, so use them in
drm_property_change_is_valid() as well.
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
drivers/gpu/drm/drm_crtc.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 92cea9d..80a34e7 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -3126,7 +3126,7 @@ int drm_mode_connector_update_edid_property(struct drm_connector *connector,
EXPORT_SYMBOL(drm_mode_connector_update_edid_property);
static bool drm_property_change_is_valid(struct drm_property *property,
- __u64 value)
+ uint64_t value)
{
if (property->flags & DRM_MODE_PROP_IMMUTABLE)
return false;
@@ -3136,7 +3136,7 @@ static bool drm_property_change_is_valid(struct drm_property *property,
return true;
} else if (property->flags & DRM_MODE_PROP_BITMASK) {
int i;
- __u64 valid_mask = 0;
+ uint64_t valid_mask = 0;
for (i = 0; i < property->num_values; i++)
valid_mask |= (1ULL << property->values[i]);
return !(value & ~valid_mask);
--
1.7.3.4
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] drm: Be more paranoid with integer overflows
2012-05-24 17:53 [PATCH 0/3] drm: A few misc patches ville.syrjala
2012-05-24 17:53 ` [PATCH 1/3] drm: Use stdint types for consistency ville.syrjala
@ 2012-05-24 17:53 ` ville.syrjala
2012-05-24 18:30 ` Daniel Vetter
2012-05-24 17:54 ` [PATCH 3/3] drm: Constify params to format_check() and framebuffer_checks() ville.syrjala
2012-05-24 18:16 ` [PATCH 0/3] drm: A few misc patches Alex Deucher
3 siblings, 1 reply; 8+ messages in thread
From: ville.syrjala @ 2012-05-24 17:53 UTC (permalink / raw)
To: dri-devel
From: Ville Syrjälä <ville.syrjala@linux.intel.com>
Make sure 'width * cpp' and 'height * pitch + offset' don't exceed
UINT_MAX.
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
drivers/gpu/drm/drm_crtc.c | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 80a34e7..e1b53fb 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -2211,13 +2211,21 @@ static int framebuffer_check(struct drm_mode_fb_cmd2 *r)
for (i = 0; i < num_planes; i++) {
unsigned int width = r->width / (i != 0 ? hsub : 1);
+ unsigned int height = r->height / (i != 0 ? vsub : 1);
+ unsigned int cpp = drm_format_plane_cpp(r->pixel_format, i);
if (!r->handles[i]) {
DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i);
return -EINVAL;
}
- if (r->pitches[i] < drm_format_plane_cpp(r->pixel_format, i) * width) {
+ if ((uint64_t) width * cpp > UINT_MAX)
+ return -ERANGE;
+
+ if ((uint64_t) height * r->pitches[i] + r->offsets[i] > UINT_MAX)
+ return -ERANGE;
+
+ if (r->pitches[i] < width * cpp) {
DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r->pitches[i], i);
return -EINVAL;
}
--
1.7.3.4
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] drm: Constify params to format_check() and framebuffer_checks()
2012-05-24 17:53 [PATCH 0/3] drm: A few misc patches ville.syrjala
2012-05-24 17:53 ` [PATCH 1/3] drm: Use stdint types for consistency ville.syrjala
2012-05-24 17:53 ` [PATCH 2/3] drm: Be more paranoid with integer overflows ville.syrjala
@ 2012-05-24 17:54 ` ville.syrjala
2012-05-24 18:16 ` [PATCH 0/3] drm: A few misc patches Alex Deucher
3 siblings, 0 replies; 8+ messages in thread
From: ville.syrjala @ 2012-05-24 17:54 UTC (permalink / raw)
To: dri-devel
From: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
drivers/gpu/drm/drm_crtc.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index e1b53fb..5fc198d 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -2116,7 +2116,7 @@ out:
return ret;
}
-static int format_check(struct drm_mode_fb_cmd2 *r)
+static int format_check(const struct drm_mode_fb_cmd2 *r)
{
uint32_t format = r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN;
@@ -2185,7 +2185,7 @@ static int format_check(struct drm_mode_fb_cmd2 *r)
}
}
-static int framebuffer_check(struct drm_mode_fb_cmd2 *r)
+static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
{
int ret, hsub, vsub, num_planes, i;
--
1.7.3.4
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 0/3] drm: A few misc patches
2012-05-24 17:53 [PATCH 0/3] drm: A few misc patches ville.syrjala
` (2 preceding siblings ...)
2012-05-24 17:54 ` [PATCH 3/3] drm: Constify params to format_check() and framebuffer_checks() ville.syrjala
@ 2012-05-24 18:16 ` Alex Deucher
3 siblings, 0 replies; 8+ messages in thread
From: Alex Deucher @ 2012-05-24 18:16 UTC (permalink / raw)
To: ville.syrjala; +Cc: dri-devel
On Thu, May 24, 2012 at 1:53 PM, <ville.syrjala@linux.intel.com> wrote:
> Just a few small items caught in my net while trawling the code.
for the series:
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] drm: Be more paranoid with integer overflows
2012-05-24 17:53 ` [PATCH 2/3] drm: Be more paranoid with integer overflows ville.syrjala
@ 2012-05-24 18:30 ` Daniel Vetter
2012-05-24 18:54 ` Ville Syrjälä
0 siblings, 1 reply; 8+ messages in thread
From: Daniel Vetter @ 2012-05-24 18:30 UTC (permalink / raw)
To: ville.syrjala; +Cc: dri-devel
On Thu, May 24, 2012 at 08:53:59PM +0300, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> Make sure 'width * cpp' and 'height * pitch + offset' don't exceed
> UINT_MAX.
>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
> drivers/gpu/drm/drm_crtc.c | 10 +++++++++-
> 1 files changed, 9 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index 80a34e7..e1b53fb 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -2211,13 +2211,21 @@ static int framebuffer_check(struct drm_mode_fb_cmd2 *r)
>
> for (i = 0; i < num_planes; i++) {
> unsigned int width = r->width / (i != 0 ? hsub : 1);
> + unsigned int height = r->height / (i != 0 ? vsub : 1);
> + unsigned int cpp = drm_format_plane_cpp(r->pixel_format, i);
>
> if (!r->handles[i]) {
> DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i);
> return -EINVAL;
> }
>
> - if (r->pitches[i] < drm_format_plane_cpp(r->pixel_format, i) * width) {
> + if ((uint64_t) width * cpp > UINT_MAX)
> + return -ERANGE;
> +
iirc that blows up on 32bit because gcc likes to use a compiler built-in.
And the usual pattern I've seen is if (UINT_MAX / a < b) return -ERANGE;
-Daniel
> + if ((uint64_t) height * r->pitches[i] + r->offsets[i] > UINT_MAX)
> + return -ERANGE;
> +
> + if (r->pitches[i] < width * cpp) {
> DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r->pitches[i], i);
> return -EINVAL;
> }
> --
> 1.7.3.4
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
--
Daniel Vetter
Mail: daniel@ffwll.ch
Mobile: +41 (0)79 365 57 48
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] drm: Be more paranoid with integer overflows
2012-05-24 18:30 ` Daniel Vetter
@ 2012-05-24 18:54 ` Ville Syrjälä
2012-05-24 19:03 ` Daniel Vetter
0 siblings, 1 reply; 8+ messages in thread
From: Ville Syrjälä @ 2012-05-24 18:54 UTC (permalink / raw)
To: Daniel Vetter; +Cc: dri-devel
On Thu, May 24, 2012 at 08:30:23PM +0200, Daniel Vetter wrote:
> On Thu, May 24, 2012 at 08:53:59PM +0300, ville.syrjala@linux.intel.com wrote:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> >
> > Make sure 'width * cpp' and 'height * pitch + offset' don't exceed
> > UINT_MAX.
> >
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> > drivers/gpu/drm/drm_crtc.c | 10 +++++++++-
> > 1 files changed, 9 insertions(+), 1 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> > index 80a34e7..e1b53fb 100644
> > --- a/drivers/gpu/drm/drm_crtc.c
> > +++ b/drivers/gpu/drm/drm_crtc.c
> > @@ -2211,13 +2211,21 @@ static int framebuffer_check(struct drm_mode_fb_cmd2 *r)
> >
> > for (i = 0; i < num_planes; i++) {
> > unsigned int width = r->width / (i != 0 ? hsub : 1);
> > + unsigned int height = r->height / (i != 0 ? vsub : 1);
> > + unsigned int cpp = drm_format_plane_cpp(r->pixel_format, i);
> >
> > if (!r->handles[i]) {
> > DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i);
> > return -EINVAL;
> > }
> >
> > - if (r->pitches[i] < drm_format_plane_cpp(r->pixel_format, i) * width) {
> > + if ((uint64_t) width * cpp > UINT_MAX)
> > + return -ERANGE;
> > +
>
> iirc that blows up on 32bit because gcc likes to use a compiler built-in.
I think that problem only happens w/ 64bit divs, which is why you have do_div()
and friends. At least with a small test app 'gcc -O2 -m32' generates the obvious
mul+cmp code, and mul+add+adc+cmp for the case w/ offsets[i] added. Maybe other
archs can't do it so neatly though.
> And the usual pattern I've seen is if (UINT_MAX / a < b) return -ERANGE;
I'm not a fan of divs :)
--
Ville Syrjälä
Intel OTC
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] drm: Be more paranoid with integer overflows
2012-05-24 18:54 ` Ville Syrjälä
@ 2012-05-24 19:03 ` Daniel Vetter
0 siblings, 0 replies; 8+ messages in thread
From: Daniel Vetter @ 2012-05-24 19:03 UTC (permalink / raw)
To: Ville Syrjälä; +Cc: dri-devel
On Thu, May 24, 2012 at 09:54:37PM +0300, Ville Syrjälä wrote:
> On Thu, May 24, 2012 at 08:30:23PM +0200, Daniel Vetter wrote:
> > On Thu, May 24, 2012 at 08:53:59PM +0300, ville.syrjala@linux.intel.com wrote:
> > > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > >
> > > Make sure 'width * cpp' and 'height * pitch + offset' don't exceed
> > > UINT_MAX.
> > >
> > > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > > ---
> > > drivers/gpu/drm/drm_crtc.c | 10 +++++++++-
> > > 1 files changed, 9 insertions(+), 1 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> > > index 80a34e7..e1b53fb 100644
> > > --- a/drivers/gpu/drm/drm_crtc.c
> > > +++ b/drivers/gpu/drm/drm_crtc.c
> > > @@ -2211,13 +2211,21 @@ static int framebuffer_check(struct drm_mode_fb_cmd2 *r)
> > >
> > > for (i = 0; i < num_planes; i++) {
> > > unsigned int width = r->width / (i != 0 ? hsub : 1);
> > > + unsigned int height = r->height / (i != 0 ? vsub : 1);
> > > + unsigned int cpp = drm_format_plane_cpp(r->pixel_format, i);
> > >
> > > if (!r->handles[i]) {
> > > DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i);
> > > return -EINVAL;
> > > }
> > >
> > > - if (r->pitches[i] < drm_format_plane_cpp(r->pixel_format, i) * width) {
> > > + if ((uint64_t) width * cpp > UINT_MAX)
> > > + return -ERANGE;
> > > +
> >
> > iirc that blows up on 32bit because gcc likes to use a compiler built-in.
>
> I think that problem only happens w/ 64bit divs, which is why you have do_div()
> and friends. At least with a small test app 'gcc -O2 -m32' generates the obvious
> mul+cmp code, and mul+add+adc+cmp for the case w/ offsets[i] added. Maybe other
> archs can't do it so neatly though.
Ah right, I've mixed things up. Sorry for the noise.
-Daniel
--
Daniel Vetter
Mail: daniel@ffwll.ch
Mobile: +41 (0)79 365 57 48
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-05-24 19:02 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-24 17:53 [PATCH 0/3] drm: A few misc patches ville.syrjala
2012-05-24 17:53 ` [PATCH 1/3] drm: Use stdint types for consistency ville.syrjala
2012-05-24 17:53 ` [PATCH 2/3] drm: Be more paranoid with integer overflows ville.syrjala
2012-05-24 18:30 ` Daniel Vetter
2012-05-24 18:54 ` Ville Syrjälä
2012-05-24 19:03 ` Daniel Vetter
2012-05-24 17:54 ` [PATCH 3/3] drm: Constify params to format_check() and framebuffer_checks() ville.syrjala
2012-05-24 18:16 ` [PATCH 0/3] drm: A few misc patches Alex Deucher
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.