"ps -e" without procfs(5)

Mikolaj Golub trociny at freebsd.org
Wed Nov 2 21:27:45 UTC 2011


On Mon, 31 Oct 2011 11:49:48 +0200 Kostik Belousov wrote:

 KB> I think it is better to use sys/elf.h over the machine/elf.h.

 KB> Please change the comment for PROC_AUXV_MAX to "Safety limit on auxv size".
 KB> Also, it worth adding a comment saying that we are reading aux vectors twice,
 KB> first to get a size, second time to fetch a content, for simplicity.

 KB> When reading aux vector, if the PROC_AUXV_MAX entries are iterated over,
 KB> and we still not reached AT_NULL, the return error is 0. Was it intended ?

 KB> For PROC_ARG and PROC_ENV, you blindly trust the read values of the arg and
 KB> env vector sizes. This can easily cause kernel panics due to unability to
 KB> malloc the requested memory. I recommend to put some clump, and twice
 KB> of (PATH_MAX + ARG_MAX) is probably enough (see kern_exec.c, in particular,
 KB> exec_alloc_args). Also, you might use the swappable memory for the strings
 KB> as well, in the style of exec_alloc_args().

 KB> I suspect this is my bug: Reading the GET_PS_STRINGS_CHUNK_SZ may validly
 KB> return EFAULT if the string is shorter than the chunk and aligned at
 KB> the end of the page, assuming the next page is not mapped. There should
 KB> be a fallback to fubyte() read loop. I remember that copyinstr() was
 KB> unsuitable.

 KB> The checks for P_WEXIT in the linprocfs routines look strange. Since
 KB> you are unlocking the process right after the check, it does not make
 KB> sense. In fact, the checks are not needed, I believe, since pseudofs
 KB> already did the hold (see e.g. pfs_read and pfs_visible).

Here is an updated version of the patch. Also available at 

http://people.freebsd.org/~trociny/env.sys.1.patch

I decided to use the same constant (PROC_VECTOR_MAX) for limiting both the number
of arg or env strings and the numbex of aux vectors.

Also I decided not to play with exec_alloc_args :-).

-- 
Mikolaj Golub

-------------- next part --------------
A non-text attachment was scrubbed...
Name: env.sys.1.patch
Type: text/x-patch
Size: 18089 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20111102/51f18720/env.sys.1.bin


More information about the freebsd-hackers mailing list