Date: Mon, 31 Oct 2011 12:54:42 +0200 From: Mikolaj Golub <trociny@freebsd.org> To: Kostik Belousov <kostikbel@gmail.com> Cc: freebsd-hackers@freebsd.org, Robert Watson <rwatson@freebsd.org> Subject: Re: "ps -e" without procfs(5) Message-ID: <86ty6pe8i5.fsf@in138.ua3> In-Reply-To: <20111031094948.GB50300@deviant.kiev.zoral.com.ua> (Kostik Belousov's message of "Mon, 31 Oct 2011 11:49:48 %2B0200") References: <86y5wkeuw9.fsf@kopusha.home.net> <20111016171005.GB50300@deviant.kiev.zoral.com.ua> <86aa8qozyx.fsf@kopusha.home.net> <20111025082451.GO50300@deviant.kiev.zoral.com.ua> <86aa8k2im0.fsf@kopusha.home.net> <20111031094948.GB50300@deviant.kiev.zoral.com.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
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: >> >> http://people.freebsd.org/~trociny/env.sys.patch >> http://people.freebsd.org/~trociny/env.user.patch >> >> 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> 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). Ah, right. Unintentionally added when was adding the P_SYSTEM check. Thank you for all your comments. I will do this. -- Mikolaj Golub
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86ty6pe8i5.fsf>