public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Ben Widawsky <ben@bwidawsk.net>
To: Intel GFX <intel-gfx@lists.freedesktop.org>
Subject: [penguin-kernel@I-love.SAKURA.ne.jp: [PATCH] drm/i915: Fix refcount leak and possible NULL pointer dereference.]
Date: Tue, 24 Dec 2013 09:51:24 -0800	[thread overview]
Message-ID: <20131224175124.GA13719@bwidawsk.net> (raw)

----- Forwarded message from Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> -----

Date: Tue, 24 Dec 2013 20:50:23 +0900
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
To: chris@chris-wilson.co.uk, ben@bwidawsk.net, daniel.vetter@ffwll.ch
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] drm/i915: Fix refcount leak and possible NULL pointer dereference.
Message-Id: <201312242050.CGH78112.JQFOSVMLOFtHOF@I-love.SAKURA.ne.jp>

>From 482be6384379072eb4c0d45d0ab8a25df4f59ed7 Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Date: Tue, 24 Dec 2013 18:04:14 +0900
Subject: [PATCH] drm/i915: Fix refcount leak and possible NULL pointer dereference.

Since get_pid_task() grabs a reference on the task_struct, we have to drop the
refcount after reading that task's comm name. Also, directly reading like
get_pid_task()->comm can trigger an oops when get_pid_task() returned NULL.

This patch fixes both problems.

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
 drivers/gpu/drm/i915/i915_debugfs.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 6ed45a9..d0a8e0a 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -406,11 +406,20 @@ static int i915_gem_object_info(struct seq_file *m, void* data)
 	seq_putc(m, '\n');
 	list_for_each_entry_reverse(file, &dev->filelist, lhead) {
 		struct file_stats stats;
+		struct task_struct *task;
+		char name[TASK_COMM_LEN];
 
 		memset(&stats, 0, sizeof(stats));
 		idr_for_each(&file->object_idr, per_file_stats, &stats);
+		task = get_pid_task(file->pid, PIDTYPE_PID);
+		if (task) {
+			get_task_comm(name, task);
+			put_task_struct(task);
+		} else {
+			strlcpy(name, "<unknown>", sizeof(name));
+		}
 		seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu inactive, %zu unbound)\n",
-			   get_pid_task(file->pid, PIDTYPE_PID)->comm,
+			   name,
 			   stats.count,
 			   stats.total,
 			   stats.active,
-- 
1.7.1

----- End forwarded message -----

-- 
Ben Widawsky, Intel Open Source Technology Center

                 reply	other threads:[~2013-12-24 17:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131224175124.GA13719@bwidawsk.net \
    --to=ben@bwidawsk.net \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox