drm: sysfs: Use scnprintf() for avoiding potential buffer overflow
Subsystems (2)
PATCH 1/1 drm: sysfs: 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().
--- drivers/gpu/drm/drm_sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_sysfs.c +1 -1
@@ -230,7 +230,7 @@ static ssize_t modes_show(struct device *device,mutex_lock (&connector->dev->mode_config.mutex);list_for_each_entry (mode, &connector->modes, head) { - written +=snprintf (buf + written,PAGE_SIZE - written,"%s\n" , + written +=scnprintf (buf + written,PAGE_SIZE - written,"%s\n" , mode->name); }mutex_unlock (&connector->dev->mode_config.mutex);
Signature · 6 lines
2.16.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi Takashi
Am 11.03.20 um 08:35 schrieb Takashi Iwai:
Quoted 15 lines
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().Signed-off-by Takashi Iwai <[email protected]>--- drivers/gpu/drm/drm_sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/drm_sysfs.c +0
-0
drivers/gpu/drm/drm_sysfs.c static ssize_t modes_show(struct device *device, · line 236
Quoted 8 lines
drivers/gpu/drm/drm_sysfs.c +1
-1@@ -230,7 +230,7 @@ static ssize_t modes_show(struct device *device,mutex_lock (&connector->dev->mode_config.mutex);list_for_each_entry (mode, &connector->modes, head) { - written +=snprintf (buf + written,PAGE_SIZE - written,"%s\n" , + written +=scnprintf (buf + written,PAGE_SIZE - written,"%s\n" , mode->name); }mutex_unlock (&connector->dev->mode_config.mutex);
In drm_sysfs.c, there are more _show functions with calls to snprintf() that could be replaced by scnprintf(). ATM they don't return the correct length for output that exceeds PAGE_SIZE. since you're at it, you may replace them as well.
But in any case
for this patch.
Do you want me to merge the patch into drm-misc-next?
Best regards
Thomas
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 19 lines · Thomas Zimmermann
Hi Takashi
Am 11.03.20 um 08:35 schrieb Takashi Iwai:
Quoted 15 lines
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().Signed-off-by Takashi Iwai <[email protected]>--- drivers/gpu/drm/drm_sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/drm_sysfs.c +0
-0@@ -230,7 +230,7 @@ static ssize_t modes_show(struct device *device,
Quoted 13 lines
drivers/gpu/drm/drm_sysfs.c static ssize_t modes_show(struct device *device, · line 236
Quoted 8 lines
drivers/gpu/drm/drm_sysfs.c +1
-1mutex_lock (&connector->dev->mode_config.mutex);list_for_each_entry (mode, &connector->modes, head) { - written +=snprintf (buf + written,PAGE_SIZE - written,"%s\n" , + written +=scnprintf (buf + written,PAGE_SIZE - written,"%s\n" , mode->name); }mutex_unlock (&connector->dev->mode_config.mutex);In
drm_sysfs.c, there are more_showfunctions with calls tosnprintf()that could be replaced byscnprintf(). ATM they don't return the correct length for output that exceedsPAGE_SIZE. since you're at it, you may replace them as well.
Well, the rest snprintf() calls are single calls and can't be over PAGE_SIZE obviously. IOW, they could be rather replaced with sprintf() instead, for a sake of simplicity.
Quoted 7 lines
But in any case
Reviewed-by Thomas Zimmermann <[email protected]>for this patch.
Do you want me to merge the patch into drm-misc-next?
Yes, please.
thanks,
Takashi
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerHi
Am 11.03.20 um 09:24 schrieb Takashi Iwai:
Quoted 35 lines
Quoted 19 lines · Thomas Zimmermann
Hi Takashi
Am 11.03.20 um 08:35 schrieb Takashi Iwai:
Quoted 15 lines
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().Signed-off-by Takashi Iwai <[email protected]>--- drivers/gpu/drm/drm_sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/drm_sysfs.c +0
-0@@ -230,7 +230,7 @@ static ssize_t modes_show(struct device *device,Quoted 13 lines
drivers/gpu/drm/drm_sysfs.c static ssize_t modes_show(struct device *device, · line 236
Quoted 8 lines
drivers/gpu/drm/drm_sysfs.c +1
-1mutex_lock (&connector->dev->mode_config.mutex);list_for_each_entry (mode, &connector->modes, head) { - written +=snprintf (buf + written,PAGE_SIZE - written,"%s\n" , + written +=scnprintf (buf + written,PAGE_SIZE - written,"%s\n" , mode->name); }mutex_unlock (&connector->dev->mode_config.mutex);In
drm_sysfs.c, there are more_showfunctions with calls tosnprintf()that could be replaced byscnprintf(). ATM they don't return the correct length for output that exceedsPAGE_SIZE. since you're at it, you may replace them as well.
Quoted 3 lines
Well, the rest
snprintf()calls are single calls and can't be overPAGE_SIZEobviously. IOW, they could be rather replaced withsprintf()instead, for a sake of simplicity.
Admittedly, none of these strings look as if they ever go beyond PAGE_SIZE, but sncprintf() is still a simple way of defensive programming here (and returns the correct value).
Quoted 10 lines
Quoted 8 lines
But in any case
Reviewed-by Thomas Zimmermann <[email protected]>for this patch.
Do you want me to merge the patch into drm-misc-next?
Yes, please.
OK, will do later today.
Best regards
Thomas
Quoted 6 lines
thanks,
Takashi
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerAm 11.03.20 um 09:24 schrieb Takashi Iwai:
Quoted 41 lines
Quoted 19 lines · Thomas Zimmermann
Hi Takashi
Am 11.03.20 um 08:35 schrieb Takashi Iwai:
Quoted 15 lines
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().Signed-off-by Takashi Iwai <[email protected]>--- drivers/gpu/drm/drm_sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/drm_sysfs.c +0
-0@@ -230,7 +230,7 @@ static ssize_t modes_show(struct device *device,Quoted 13 lines
drivers/gpu/drm/drm_sysfs.c static ssize_t modes_show(struct device *device, · line 236
Quoted 8 lines
drivers/gpu/drm/drm_sysfs.c +1
-1mutex_lock (&connector->dev->mode_config.mutex);list_for_each_entry (mode, &connector->modes, head) { - written +=snprintf (buf + written,PAGE_SIZE - written,"%s\n" , + written +=scnprintf (buf + written,PAGE_SIZE - written,"%s\n" , mode->name); }mutex_unlock (&connector->dev->mode_config.mutex);In
drm_sysfs.c, there are more_showfunctions with calls tosnprintf()that could be replaced byscnprintf(). ATM they don't return the correct length for output that exceedsPAGE_SIZE. since you're at it, you may replace them as well.Well, the rest
snprintf()calls are single calls and can't be overPAGE_SIZEobviously. IOW, they could be rather replaced withsprintf()instead, for a sake of simplicity.Quoted 2 lines
But in any case
Quoted 7 lines
Quoted 5 lines
Reviewed-by Thomas Zimmermann <[email protected]>for this patch.
Do you want me to merge the patch into drm-misc-next?
Yes, please.
https://cgit.freedesktop.org/drm/drm-misc/commit/?id=9b9f2219b2c4fa3d1a41245cdc263d09a4c9ad92
Best regards
Thomas
Quoted 6 lines
thanks,
Takashi
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel