Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Jan 2012 18:47:24 +0000 (UTC)
From:      Mikolaj Golub <trociny@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r230145 - in head/sys: compat/linprocfs fs/procfs kern sys
Message-ID:  <201201151847.q0FIlOXg095240@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trociny
Date: Sun Jan 15 18:47:24 2012
New Revision: 230145
URL: http://svn.freebsd.org/changeset/base/230145

Log:
  Abrogate nchr argument in proc_getargv() and proc_getenvv(): we always want
  to read strings completely to know the actual size.
  
  As a side effect it fixes the issue with kern.proc.args and kern.proc.env
  sysctls, which didn't return the size of available data when calling
  sysctl(3) with the NULL argument for oldp.
  
  Note, in get_ps_strings(), which does actual work for proc_getargv() and
  proc_getenvv(), we still have a safety limit on the size of data read in
  case of a corrupted procces stack.
  
  Suggested by:	kib
  MFC after:	3 days

Modified:
  head/sys/compat/linprocfs/linprocfs.c
  head/sys/fs/procfs/procfs_status.c
  head/sys/kern/kern_proc.c
  head/sys/sys/proc.h

Modified: head/sys/compat/linprocfs/linprocfs.c
==============================================================================
--- head/sys/compat/linprocfs/linprocfs.c	Sun Jan 15 18:26:43 2012	(r230144)
+++ head/sys/compat/linprocfs/linprocfs.c	Sun Jan 15 18:47:24 2012	(r230145)
@@ -954,7 +954,7 @@ linprocfs_doproccmdline(PFS_FILL_ARGS)
 
 	PROC_UNLOCK(p);
 
-	ret = proc_getargv(td, p, sb, ARG_MAX);
+	ret = proc_getargv(td, p, sb);
 	return (ret);
 }
 
@@ -988,7 +988,7 @@ linprocfs_doprocenviron(PFS_FILL_ARGS)
 
 	PROC_UNLOCK(p);
 
-	ret = proc_getenvv(td, p, sb, ARG_MAX);
+	ret = proc_getenvv(td, p, sb);
 	return (ret);
 }
 

Modified: head/sys/fs/procfs/procfs_status.c
==============================================================================
--- head/sys/fs/procfs/procfs_status.c	Sun Jan 15 18:26:43 2012	(r230144)
+++ head/sys/fs/procfs/procfs_status.c	Sun Jan 15 18:47:24 2012	(r230145)
@@ -193,5 +193,5 @@ procfs_doproccmdline(PFS_FILL_ARGS)
 
 	PROC_UNLOCK(p);
 
-	return (proc_getargv(td, p, sb, ARG_MAX));
+	return (proc_getargv(td, p, sb));
 }

Modified: head/sys/kern/kern_proc.c
==============================================================================
--- head/sys/kern/kern_proc.c	Sun Jan 15 18:26:43 2012	(r230144)
+++ head/sys/kern/kern_proc.c	Sun Jan 15 18:47:24 2012	(r230145)
@@ -1631,20 +1631,19 @@ get_proc_vector(struct thread *td, struc
 
 static int
 get_ps_strings(struct thread *td, struct proc *p, struct sbuf *sb,
-    enum proc_vector_type type, size_t nchr)
+    enum proc_vector_type type)
 {
-	size_t done, len, vsize;
+	size_t done, len, nchr, vsize;
 	int error, i;
 	char **proc_vector, *sptr;
 	char pss_string[GET_PS_STRINGS_CHUNK_SZ];
 
 	PROC_ASSERT_HELD(p);
 
-	 /*
-	  * We are not going to read more than 2 * (PATH_MAX + ARG_MAX) bytes.
-	  */
-	if (nchr > 2 * (PATH_MAX + ARG_MAX))
-		nchr = 2 * (PATH_MAX + ARG_MAX);
+	/*
+	 * We are not going to read more than 2 * (PATH_MAX + ARG_MAX) bytes.
+	 */
+	nchr = 2 * (PATH_MAX + ARG_MAX);
 
 	error = get_proc_vector(td, p, &proc_vector, &vsize, type);
 	if (error != 0)
@@ -1679,17 +1678,17 @@ done:
 }
 
 int
-proc_getargv(struct thread *td, struct proc *p, struct sbuf *sb, size_t nchr)
+proc_getargv(struct thread *td, struct proc *p, struct sbuf *sb)
 {
 
-	return (get_ps_strings(curthread, p, sb, PROC_ARG, nchr));
+	return (get_ps_strings(curthread, p, sb, PROC_ARG));
 }
 
 int
-proc_getenvv(struct thread *td, struct proc *p, struct sbuf *sb, size_t nchr)
+proc_getenvv(struct thread *td, struct proc *p, struct sbuf *sb)
 {
 
-	return (get_ps_strings(curthread, p, sb, PROC_ENV, nchr));
+	return (get_ps_strings(curthread, p, sb, PROC_ENV));
 }
 
 /*
@@ -1728,7 +1727,7 @@ sysctl_kern_proc_args(SYSCTL_HANDLER_ARG
 		_PHOLD(p);
 		PROC_UNLOCK(p);
 		sbuf_new_for_sysctl(&sb, NULL, GET_PS_STRINGS_CHUNK_SZ, req);
-		error = proc_getargv(curthread, p, &sb, req->oldlen);
+		error = proc_getargv(curthread, p, &sb);
 		error2 = sbuf_finish(&sb);
 		PRELE(p);
 		sbuf_delete(&sb);
@@ -1780,7 +1779,7 @@ sysctl_kern_proc_env(SYSCTL_HANDLER_ARGS
 	}
 
 	sbuf_new_for_sysctl(&sb, NULL, GET_PS_STRINGS_CHUNK_SZ, req);
-	error = proc_getenvv(curthread, p, &sb, req->oldlen);
+	error = proc_getenvv(curthread, p, &sb);
 	error2 = sbuf_finish(&sb);
 	PRELE(p);
 	sbuf_delete(&sb);

Modified: head/sys/sys/proc.h
==============================================================================
--- head/sys/sys/proc.h	Sun Jan 15 18:26:43 2012	(r230144)
+++ head/sys/sys/proc.h	Sun Jan 15 18:47:24 2012	(r230145)
@@ -859,10 +859,8 @@ int	p_canwait(struct thread *td, struct 
 struct	pargs *pargs_alloc(int len);
 void	pargs_drop(struct pargs *pa);
 void	pargs_hold(struct pargs *pa);
-int	proc_getargv(struct thread *td, struct proc *p, struct sbuf *sb,
-	    size_t nchr);
-int	proc_getenvv(struct thread *td, struct proc *p, struct sbuf *sb,
-	    size_t nchr);
+int	proc_getargv(struct thread *td, struct proc *p, struct sbuf *sb);
+int	proc_getenvv(struct thread *td, struct proc *p, struct sbuf *sb);
 void	procinit(void);
 void	proc_linkup0(struct proc *p, struct thread *td);
 void	proc_linkup(struct proc *p, struct thread *td);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201201151847.q0FIlOXg095240>