drm/gud: Use size_add() in call to struct_size()
Subsystems (3)
PATCH 1/1 drm/gud: Use size_add() in call to struct_size()
If, for any reason, the open-coded arithmetic causes a wraparound, the protection that struct_size() adds against potential integer overflows is defeated. Fix this by hardening call to struct_size() with size_add().
--- drivers/gpu/drm/gud/gud_pipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/gud/gud_pipe.c +1 -1
@@ -503,7 +503,7 @@ int gud_pipe_check(struct drm_simple_display_pipe *pipe,return -ENOENT ; len =struct_size (req, properties, -GUD_PROPERTIES_MAX_NUM +GUD_CONNECTOR_PROPERTIES_MAX_NUM ); +size_add (GUD_PROPERTIES_MAX_NUM ,GUD_CONNECTOR_PROPERTIES_MAX_NUM )); req =kzalloc (len,GFP_KERNEL );if (!req)return -ENOMEM ;
Signature · 1 line
2.34.1
Quoted 15 lines · Gustavo A. R. Silva
If, for any reason, the open-coded arithmetic causes a wraparound, the protection that
struct_size()adds against potential integer overflows is defeated. Fix this by hardening call tostruct_size()withsize_add().Fixes 40e1a70b4aed ("drm: Add GUD USB Display driver")Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/gpu/drm/gud/gud_pipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/gud/gud_pipe.c +0
-0
drivers/gpu/drm/gud/gud_pipe.c int gud_pipe_check(struct drm_simple_display_pipe *pipe, · line 506
Quoted 5 lines
drivers/gpu/drm/gud/gud_pipe.c +1
-1@@ -503,7 +503,7 @@ int gud_pipe_check(struct drm_simple_display_pipe *pipe,return -ENOENT ; len =struct_size (req, properties, -GUD_PROPERTIES_MAX_NUM +GUD_CONNECTOR_PROPERTIES_MAX_NUM ); +size_add (GUD_PROPERTIES_MAX_NUM ,GUD_CONNECTOR_PROPERTIES_MAX_NUM ));
There are both constant expressions, so there's not too much value in wrapping them with size_add(), but for maintaining a common coding style for dealing with allocation sizes, I can be convinced of the change. :)
Quoted 6 lines
drivers/gpu/drm/gud/gud_pipe.c +0
-0req =kzalloc (len,GFP_KERNEL );if (!req)return -ENOMEM ;Signature · 1 line
2.34.1
Signature · 1 line
Kees Cook
Quoted 18 lines · Kees Cook
Quoted 17 lines · Gustavo A. R. Silva
If, for any reason, the open-coded arithmetic causes a wraparound, the protection that
struct_size()adds against potential integer overflows is defeated. Fix this by hardening call tostruct_size()withsize_add().Fixes 40e1a70b4aed ("drm: Add GUD USB Display driver")Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/gpu/drm/gud/gud_pipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/gud/gud_pipe.c +0
-0@@ -503,7 +503,7 @@ int gud_pipe_check(struct drm_simple_display_pipe *pipe,return -ENOENT ;
Quoted 7 lines
drivers/gpu/drm/gud/gud_pipe.c int gud_pipe_check(struct drm_simple_display_pipe *pipe, · line 506
Quoted 3 lines
drivers/gpu/drm/gud/gud_pipe.c +1
-1len =struct_size (req, properties, -GUD_PROPERTIES_MAX_NUM +GUD_CONNECTOR_PROPERTIES_MAX_NUM ); +size_add (GUD_PROPERTIES_MAX_NUM ,GUD_CONNECTOR_PROPERTIES_MAX_NUM ));There are both constant expressions, so there's not too much value in wrapping them with
size_add(), but for maintaining a common coding style for dealing with allocation sizes, I can be convinced of the change. :)
Yep; I've found a mix of constant expressions and variables doing open-coded arithmetic in struct_size(), so I'm sending them all.
Quoted 2 lines
Reviewed-by Kees Cook <[email protected]>
Thanks!
--
Gustavo
Quoted 9 lines
Quoted 8 lines
drivers/gpu/drm/gud/gud_pipe.c +0
-0req =kzalloc (len,GFP_KERNEL );if (!req)return -ENOMEM ;Signature · 1 line
2.34.1
Kees Cook
AppliedQuoted 5 lines · Gustavo A. R. Silva
If, for any reason, the open-coded arithmetic causes a wraparound, the protection that
struct_size()adds against potential integer overflows is defeated. Fix this by hardening call tostruct_size()withsize_add().
Applied to for-next/hardening, thanks!
[1/1] drm/gud: Use size_add() in call to struct_size()
https://git.kernel.org/kees/c/836ccb46073e
Take care,
Signature · 1 line
Kees Cook