Skip to contentSkip to conversation

drm: A few misc patches

PATCH In review [email protected] 3 participants 8 messages May 24, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover drm: A few misc patches

Just a few small items caught in my net while trawling the code.

#1 lore raw

PATCH 1/3 drm: Use stdint types for consistency

From: Ville Syrjälä <[email protected]>

The rest of the code uses stdint types, so use them in drm_property_change_is_valid() as well.

---
 drivers/gpu/drm/drm_crtc.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_crtc.c +2 -2
index 92cea9d..80a34e7 100644
@@ -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);
Signature · 6 lines
1.7.3.4

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

PATCH 2/3 drm: Be more paranoid with integer overflows

In reply to [email protected]

From: Ville Syrjälä <[email protected]>

Make sure 'width * cpp' and 'height * pitch + offset' don't exceed UINT_MAX.

---
 drivers/gpu/drm/drm_crtc.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
drivers/gpu/drm/drm_crtc.c +9 -1
index 80a34e7..e1b53fb 100644
@@ -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;
 		}
Signature · 6 lines
1.7.3.4

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

Re: [PATCH 2/3] drm: Be more paranoid with integer overflows

Quoted 20 lines · On Thu, May 24, 2012 at 08:53:59PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

Make sure 'width * cpp' and 'height * pitch + offset' don't exceed UINT_MAX.

---
 drivers/gpu/drm/drm_crtc.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
drivers/gpu/drm/drm_crtc.c +2 -0
index 80a34e7..e1b53fb 100644
@@ -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);

drivers/gpu/drm/drm_crtc.c static int framebuffer_check(struct drm_mode_fb_cmd2 *r) · line 2224

Quoted 10 lines
drivers/gpu/drm/drm_crtc.c +3 -1
 
 		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

Quoted 14 lines
drivers/gpu/drm/drm_crtc.c +4 -0
+		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;
 		}
Signature · 6 lines
1.7.3.4

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
#4 lore raw

Re: [PATCH 2/3] drm: Be more paranoid with integer overflows

Quoted 27 lines · Daniel Vetter
Quoted 26 lines · On Thu, May 24, 2012 at 08:53:59PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

Make sure 'width * cpp' and 'height * pitch + offset' don't exceed UINT_MAX.

---
 drivers/gpu/drm/drm_crtc.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
drivers/gpu/drm/drm_crtc.c +2 -0
index 80a34e7..e1b53fb 100644
@@ -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;
 		}
 
Quoted 6 lines

drivers/gpu/drm/drm_crtc.c static int framebuffer_check(struct drm_mode_fb_cmd2 *r) · line 2224

Quoted 4 lines
drivers/gpu/drm/drm_crtc.c +3 -1
-		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.

Quoted 1 line

And the usual pattern I've seen is if (UINT_MAX / a < b) return -ERANGE;

I'm not a fan of divs :)

Signature · 2 lines
Ville Syrjälä
Intel OTC
#5 lore raw

Re: [PATCH 2/3] drm: Be more paranoid with integer overflows

Quoted 35 lines · Ville Syrjälä
Quoted 27 lines · Daniel Vetter
Quoted 26 lines · On Thu, May 24, 2012 at 08:53:59PM +0300, [email protected] wrote:

From: Ville Syrjälä <[email protected]>

Make sure 'width * cpp' and 'height * pitch + offset' don't exceed UINT_MAX.

---
 drivers/gpu/drm/drm_crtc.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
drivers/gpu/drm/drm_crtc.c +2 -0
index 80a34e7..e1b53fb 100644
@@ -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;
 		}
 
Quoted 6 lines

drivers/gpu/drm/drm_crtc.c static int framebuffer_check(struct drm_mode_fb_cmd2 *r) · line 2224

Quoted 4 lines
drivers/gpu/drm/drm_crtc.c +3 -1
-		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.

Quoted 4 lines

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

Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
#6 lore raw

PATCH 3/3 drm: Constify params to format_check() and framebuffer_checks()

In reply to [email protected]

From: Ville Syrjälä <[email protected]>

---
 drivers/gpu/drm/drm_crtc.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_crtc.c +2 -2
index e1b53fb..5fc198d 100644
@@ -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;
 
Signature · 6 lines
1.7.3.4

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel