Skip to contentSkip to conversation

drm/logicvc: Avoid possible overflow in layer buffer setup variables

PATCH In review Paul Kocialkowski 1 participant 3 messages Oct 25, 2023 – Nov 21, 2023

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

PATCH 1/2 drm/logicvc: Avoid possible overflow in layer buffer setup variables

The buffer_sel, voffset and hoffset values are calculated from u32 values and might overflow under certain conditions.

Move them to u32 definitions instead of u8/u16 to avoid the issue.

Fixes efeeaefe9be5 ("drm: Add support for the LogiCVC display controller")
---
 drivers/gpu/drm/logicvc/logicvc_layer.c | 6 +++---
 drivers/gpu/drm/logicvc/logicvc_layer.h | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/logicvc/logicvc_layer.c +3 -3
index 464000aea765..eea22379d042 100644
@@ -268,9 +268,9 @@ int logicvc_layer_buffer_find_setup(struct logicvc_drm *logicvc,
 	u32 layer_stride = layer_bytespp * logicvc->config.row_stride;
 	u32 base_offset = layer->config.base_offset * layer_stride;
 	u32 buffer_offset = layer->config.buffer_offset * layer_stride;
-	u8 buffer_sel = 0;
-	u16 voffset = 0;
-	u16 hoffset = 0;
+	u32 buffer_sel = 0;
+	u32 voffset = 0;
+	u32 hoffset = 0;
 	phys_addr_t fb_addr;
 	u32 fb_offset;
 	u32 gap;
drivers/gpu/drm/logicvc/logicvc_layer.h +3 -3
index 4a4b02e9b819..a06feeda3abf 100644
@@ -18,9 +18,9 @@
 #define LOGICVC_LAYER_ALPHA_PIXEL		1
 
 struct logicvc_layer_buffer_setup {
-	u8 buffer_sel;
-	u16 voffset;
-	u16 hoffset;
+	u32 buffer_sel;
+	u32 voffset;
+	u32 hoffset;
 };
 
 struct logicvc_layer_config {
Signature · 1 line
2.42.0
#1 lore raw

PATCH 2/2 drm/logicvc: Define max dimensions from USHRT_MAX

Use the existing macro instead of redefining it.

---
 drivers/gpu/drm/logicvc/logicvc_regs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/logicvc/logicvc_regs.h +1 -1
index 4aae27e9ba2b..0fc413fef6dd 100644
@@ -10,7 +10,7 @@
 #ifndef _LOGICVC_REGS_H_
 #define _LOGICVC_REGS_H_
 
-#define LOGICVC_DIMENSIONS_MAX		(BIT(16) - 1)
+#define LOGICVC_DIMENSIONS_MAX		USHRT_MAX
 
 #define LOGICVC_HSYNC_FRONT_PORCH_REG	0x00
 #define LOGICVC_HSYNC_REG		0x08
Signature · 1 line
2.42.0
#2 lore raw
In reply to Paul Kocialkowski

Hi folks,

Quoted 4 lines · Paul Kocialkowski

The buffer_sel, voffset and hoffset values are calculated from u32 values and might overflow under certain conditions.

Move them to u32 definitions instead of u8/u16 to avoid the issue.

Any chance to get a quick review on this simple fixup (and the next one)? I can certainly push them myself after that.

Thanks,

Paul

Quoted 45 lines
Fixes efeeaefe9be5 ("drm: Add support for the LogiCVC display controller")
---
 drivers/gpu/drm/logicvc/logicvc_layer.c | 6 +++---
 drivers/gpu/drm/logicvc/logicvc_layer.h | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/logicvc/logicvc_layer.c +3 -3
index 464000aea765..eea22379d042 100644
@@ -268,9 +268,9 @@ int logicvc_layer_buffer_find_setup(struct logicvc_drm *logicvc,
 	u32 layer_stride = layer_bytespp * logicvc->config.row_stride;
 	u32 base_offset = layer->config.base_offset * layer_stride;
 	u32 buffer_offset = layer->config.buffer_offset * layer_stride;
-	u8 buffer_sel = 0;
-	u16 voffset = 0;
-	u16 hoffset = 0;
+	u32 buffer_sel = 0;
+	u32 voffset = 0;
+	u32 hoffset = 0;
 	phys_addr_t fb_addr;
 	u32 fb_offset;
 	u32 gap;
drivers/gpu/drm/logicvc/logicvc_layer.h +3 -3
index 4a4b02e9b819..a06feeda3abf 100644
@@ -18,9 +18,9 @@
 #define LOGICVC_LAYER_ALPHA_PIXEL		1
 
 struct logicvc_layer_buffer_setup {
-	u8 buffer_sel;
-	u16 voffset;
-	u16 hoffset;
+	u32 buffer_sel;
+	u32 voffset;
+	u32 hoffset;
 };
 
 struct logicvc_layer_config {
Signature · 1 line
2.42.0
Signature · 3 lines
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com