On Mon, 31 Oct 2011 11:49:48 +0200 Kostik Belousov wrote: 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.
Hm, I thought that this issue was only for reading arg and env strings (which could be shorter than GET_PS_STRINGS_CHUNK_SZ), but investigating the cases when EFAULT was returned in my tests (running buildworld and procstat in loop) I saw that it also returned when reading other objects (like struct ps_strings), and a fallback to fubyte() read loop was successful in those cases too. So I updated the patch to do fallback for any type of read (although it does not contain a good comment explaining why fubyte() read might succeed when proc_rwmem() failed). Also there were the cases when EFAULT was returned because arg vector contained the NULL pointer. I observed this for sh processes. In lib/libc/gen/setproctitle.c I found this comment: oargc = ps_strings->ps_nargvstr; oargv = ps_strings->ps_argvstr; for (i = len = 0; i < oargc; i++) { /* * The program may have scribbled into its * argv array, e.g., to remove some arguments. * If that has happened, break out before * trying to call strlen on a NULL pointer. */ if (oargv[i] == NULL) { oargc = i; break; } I have updated my patch to do the same. Running buildworld test after these changes I have observed EFAULT only once, for cc process, when argv contained a pointer to 0x40. Also, for kern.proc.args some times errors like below are observed: procstat: sysctl: kern.proc.args: 58002: 8: Exec format error And for kern.proc.env: procstat: sysctl: kern.proc.env: 81352: 16: Device busy But I have not investigated these cases yet. The update version: http://people.freebsd.org/~trociny/env.sys.2.patch -- Mikolaj Golub _______________________________________________ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"