public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Akinobu Mita <akinobu.mita@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: stable@kernel.org
Subject: [PATCH] check d_path() error in print-fatal-signals
Date: Sun, 20 May 2007 14:56:39 +0900	[thread overview]
Message-ID: <20070520055639.GA4485@APFDCB5C> (raw)

d_path() returns -ENAMETOOLONG if buffer length is not enough.
But there is no error handling for it in print_vma() which calls
d_path() with not enough buffer (We can easily make segfault program
which has longer path than 128bytes).

This patch allocates enough buffer for d_path() dynamically.
audit_log_d_path() is doing sililar thing. So I just stole from it.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>

---
 kernel/signal.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Index: 2.6-mm/kernel/signal.c
===================================================================
--- 2.6-mm.orig/kernel/signal.c
+++ 2.6-mm/kernel/signal.c
@@ -740,15 +740,23 @@ static int print_vma(struct vm_area_stru
 	 * special [heap] marker for the heap:
 	 */
 	if (file) {
-#define SIZE 128
-		char tmp[SIZE], *str;
-
-		str = d_path(file->f_dentry, file->f_vfsmnt, tmp, SIZE);
-		while (str[0] && (str[0] == ' '))
-			str++;
+		char *p, *path;
 
+		/* We will allow 11 spaces for ' (deleted)' to be appended */
+		path = kmalloc(PATH_MAX + 11, GFP_KERNEL);
+		if (!path)
+			p = "<no memory>";
+		else {
+			p = d_path(file->f_dentry, file->f_vfsmnt, path,
+				   PATH_MAX + 11);
+			if (IS_ERR(p))
+				p = "<too long>";
+			else
+				p = strstrip(p);
+		}
 		pad_len_spaces(len);
-		printk("%s", str);
+		printk("%s", p);
+		kfree(path);
 	} else {
 		const char *name = arch_vma_name(vma);
 		if (!name) {

             reply	other threads:[~2007-05-20  6:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-20  5:56 Akinobu Mita [this message]
2007-05-20  6:41 ` [PATCH] check d_path() error in print-fatal-signals Andrew Morton

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=20070520055639.GA4485@APFDCB5C \
    --to=akinobu.mita@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@kernel.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