drm/logicvc: Avoid possible overflow in layer buffer setup variables
Subsystems (3)
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.
Signed-off-by Paul Kocialkowski <[email protected]>
Reported-by Dan Carpenter <[email protected]>
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
@@ -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
@@ -18,9 +18,9 @@#define LOGICVC_LAYER_ALPHA_PIXEL 1struct 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
PATCH 2/2 drm/logicvc: Define max dimensions from USHRT_MAX
Use the existing macro instead of redefining it.
Signed-off-by Paul Kocialkowski <[email protected]>
--- drivers/gpu/drm/logicvc/logicvc_regs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/logicvc/logicvc_regs.h +1 -1
@@ -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
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
Signed-off-by Paul Kocialkowski <[email protected]>Reported-by Dan Carpenter <[email protected]>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@@ -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@@ -18,9 +18,9 @@#define LOGICVC_LAYER_ALPHA_PIXEL 1struct 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