drm/ttm: Fix dummy res NULL ptr deref bug
Hello Arunpravin Paneer Selvam,
This is a semi-automatic email about new static checker warnings.
The patch cf4b7387c0a8: "drm/ttm: Fix dummy res NULL ptr deref bug" from Aug 9, 2022, leads to the following Smatch complaint:
drivers/gpu/drm/ttm/ttm_bo.c:915 ttm_bo_validate()
warn: variable dereferenced before check 'bo->resource' (see line 907)drivers/gpu/drm/ttm/ttm_bo.c
906 */
907 if (!ttm_resource_compat(bo->resource, placement)) {
^^^^^^^^^^^^Unchecked dereference here inside the function.
908 ret = ttm_bo_move_buffer(bo, placement, ctx);
909 if (ret)
910 return ret;
911 }
912 /*
913 * We might need to add a TTM.
914 */
915 if (!bo->resource || bo->resource->mem_type == TTM_PL_SYSTEM) {
^^^^^^^^^^^^Checked too late.
This NULL check was added deliberately based on a report from the kbuild bot, but it's not clear why bo->resource is NULL at this point. Was the patch tested? There is a [email protected] but there is no Fixes tag.
916 ret = ttm_tt_create(bo, true); 917 if (ret)
regards,
dan carpenter
Hi Dan,
drm-misc-fixes doesn't have the updated ttm_bo.c file, we have the updated ttm_bo.c version in drm-misc-next branch. Please find below for the line number 907.
Quoted 7 lines · Dan Carpenter
Hello Arunpravin Paneer Selvam,
This is a semi-automatic email about new static checker warnings.
The patch
cf4b7387c0a8: "drm/ttm: Fix dummy res NULL ptr deref bug" from Aug 9, 2022, leads to the following Smatch complaint:
Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c:915 ttm_bo_validate() warn: variable dereferenced before check 'bo->resource' (see line 907)
drivers/gpu/drm/ttm/ttm_bo.c906 */ 907 if (!ttm_resource_compat(bo->resource, placement)) { ^^^^^^^^^^^^Unchecked dereference here inside the function.
|if (!bo->resource || !ttm_resource_compat(bo->resource, placement)) { we have this version in drm-misc-next Regards, Arun |
Quoted 22 lines
908 ret = ttm_bo_move_buffer(bo, placement, ctx); 909 if (ret) 910 return ret; 911 } 912 /* 913 * We might need to add a TTM. 914 */ 915 if (!bo->resource || bo->resource->mem_type == TTM_PL_SYSTEM) { ^^^^^^^^^^^^Checked too late.
This NULL check was added deliberately based on a report from the kbuild bot, but it's not clear why
bo->resourceis NULL at this point. Was the patch tested? There is [email protected] but there is no Fixes tag.916 ret = ttm_tt_create(bo, true); 917 if (ret)regards,
dan carpenter
Quoted 17 lines · Arunpravin Paneer Selvam
Hi Dan,
drm-misc-fixes doesn't have the updated
ttm_bo.cfile, we have the updatedttm_bo.cversion in
drm-misc-next branch. Please find below for the line number 907.Quoted 10 lines · Dan Carpenter
Hello Arunpravin Paneer Selvam,
This is a semi-automatic email about new static checker warnings.
The patch
cf4b7387c0a8: "drm/ttm: Fix dummy res NULL ptr deref bug" from Aug 9, 2022, leads to the following Smatch complaint:drivers/gpu/drm/ttm/ttm_bo.c:915 ttm_bo_validate() warn: variable dereferenced before check 'bo->resource' (see line 907)
Quoted 9 lines
Quoted 5 lines
drivers/gpu/drm/ttm/ttm_bo.c906 */ 907 if (!ttm_resource_compat(bo->resource, placement)) { ^^^^^^^^^^^^Unchecked dereference here inside the function.
|if (!bo->resource || !ttm_resource_compat(bo->resource, placement)) { we have this version in drm-misc-next Regards, Arun |
Huh... That's very interesting. It appears there was a bug in drm-misc-next, we applied the fix to the wrong tree, and now both trees are wrong. The drm-misc-next tree still has the bug and the other tree has a static checker warning about nonsensical NULL checks.
Eventually drm-misc-next will get merged and everything will work. Is it too late to remove the bogus "CC: [email protected]"?
This could have been avoided if the NULL dereference fix had a Fixes tag.
regards,
dan carpenter
Hi Dan,
Quoted 26 lines · Dan Carpenter
Quoted 17 lines · Arunpravin Paneer Selvam
Hi Dan,
drm-misc-fixes doesn't have the updated
ttm_bo.cfile, we have the updatedttm_bo.cversion in
drm-misc-next branch. Please find below for the line number 907.Quoted 10 lines · Dan Carpenter
Hello Arunpravin Paneer Selvam,
This is a semi-automatic email about new static checker warnings.
The patch
cf4b7387c0a8: "drm/ttm: Fix dummy res NULL ptr deref bug" from Aug 9, 2022, leads to the following Smatch complaint:drivers/gpu/drm/ttm/ttm_bo.c:915 ttm_bo_validate() warn: variable dereferenced before check 'bo->resource' (see line 907)Quoted 8 lines
Quoted 5 lines
drivers/gpu/drm/ttm/ttm_bo.c906 */ 907 if (!ttm_resource_compat(bo->resource, placement)) { ^^^^^^^^^^^^Unchecked dereference here inside the function.
|if (!bo->resource || !ttm_resource_compat(bo->resource, placement)) { we have this version in drm-misc-next Regards, Arun |
Quoted 7 lines
Huh... That's very interesting. It appears there was a bug in drm-misc-next, we applied the fix to the wrong tree, and now both trees are wrong. The drm-misc-next tree still has the bug and the other tree has a static checker warning about nonsensical NULL checks.
Eventually drm-misc-next will get merged and everything will work. Is it too late to remove the bogus "CC: [email protected]"?
I will look into this problem.
Quoted 1 line
This could have been avoided if the NULL dereference fix had a Fixes tag.
I should have added the below tag
I will check on this.
Thanks,
Arun
Quoted 4 lines
regards,
dan carpenter
Am 14.08.22 um 08:00 schrieb Arunpravin Paneer Selvam:
Quoted 29 lines
Hi Dan,
Quoted 26 lines · Dan Carpenter
Quoted 25 lines · Arunpravin Paneer Selvam
Hi Dan,
drm-misc-fixes doesn't have the updated
ttm_bo.cfile, we have the updatedttm_bo.cversion in
drm-misc-next branch. Please find below for the line number 907.Quoted 7 lines · Dan Carpenter
Hello Arunpravin Paneer Selvam,
This is a semi-automatic email about new static checker warnings.
The patch
cf4b7387c0a8: "drm/ttm: Fix dummy res NULL ptr deref bug" from Aug 9, 2022, leads to the following Smatch complaint:Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo.c:915ttm_bo_validate()
warn: variable dereferenced before check 'bo->resource' (see line 907)
drivers/gpu/drm/ttm/ttm_bo.c
906 */
907 if (!ttm_resource_compat(bo->resource, placement)) { ^^^^^^^^^^^^ Unchecked dereference here inside the function.|if (!bo->resource || !ttm_resource_compat(bo->resource, placement)) { we have this version in drm-misc-next Regards, Arun |
Quoted 8 lines
Quoted 7 lines
Huh... That's very interesting. It appears there was a bug in drm-misc-next, we applied the fix to the wrong tree, and now both trees are wrong. The drm-misc-next tree still has the bug and the other tree has a static checker warning about nonsensical NULL checks.
Eventually drm-misc-next will get merged and everything will work. Is it too late to remove the bogus "CC: [email protected]"?
I will look into this problem.
Mhm, if I'm not completely mistaken the "CC: [email protected]" is actually correct, we just need to limit to which version it applies.
Quoted 3 lines
Quoted 1 line
This could have been avoided if the NULL dereference fix had a Fixes tag.
I should have added the below tag
Fixes 347987a2cf0d ("drm/ttm: rename and cleanup ttm_bo_init")
WAIT! That's not the correct one. This patch just made the problem more obvious.
The real one is bfa3357ef9ab drm/ttm: allocate resource object instead of embedding it v2
Regards,
Christian.
Quoted 10 lines
I will check on this.
Thanks,
ArunQuoted 4 lines
regards,
dan carpenter