drm/amdgpu/pm: Use scnprintf() for avoiding potential buffer overflow
Subsystems (2)
PATCH 1/5 drm/amdgpu/pm: Use scnprintf() for avoiding potential buffer overflow
Since snprintf() returns the would-be-output size instead of the actual output size, the succeeding calls may go beyond the given buffer limit. Fix it by replacing with scnprintf().
Also adjust the size argument passed to scnprintf() so that it really cuts off at the right remaining buffer length.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1 -1
@@ -448,7 +448,7 @@ static ssize_t amdgpu_get_pp_num_states(struct device *dev, buf_len =snprintf (buf,PAGE_SIZE ,"states: %d\n" , data.nums);for (i =0 ; i < data.nums; i++) - buf_len +=snprintf (buf + buf_len,PAGE_SIZE ,"%d %s\n" , i, + buf_len +=scnprintf (buf + buf_len,PAGE_SIZE - buf_len,"%d %s\n" , i, (data.states[i] ==POWER_STATE_TYPE_INTERNAL_BOOT ) ?"boot" : (data.states[i] ==POWER_STATE_TYPE_BATTERY ) ?"battery" : (data.states[i] == POWER_STATE_TYPE_BALANCED) ? "balanced" :
Signature · 6 lines
2.16.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
BTW, please ignore the subject prefix '[1/5]', which was added mistakenly while extracting a patch from the commit list. This is a single patch.
thanks,
Takashi
Quoted 29 lines · Takashi Iwai
Since
snprintf()returns the would-be-output size instead of the actual output size, the succeeding calls may go beyond the given buffer limit. Fix it by replacing withscnprintf().Also adjust the size argument passed to
scnprintf()so that it really cuts off at the right remaining buffer length.Signed-off-by Takashi Iwai <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1
-1@@ -448,7 +448,7 @@ static ssize_t amdgpu_get_pp_num_states(struct device *dev, buf_len =snprintf (buf,PAGE_SIZE ,"states: %d\n" , data.nums);for (i =0 ; i < data.nums; i++) - buf_len +=snprintf (buf + buf_len,PAGE_SIZE ,"%d %s\n" , i, + buf_len +=scnprintf (buf + buf_len,PAGE_SIZE - buf_len,"%d %s\n" , i, (data.states[i] ==POWER_STATE_TYPE_INTERNAL_BOOT ) ?"boot" : (data.states[i] ==POWER_STATE_TYPE_BATTERY ) ?"battery" : (data.states[i] == POWER_STATE_TYPE_BALANCED) ? "balanced" :Signature · 1 line
2.16.4
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx