"ps -e" without procfs(5)
trociny at freebsd.org
Mon Oct 31 10:54:50 UTC 2011
On Mon, 31 Oct 2011 11:49:48 +0200 Kostik Belousov wrote:
KB> On Sat, Oct 29, 2011 at 01:32:39PM +0300, Mikolaj Golub wrote:
>> What do you think about the attached patch? This is a kernel
>> part. COMPAT_FREEBSD32 has not been tested after the last update (just checked
>> that it compiles): it looks I will not have access to amd64 box for testing
>> during the weekend. I will test it after the weekend.
>> Both kernel and userland parts are available here:
>> Currently there is an issue with procstat -x: if one tried to run it on 64 bit
>> for a 32 bit process it would not detect this so would output a garbage. Could
>> somebody recommend a way how to get this info about a process from userlend?
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 ?
According to kern_exec.c it is possible that a process doesn't have auxv at
all. I don't know a way how to detect this. So because PROC_AUXV_MAX is much
larger than expected amount of aux entries and we have not reached AT_NULL it
is most likely the process doesn't have auxv and 0 length array (without
error) is returned.
If you think I should return a error in this situation, I can add this. Please
tell me the error code I should return :-).
Also, may be there is a sane way to check on auxv existence?
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> 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).
Ah, right. Unintentionally added when was adding the P_SYSTEM check.
Thank you for all your comments. I will do this.
More information about the freebsd-hackers