public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] check d_path() error in print-fatal-signals
@ 2007-05-20  5:56 Akinobu Mita
  2007-05-20  6:41 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Akinobu Mita @ 2007-05-20  5:56 UTC (permalink / raw)
  To: linux-kernel; +Cc: stable

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) {

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

* Re: [PATCH] check d_path() error in print-fatal-signals
  2007-05-20  5:56 [PATCH] check d_path() error in print-fatal-signals Akinobu Mita
@ 2007-05-20  6:41 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2007-05-20  6:41 UTC (permalink / raw)
  To: Akinobu Mita; +Cc: linux-kernel, stable, Ingo Molnar

On Sun, 20 May 2007 14:56:39 +0900 Akinobu Mita <akinobu.mita@gmail.com> wrote:

> 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) {

Thanks.

This bug exists only in -mm kernels, and is introduced by the -mm-only
debugging patch
vdso-improve-print_fatal_signals-support-by-adding-memory-maps.patch.

I think I'll just drop that patch - I don't think it is proving useful to
anyone.


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

end of thread, other threads:[~2007-05-20  6:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-20  5:56 [PATCH] check d_path() error in print-fatal-signals Akinobu Mita
2007-05-20  6:41 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox