drm: Limit to INT_MAX in create_blob ioctl
Subsystems (2)
PATCH 1/1 drm: Limit to INT_MAX in create_blob ioctl
The hardened usercpy code is too paranoid ever since:
commit 6a30afa8c1fbde5f10f9c584c2992aa3c7f7a8fe
Author: Kees Cook <[email protected]> Date: Wed Nov 6 16:07:01 2019 +1100
uaccess: disallow > INT_MAX copy sizes
Code itself should have been fine as-is.
--
Kees/Andrew,
Since this is -mm can I have a stable sha1 or something for referencing? Or do you want to include this in the -mm patch bomb for the merge window?
-Daniel
--- drivers/gpu/drm/drm_property.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_property.c +1 -1
@@ -561,7 +561,7 @@ drm_property_create_blob(struct drm_device *dev, size_t length,struct drm_property_blob *blob;int ret; -if (!length || length >ULONG_MAX -sizeof (struct drm_property_blob )) +if (!length || length >INT_MAX -sizeof (struct drm_property_blob ))return ERR_PTR (-EINVAL ); blob =kvzalloc (sizeof (struct drm_property_blob )+length,GFP_KERNEL );
Signature · 1 line
2.24.0.rc2
Quoted 33 lines · Daniel Vetter
The hardened usercpy code is too paranoid ever since:
commit
6a30afa8c1fbde5f10f9c584c2992aa3c7f7a8feAuthor: Kees Cook <[email protected]> Date: Wed Nov 6 16:07:01 2019 +1100uaccess: disallow >
INT_MAXcopy sizesCode itself should have been fine as-is.
Reported-by [email protected]Fixes 6a30afa8c1fb ("uaccess: disallow > INT_MAX copy sizes")Cc Kees Cook <[email protected]>Cc Alexander Viro <[email protected]>Cc Andrew Morton <[email protected]>Cc Stephen Rothwell <[email protected]>Signed-off-by Daniel Vetter <[email protected]>--
Kees/Andrew,Since this is -mm can I have a stable sha1 or something for referencing? Or do you want to include this in the -mm patch bomb for the merge window?
(quoted diff) +0
-2-Daniel --- drivers/gpu/drm/drm_property.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/drm_property.c +0
-0
drivers/gpu/drm/drm_property.c drm_property_create_blob(struct drm_device *dev, size_t length, · line 565
Quoted 6 lines
drivers/gpu/drm/drm_property.c +1
-1@@ -561,7 +561,7 @@ drm_property_create_blob(struct drm_device *dev, size_t length,struct drm_property_blob *blob;int ret; -if (!length || length >ULONG_MAX -sizeof (struct drm_property_blob )) +if (!length || length >INT_MAX -sizeof (struct drm_property_blob ))return ERR_PTR (-EINVAL );
INT_MAX should be more than enough.
Quoted 9 lines
drivers/gpu/drm/drm_property.c +0
-0blob =kvzalloc (sizeof (struct drm_property_blob )+length,GFP_KERNEL );Signature · 6 lines
2.24.0.rc2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 2 lines
Ville Syrjälä Intel
Quoted 9 lines · Daniel Vetter
The hardened usercpy code is too paranoid ever since:
commit
6a30afa8c1fbde5f10f9c584c2992aa3c7f7a8feAuthor: Kees Cook <[email protected]> Date: Wed Nov 6 16:07:01 2019 +1100uaccess: disallow >
INT_MAXcopy sizesCode itself should have been fine as-is.
I had to go read the syzbot report to understand what was actually being fixed here. Can you be a bit more verbose in this commit log? It sounds like huge usercopy sizes were allowed by drm (though I guess they would fail gracefully in some other way?) but after 6a30afa8c1fb, the copy would yell about sizes where INT_MAX < size < ULONG_MAX - sizeof(...) ?
What was the prior failure mode that made the existing ULONG_MAX check safe? Your patch looks fine, though:
Quoted 7 lines
Reported-by [email protected]Fixes 6a30afa8c1fb ("uaccess: disallow > INT_MAX copy sizes")Cc Kees Cook <[email protected]>Cc Alexander Viro <[email protected]>Cc Andrew Morton <[email protected]>Cc Stephen Rothwell <[email protected]>Signed-off-by Daniel Vetter <[email protected]>
Quoted 6 lines
--
Kees/Andrew,Since this is -mm can I have a stable sha1 or something for referencing? Or do you want to include this in the -mm patch bomb for the merge window?
Traditionally these things live in akpm's tree when they are fixes for patches in there. I have no idea how the Fixes tags work in that case, though...
-Kees
Quoted 21 lines
(quoted diff) +0
-2-Daniel --- drivers/gpu/drm/drm_property.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/drm_property.c +1
-1@@ -561,7 +561,7 @@ drm_property_create_blob(struct drm_device *dev, size_t length,struct drm_property_blob *blob;int ret; -if (!length || length >ULONG_MAX -sizeof (struct drm_property_blob )) +if (!length || length >INT_MAX -sizeof (struct drm_property_blob ))return ERR_PTR (-EINVAL ); blob =kvzalloc (sizeof (struct drm_property_blob )+length,GFP_KERNEL );Signature · 1 line
2.24.0.rc2
Signature · 1 line
Kees Cook
Quoted 10 lines · Kees Cook
Quoted 8 lines · Daniel Vetter
The hardened usercpy code is too paranoid ever since:
commit
6a30afa8c1fbde5f10f9c584c2992aa3c7f7a8feAuthor: Kees Cook <[email protected]> Date: Wed Nov 6 16:07:01 2019 +1100uaccess: disallow >
INT_MAXcopy sizes
Quoted 7 lines
Quoted 1 line
Code itself should have been fine as-is.
I had to go read the syzbot report to understand what was actually being fixed here. Can you be a bit more verbose in this commit log? It sounds like huge usercopy sizes were allowed by drm (though I guess they would fail gracefully in some other way?) but after
6a30afa8c1fb, the copy would yell about sizes whereINT_MAX< size <ULONG_MAX- sizeof(...) ?
The WARNING seems to have been the only bad effect. I guess in practice the real big stuff fails at memory allocation time, but shouldn't overflow. Or maybe I still don't get how this C thing works. Anyway I figured the cited patch is good enough, userptr copies > INT_MAX aren't allowed anymore, so we need to adjust our overflow checks.
-Daniel
Quoted 49 lines
What was the prior failure mode that made the existing
ULONG_MAXcheck safe? Your patch looks fine, though:Reviewed-by Kees Cook <[email protected]>Quoted 7 lines
Reported-by [email protected]Fixes 6a30afa8c1fb ("uaccess: disallow > INT_MAX copy sizes")Cc Kees Cook <[email protected]>Cc Alexander Viro <[email protected]>Cc Andrew Morton <[email protected]>Cc Stephen Rothwell <[email protected]>Signed-off-by Daniel Vetter <[email protected]>Quoted 6 lines
--
Kees/Andrew,Since this is -mm can I have a stable sha1 or something for referencing? Or do you want to include this in the -mm patch bomb for the merge window?
Traditionally these things live in akpm's tree when they are fixes for patches in there. I have no idea how the Fixes tags work in that case, though...
-Kees
Quoted 19 lines
(quoted diff) +0
-2-Daniel --- drivers/gpu/drm/drm_property.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/drm_property.c +1
-2@@ -561,7 +561,7 @@ drm_property_create_blob(struct drm_device *dev, size_t length,struct drm_property_blob *blob;int ret; -if (!length || length >ULONG_MAX -sizeof (struct drm_property_blob )) +if (!length || length >INT_MAX -sizeof (struct drm_property_blob ))return ERR_PTR (-EINVAL ); blob =kvzalloc (sizeof (struct drm_property_blob )+length,GFP_KERNEL ); --Quoted 2 lines
2.24.0.rc2
--
Kees Cook
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 7 lines · On Wed, 6 Nov 2019 09:24:18 -0800 Kees Cook <[email protected]> wrote:
Quoted 3 lines
Since this is -mm can I have a stable sha1 or something for referencing? Or do you want to include this in the -mm patch bomb for the merge window?
Traditionally these things live in akpm's tree when they are fixes for patches in there. I have no idea how the Fixes tags work in that case, though...
I queued it immediately ahead of uaccess-disallow-int_max-copy-sizes.patch so all should be good, thanks.