linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3.7-rc8] ttm: Fix possible _manager memory allocation oops
@ 2012-12-06 16:20 Tim Gardner
  2012-12-06 22:46 ` Dave Airlie
  0 siblings, 1 reply; 5+ messages in thread
From: Tim Gardner @ 2012-12-06 16:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: Tim Gardner, David Airlie, Dave Airlie, Paul E. McKenney,
	Zhao Yakui, David Howells, dri-devel

Memory for _manager is allocated using kzalloc() but the result is not checked.

Free _manager on error lest memory become orphaned.

I was led to scrutinize ttm_page_alloc_init() from a smatch warning:

drivers/gpu/drm/ttm/ttm_page_alloc.c:799 ttm_page_alloc_init() error: potential null dereference '_manager'.  (kzalloc returns null)

Cc: David Airlie <airlied@linux.ie>
Cc: Dave Airlie <airlied@redhat.com>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Zhao Yakui <yakui.zhao@intel.com>
Cc: David Howells <dhowells@redhat.com>
Cc: dri-devel@lists.freedesktop.org
Cc: stable@vger.kernel.org # 3.5+
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
---

This patch applies to stable 3.5 and newer.

 drivers/gpu/drm/ttm/ttm_page_alloc.c |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
index bd2a3b4..2c73d0a 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
@@ -798,6 +798,10 @@ int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages)
 	pr_info("Initializing pool allocator\n");
 
 	_manager = kzalloc(sizeof(*_manager), GFP_KERNEL);
+	if (!_manager) {
+		pr_err("ttm: Could not allocate _manager.\n");
+		return -ENOMEM;
+	}
 
 	ttm_page_pool_init_locked(&_manager->wc_pool, GFP_HIGHUSER, "wc");
 
@@ -817,6 +821,7 @@ int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages)
 				   &glob->kobj, "pool");
 	if (unlikely(ret != 0)) {
 		kobject_put(&_manager->kobj);
+		kfree(_manager);
 		_manager = NULL;
 		return ret;
 	}
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 3.7-rc8] ttm: Fix possible _manager memory allocation oops
  2012-12-06 16:20 [PATCH 3.7-rc8] ttm: Fix possible _manager memory allocation oops Tim Gardner
@ 2012-12-06 22:46 ` Dave Airlie
  2012-12-06 23:05   ` Tim Gardner
  0 siblings, 1 reply; 5+ messages in thread
From: Dave Airlie @ 2012-12-06 22:46 UTC (permalink / raw)
  To: Tim Gardner
  Cc: linux-kernel, Paul E. McKenney, dri-devel, David Howells, Dave Airlie

On Thu, Dec 6, 2012 at 4:20 PM, Tim Gardner <tim.gardner@canonical.com> wrote:
> Memory for _manager is allocated using kzalloc() but the result is not checked.
>
> Free _manager on error lest memory become orphaned.
>
> I was led to scrutinize ttm_page_alloc_init() from a smatch warning:
>
> drivers/gpu/drm/ttm/ttm_page_alloc.c:799 ttm_page_alloc_init() error: potential null dereference '_manager'.  (kzalloc returns null)
>
> Cc: David Airlie <airlied@linux.ie>
> Cc: Dave Airlie <airlied@redhat.com>
> Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
> Cc: Zhao Yakui <yakui.zhao@intel.com>
> Cc: David Howells <dhowells@redhat.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: stable@vger.kernel.org # 3.5+
> Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
> ---
>
> This patch applies to stable 3.5 and newer.
>
>  drivers/gpu/drm/ttm/ttm_page_alloc.c |    5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
> index bd2a3b4..2c73d0a 100644
> --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
> +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
> @@ -798,6 +798,10 @@ int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages)
>         pr_info("Initializing pool allocator\n");
>
>         _manager = kzalloc(sizeof(*_manager), GFP_KERNEL);
> +       if (!_manager) {
> +               pr_err("ttm: Could not allocate _manager.\n");
> +               return -ENOMEM;
> +       }

This is fine,
>
>         ttm_page_pool_init_locked(&_manager->wc_pool, GFP_HIGHUSER, "wc");
>
> @@ -817,6 +821,7 @@ int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages)
>                                    &glob->kobj, "pool");
>         if (unlikely(ret != 0)) {
>                 kobject_put(&_manager->kobj);
> +               kfree(_manager);
>                 _manager = NULL;

I don;t think this is, since the kobject_put shuold free it.

Dave.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 3.7-rc8] ttm: Fix possible _manager memory allocation oops
  2012-12-06 22:46 ` Dave Airlie
@ 2012-12-06 23:05   ` Tim Gardner
  2012-12-07  5:59     ` Dave Airlie
  0 siblings, 1 reply; 5+ messages in thread
From: Tim Gardner @ 2012-12-06 23:05 UTC (permalink / raw)
  To: Dave Airlie
  Cc: linux-kernel, Paul E. McKenney, dri-devel, David Howells, Dave Airlie

On 12/06/2012 03:46 PM, Dave Airlie wrote:

>>
>>          ttm_page_pool_init_locked(&_manager->wc_pool, GFP_HIGHUSER, "wc");
>>
>> @@ -817,6 +821,7 @@ int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages)
>>                                     &glob->kobj, "pool");
>>          if (unlikely(ret != 0)) {
>>                  kobject_put(&_manager->kobj);
>> +               kfree(_manager);
>>                  _manager = NULL;
>
> I don;t think this is, since the kobject_put shuold free it.
>

kobject_put only frees memory referenced by kobj, but not the memory 
pointed at by _manager.

rtg
-- 
Tim Gardner tim.gardner@canonical.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 3.7-rc8] ttm: Fix possible _manager memory allocation oops
  2012-12-06 23:05   ` Tim Gardner
@ 2012-12-07  5:59     ` Dave Airlie
  2012-12-07 14:16       ` [PATCH v2 " Tim Gardner
  0 siblings, 1 reply; 5+ messages in thread
From: Dave Airlie @ 2012-12-07  5:59 UTC (permalink / raw)
  To: Tim Gardner
  Cc: linux-kernel, Paul E. McKenney, dri-devel, David Howells, Dave Airlie

On Fri, Dec 7, 2012 at 9:05 AM, Tim Gardner <tim.gardner@canonical.com> wrote:
> On 12/06/2012 03:46 PM, Dave Airlie wrote:
>
>>>
>>>          ttm_page_pool_init_locked(&_manager->wc_pool, GFP_HIGHUSER,
>>> "wc");
>>>
>>> @@ -817,6 +821,7 @@ int ttm_page_alloc_init(struct ttm_mem_global *glob,
>>> unsigned max_pages)
>>>                                     &glob->kobj, "pool");
>>>          if (unlikely(ret != 0)) {
>>>                  kobject_put(&_manager->kobj);
>>> +               kfree(_manager);
>>>                  _manager = NULL;
>>
>>
>> I don;t think this is, since the kobject_put shuold free it.
>>
>
> kobject_put only frees memory referenced by kobj, but not the memory pointed
> at by _manager.
>

The memory pointed at by _manager is the memory freed by the kobj if I
read the code correctly.

Dave.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 3.7-rc8] ttm: Fix possible _manager memory allocation oops
  2012-12-07  5:59     ` Dave Airlie
@ 2012-12-07 14:16       ` Tim Gardner
  0 siblings, 0 replies; 5+ messages in thread
From: Tim Gardner @ 2012-12-07 14:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Tim Gardner, David Airlie, Dave Airlie, Paul E. McKenney,
	Zhao Yakui, David Howells, dri-devel

Memory for _manager is allocated using kzalloc() but the result is not checked.

I was led to scrutinize ttm_page_alloc_init() from a smatch warning:

drivers/gpu/drm/ttm/ttm_page_alloc.c:799 ttm_page_alloc_init() error: potential null dereference '_manager'.  (kzalloc returns null)

Cc: David Airlie <airlied@linux.ie>
Cc: Dave Airlie <airlied@redhat.com>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Zhao Yakui <yakui.zhao@intel.com>
Cc: David Howells <dhowells@redhat.com>
Cc: dri-devel@lists.freedesktop.org
Cc: stable@vger.kernel.org # 3.5+
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
---

This patch applies to stable 3.5 and newer.

V2 - kobject_put(&_manager->kobj) uses a destructor and
container_of() to free _mamanger.

 drivers/gpu/drm/ttm/ttm_page_alloc.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
index bd2a3b4..c64e96c 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
@@ -798,6 +798,10 @@ int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages)
 	pr_info("Initializing pool allocator\n");
 
 	_manager = kzalloc(sizeof(*_manager), GFP_KERNEL);
+	if (!_manager) {
+		pr_err("ttm: Could not allocate _manager.\n");
+		return -ENOMEM;
+	}
 
 	ttm_page_pool_init_locked(&_manager->wc_pool, GFP_HIGHUSER, "wc");
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-12-07 14:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-06 16:20 [PATCH 3.7-rc8] ttm: Fix possible _manager memory allocation oops Tim Gardner
2012-12-06 22:46 ` Dave Airlie
2012-12-06 23:05   ` Tim Gardner
2012-12-07  5:59     ` Dave Airlie
2012-12-07 14:16       ` [PATCH v2 " Tim Gardner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).