drm: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
Subsystems (2)
cover drm: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
Xiubo Li (3):
drm/bufs: Fix possible ZERO_SIZE_PTR pointer dereferencing error. drm/crtc: Fix possible ZERO_SIZE_PTR pointer dereferencing error. drm/global: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
drivers/gpu/drm/drm_bufs.c | 12 +++++++++--- drivers/gpu/drm/drm_crtc.c | 14 +++++++++++--- drivers/gpu/drm/drm_global.c | 5 +++++ 3 files changed, 25 insertions(+), 6 deletions(-)
Signature · 1 line
1.8.5
PATCH 1/3 drm/bufs: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
Since we cannot make sure the 'count' and 'dev->driver->dev_priv_size' will always be none zero here, and then if either equal to zero, the kzalloc() will return ZERO_SIZE_PTR, which equals to ((void *)16).
So this patch fix this with just doing the zero check before calling kzalloc().
--- drivers/gpu/drm/drm_bufs.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_bufs.c +9 -3
@@ -617,6 +617,9 @@ int drm_addbufs_agp(struct drm_device * dev, struct drm_buf_desc * request)int i, valid;struct drm_buf **temp_buflist; +if (!dev->driver->dev_priv_size) +return -EINVAL ; +if (!dma)return -EINVAL ;
@@ -672,7 +675,7 @@ int drm_addbufs_agp(struct drm_device * dev, struct drm_buf_desc * request)return -ENOMEM ;/* May only call once for each order */ } -if (count <0 || count >4096 ) { +if (count <=0 || count >4096 ) {mutex_unlock (&dev->struct_mutex);atomic_dec (&dev->buf_alloc);return -EINVAL ;
@@ -781,6 +784,9 @@ int drm_addbufs_pci(struct drm_device * dev, struct drm_buf_desc * request)unsigned long *temp_pagelist;struct drm_buf **temp_buflist; +if (!dev->driver->dev_priv_size) +return -EINVAL ; +if (!drm_core_check_feature (dev,DRIVER_PCI_DMA ))return -EINVAL ;
@@ -821,7 +827,7 @@ int drm_addbufs_pci(struct drm_device * dev, struct drm_buf_desc * request)return -ENOMEM ;/* May only call once for each order */ } -if (count <0 || count >4096 ) { +if (count <=0 || count >4096 ) {mutex_unlock (&dev->struct_mutex);atomic_dec (&dev->buf_alloc);return -EINVAL ;
@@ -1031,7 +1037,7 @@ static int drm_addbufs_sg(struct drm_device * dev, struct drm_buf_desc * requestreturn -ENOMEM ;/* May only call once for each order */ } -if (count <0 || count >4096 ) { +if (count <=0 || count >4096 ) {mutex_unlock (&dev->struct_mutex);atomic_dec (&dev->buf_alloc);return -EINVAL ;
Signature · 1 line
1.8.5
PATCH 2/3 drm/crtc: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
In reply to Xiubo LiSince we cannot make sure the 'total_objects' and 'gamma_size' will always be none zero here, and then if either equals to zero, the kzalloc() will return ZERO_SIZE_PTR, which equals to ((void *)16).
This patch fix this with just doing the zero check before calling kzalloc().
--- drivers/gpu/drm/drm_crtc.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_crtc.c +11 -3
@@ -1507,9 +1507,14 @@ static int drm_mode_group_init(struct drm_device *dev, struct drm_mode_group *gr total_objects += dev->mode_config.num_encoder; total_objects += dev->mode_config.num_bridge; - group->id_list =kzalloc (total_objects *sizeof (uint32_t ),GFP_KERNEL ); -if (!group->id_list) -return -ENOMEM ; +if (total_objects) { + group->id_list =kzalloc (total_objects *sizeof (uint32_t ), +GFP_KERNEL ); +if (!group->id_list) +return -ENOMEM ; + }else { + group->id_list =NULL ; + } group->num_crtcs =0 ; group->num_connectors =0 ;
@@ -4337,6 +4342,9 @@ EXPORT_SYMBOL(drm_mode_connector_attach_encoder);int drm_mode_crtc_set_gamma_size (struct drm_crtc *crtc,int gamma_size) { +if (!gamma_size) +return -EINVAL ; + crtc->gamma_size = gamma_size; crtc->gamma_store =kzalloc (gamma_size *sizeof (uint16_t ) *3 ,GFP_KERNEL );
Signature · 1 line
1.8.5
PATCH 3/3 drm/global: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
In reply to Xiubo LiSince we cannot make sure the 'ref->size' will always be none zero here, and then if it equals to zero, the kzalloc() will return ZERO_SIZE_PTR, which equals to ((void *)16).
This patch fix this with just doing the zero check before calling kzalloc().
--- drivers/gpu/drm/drm_global.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/drm_global.c +5 -0
@@ -70,6 +70,11 @@ int drm_global_item_ref(struct drm_global_reference *ref)mutex_lock (&item->mutex);if (item->refcount ==0 ) { +if (!ref->size) { + ret = -EINVAL ; + goto out_err; + } + item->object =kzalloc (ref->size,GFP_KERNEL );if (unlikely (item->object ==NULL )) { ret = -ENOMEM ;
Signature · 1 line
1.8.5
Ping :)
Thanks,
BRs
Xiubo
Quoted 21 lines
-----Original Message-----
From: Xiubo Li [mailto:[email protected]]
Sent: Tuesday, August 12, 2014 11:30 AM
To: [email protected]; [email protected]
Cc: Xiubo Li-B47053
Subject: [PATCH 0/3] drm: Fix possibleZERO_SIZE_PTRpointer dereferencing error.Xiubo Li (3):
drm/bufs: Fix possibleZERO_SIZE_PTRpointer dereferencing error. drm/crtc: Fix possibleZERO_SIZE_PTRpointer dereferencing error. drm/global: Fix possibleZERO_SIZE_PTRpointer dereferencing error.drivers/gpu/drm/drm_bufs.c | 12 +++++++++--- drivers/gpu/drm/drm_crtc.c | 14 +++++++++++--- drivers/gpu/drm/drm_global.c | 5 +++++ 3 files changed, 25 insertions(+), 6 deletions(-)--
1.8.5