i915/perf: Fix NULL deref bugs with drm_dbg() calls

Message ID 20231027140729.2505993-1-harshit.m.mogalapalli@oracle.com
State New
Headers
Series i915/perf: Fix NULL deref bugs with drm_dbg() calls |

Commit Message

Harshit Mogalapalli Oct. 27, 2023, 2:07 p.m. UTC
  When i915 perf interface is not available dereferencing it will lead to
NULL dereferences.

Fix this by using DRM_DEBUG() which the scenario before the commit in
the Fixes tag.

Fixes: 2fec539112e8 ("i915/perf: Replace DRM_DEBUG with driver specific drm_dbg call")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
This is found using smatch(static analysis tool), only compile tested.
---
 drivers/gpu/drm/i915/i915_perf.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
  

Comments

Andrzej Hajda Oct. 27, 2023, 2:11 p.m. UTC | #1
On 27.10.2023 16:07, Harshit Mogalapalli wrote:
> When i915 perf interface is not available dereferencing it will lead to
> NULL dereferences.
>
> Fix this by using DRM_DEBUG() which the scenario before the commit in
> the Fixes tag.
>
> Fixes: 2fec539112e8 ("i915/perf: Replace DRM_DEBUG with driver specific drm_dbg call")
> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>


Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>

Regards
Andrzej

> ---
> This is found using smatch(static analysis tool), only compile tested.
> ---
>   drivers/gpu/drm/i915/i915_perf.c | 9 +++------
>   1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
> index 2f3ecd7d4804..bb48c96b7950 100644
> --- a/drivers/gpu/drm/i915/i915_perf.c
> +++ b/drivers/gpu/drm/i915/i915_perf.c
> @@ -4228,8 +4228,7 @@ int i915_perf_open_ioctl(struct drm_device *dev, void *data,
>   	int ret;
>   
>   	if (!perf->i915) {
> -		drm_dbg(&perf->i915->drm,
> -			"i915 perf interface not available for this system\n");
> +		DRM_DEBUG("i915 perf interface not available for this system\n");
>   		return -ENOTSUPP;
>   	}
>   
> @@ -4608,8 +4607,7 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data,
>   	int err, id;
>   
>   	if (!perf->i915) {
> -		drm_dbg(&perf->i915->drm,
> -			"i915 perf interface not available for this system\n");
> +		DRM_DEBUG("i915 perf interface not available for this system\n");
>   		return -ENOTSUPP;
>   	}
>   
> @@ -4774,8 +4772,7 @@ int i915_perf_remove_config_ioctl(struct drm_device *dev, void *data,
>   	int ret;
>   
>   	if (!perf->i915) {
> -		drm_dbg(&perf->i915->drm,
> -			"i915 perf interface not available for this system\n");
> +		DRM_DEBUG("i915 perf interface not available for this system\n");
>   		return -ENOTSUPP;
>   	}
>
  
Tvrtko Ursulin Oct. 27, 2023, 2:47 p.m. UTC | #2
On 27/10/2023 15:11, Andrzej Hajda wrote:
> On 27.10.2023 16:07, Harshit Mogalapalli wrote:
>> When i915 perf interface is not available dereferencing it will lead to
>> NULL dereferences.
>>
>> Fix this by using DRM_DEBUG() which the scenario before the commit in
>> the Fixes tag.
>>
>> Fixes: 2fec539112e8 ("i915/perf: Replace DRM_DEBUG with driver 
>> specific drm_dbg call")
>> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
> 
> 
> Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>

Please hold off merging.

>> ---
>> This is found using smatch(static analysis tool), only compile tested.
>> ---
>>   drivers/gpu/drm/i915/i915_perf.c | 9 +++------
>>   1 file changed, 3 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/i915/i915_perf.c 
>> b/drivers/gpu/drm/i915/i915_perf.c
>> index 2f3ecd7d4804..bb48c96b7950 100644
>> --- a/drivers/gpu/drm/i915/i915_perf.c
>> +++ b/drivers/gpu/drm/i915/i915_perf.c
>> @@ -4228,8 +4228,7 @@ int i915_perf_open_ioctl(struct drm_device *dev, 
>> void *data,
>>       int ret;
>>       if (!perf->i915) {
>> -        drm_dbg(&perf->i915->drm,
>> -            "i915 perf interface not available for this system\n");
>> +        DRM_DEBUG("i915 perf interface not available for this 
>> system\n");

What's that struct drm_device *dev function argument a few lines up? :)

Although TBH all these these could just be removed since I doubt they 
are adding any value and ENOTSUPP is pretty clear.

Regards,

Tvrtko

>>           return -ENOTSUPP;
>>       }
>> @@ -4608,8 +4607,7 @@ int i915_perf_add_config_ioctl(struct drm_device 
>> *dev, void *data,
>>       int err, id;
>>       if (!perf->i915) {
>> -        drm_dbg(&perf->i915->drm,
>> -            "i915 perf interface not available for this system\n");
>> +        DRM_DEBUG("i915 perf interface not available for this 
>> system\n");
>>           return -ENOTSUPP;
>>       }
>> @@ -4774,8 +4772,7 @@ int i915_perf_remove_config_ioctl(struct 
>> drm_device *dev, void *data,
>>       int ret;
>>       if (!perf->i915) {
>> -        drm_dbg(&perf->i915->drm,
>> -            "i915 perf interface not available for this system\n");
>> +        DRM_DEBUG("i915 perf interface not available for this 
>> system\n");
>>           return -ENOTSUPP;
>>       }
>
  
Harshit Mogalapalli Oct. 27, 2023, 5:18 p.m. UTC | #3
Hi Tvrtko,

On 27/10/23 8:17 pm, Tvrtko Ursulin wrote:
> 
> On 27/10/2023 15:11, Andrzej Hajda wrote:
>> On 27.10.2023 16:07, Harshit Mogalapalli wrote:
>>> When i915 perf interface is not available dereferencing it will lead to
>>> NULL dereferences.
>>>
>>> Fix this by using DRM_DEBUG() which the scenario before the commit in
>>> the Fixes tag.
>>>
>>> Fixes: 2fec539112e8 ("i915/perf: Replace DRM_DEBUG with driver 
>>> specific drm_dbg call")
>>> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
>>
>>
>> Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>
> 
> Please hold off merging.
> 
>>> ---
>>> This is found using smatch(static analysis tool), only compile tested.
>>> ---
>>>   drivers/gpu/drm/i915/i915_perf.c | 9 +++------
>>>   1 file changed, 3 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/i915/i915_perf.c 
>>> b/drivers/gpu/drm/i915/i915_perf.c
>>> index 2f3ecd7d4804..bb48c96b7950 100644
>>> --- a/drivers/gpu/drm/i915/i915_perf.c
>>> +++ b/drivers/gpu/drm/i915/i915_perf.c
>>> @@ -4228,8 +4228,7 @@ int i915_perf_open_ioctl(struct drm_device 
>>> *dev, void *data,
>>>       int ret;
>>>       if (!perf->i915) {
>>> -        drm_dbg(&perf->i915->drm,
>>> -            "i915 perf interface not available for this system\n");
>>> +        DRM_DEBUG("i915 perf interface not available for this 
>>> system\n");
> 
> What's that struct drm_device *dev function argument a few lines up? :)
> 
> Although TBH all these these could just be removed since I doubt they 
> are adding any value and ENOTSUPP is pretty clear.
> 

Thanks for checking. I will remove the dbg() calls and send a V2.

Regards,
Harshit

> Regards,
> 
> Tvrtko
> 
>>>           return -ENOTSUPP;
>>>       }
>>> @@ -4608,8 +4607,7 @@ int i915_perf_add_config_ioctl(struct 
>>> drm_device *dev, void *data,
>>>       int err, id;
>>>       if (!perf->i915) {
>>> -        drm_dbg(&perf->i915->drm,
>>> -            "i915 perf interface not available for this system\n");
>>> +        DRM_DEBUG("i915 perf interface not available for this 
>>> system\n");
>>>           return -ENOTSUPP;
>>>       }
>>> @@ -4774,8 +4772,7 @@ int i915_perf_remove_config_ioctl(struct 
>>> drm_device *dev, void *data,
>>>       int ret;
>>>       if (!perf->i915) {
>>> -        drm_dbg(&perf->i915->drm,
>>> -            "i915 perf interface not available for this system\n");
>>> +        DRM_DEBUG("i915 perf interface not available for this 
>>> system\n");
>>>           return -ENOTSUPP;
>>>       }
>>
  

Patch

diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index 2f3ecd7d4804..bb48c96b7950 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -4228,8 +4228,7 @@  int i915_perf_open_ioctl(struct drm_device *dev, void *data,
 	int ret;
 
 	if (!perf->i915) {
-		drm_dbg(&perf->i915->drm,
-			"i915 perf interface not available for this system\n");
+		DRM_DEBUG("i915 perf interface not available for this system\n");
 		return -ENOTSUPP;
 	}
 
@@ -4608,8 +4607,7 @@  int i915_perf_add_config_ioctl(struct drm_device *dev, void *data,
 	int err, id;
 
 	if (!perf->i915) {
-		drm_dbg(&perf->i915->drm,
-			"i915 perf interface not available for this system\n");
+		DRM_DEBUG("i915 perf interface not available for this system\n");
 		return -ENOTSUPP;
 	}
 
@@ -4774,8 +4772,7 @@  int i915_perf_remove_config_ioctl(struct drm_device *dev, void *data,
 	int ret;
 
 	if (!perf->i915) {
-		drm_dbg(&perf->i915->drm,
-			"i915 perf interface not available for this system\n");
+		DRM_DEBUG("i915 perf interface not available for this system\n");
 		return -ENOTSUPP;
 	}