Date: Fri, 19 Feb 2010 19:27:32 +0100 From: =?ISO-8859-1?Q?Fernando_Apestegu=EDa?= <fernando.apesteguia@gmail.com> To: Kostik Belousov <kostikbel@gmail.com> Cc: FreeBSD Hackers <freebsd-hackers@freebsd.org> Subject: Re: linprocfs proc/pid/environ patch & list question Message-ID: <1bd550a01002191027m75657308n8227b738dc64486e@mail.gmail.com> In-Reply-To: <20100218202143.GT50403@deviant.kiev.zoral.com.ua> References: <1bd550a01002171051n7117895avb5cf57fb7fbb9388@mail.gmail.com> <20100217191156.GP50403@deviant.kiev.zoral.com.ua> <1bd550a01002180948r48300f8em15efca184d99ed98@mail.gmail.com> <20100218202143.GT50403@deviant.kiev.zoral.com.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
2010/2/18 Kostik Belousov <kostikbel@gmail.com>: > On Thu, Feb 18, 2010 at 06:48:35PM +0100, Fernando Apestegu?a wrote: >> On Wed, Feb 17, 2010 at 8:11 PM, Kostik Belousov <kostikbel@gmail.com> wrote: >> > On Wed, Feb 17, 2010 at 07:51:06PM +0100, Fernando Apestegu?a wrote: >> >> Hi, >> >> >> >> I have a small patch (against 8.0-RELEASE-p2) that _should_ implement >> >> the /proc/pid/environ file >> >> under linprocfs. >> >> However, it seems it does not work properly but I don't know what I'm >> >> doing wrong. >> >> Is this list the place to ask for help? I tried in the forums[1] but >> >> got no answer. >> > Putting aside any "does not work" questions, please see comment below. >> >> Sorry I didn't explain this. If I have a process forked from bash >> shell in which I have >> exported VAR=XXXX the /compat/linux/proc/pid/environ for the child process >> does not show the VAR variable. > Copyin copies the data from the address space of the current process. > You are interested in the content of address space of different process. > Look at the proc_rwmem(). Thanks > >> >> >> >> >> Don't we have a 'kernel newbies'-like list? >> >> >> >> Thanks in advance. >> >> >> >> [1] http://forums.freebsd.org/showthread.php?t=11329 >> >> >> >> --- sys/compat/linprocfs/linprocfs.c.orig 2009-10-25 02:10:29.000000000 +0100 >> >> +++ sys/compat/linprocfs/linprocfs.c 2010-02-16 19:38:36.000000000 +0100 >> >> @@ -939,8 +939,38 @@ >> >> static int >> >> linprocfs_doprocenviron(PFS_FILL_ARGS) >> >> { >> >> + int i, error; >> >> + struct ps_strings pss; >> >> + char **ps_envstr; >> >> >> >> - sbuf_printf(sb, "doprocenviron\n%c", '\0'); >> >> + PROC_LOCK(p); >> >> + if (p_cansee(td, p) != 0) >> >> + return (0); >> >> + PROC_UNLOCK(p); >> >> + >> >> + error = copyin((void *)p->p_sysent->sv_psstrings, &pss, >> >> + sizeof(pss)); >> >> + if (error) >> >> + return (error); >> >> + >> >> + ps_envstr = malloc(pss.ps_nenvstr * sizeof(char *), >> >> + M_TEMP, M_WAITOK); >> > This is essentially "panic me" code. ps_nenvstr is user-controlled, >> > and allows to specify arbitrary integers. >> > >> > Even ignoring exhaustion of the kernel map, it can cause allocation of >> > big amount of physical memory. Note that execve(2) implementation uses >> > swappable memory to store arguments and environment strings passed from >> > vm spaces. >> >> Thanks for the comment. If I want to check ps_envstr, which threshold would be >> reasonable? PAGE_SIZE maybe? >> >> Thanks again. >> >> > >> >> + >> >> + error = copyin((void *)pss.ps_envstr, ps_envstr, >> >> + pss.ps_nenvstr * sizeof(char *)); >> >> + >> >> + if (error) { >> >> + free(ps_envstr, M_TEMP); >> >> + return (error); >> >> + } >> >> + >> >> + /* NULL separated list of variable=value pairs */ >> >> + >> >> + for (i = 0; i < pss.ps_nenvstr; i++) { >> >> + sbuf_copyin(sb, ps_envstr[i], 0); >> >> + } >> >> + >> >> + free(ps_envstr, M_TEMP); >> >> return (0); >> >> } >> >> _______________________________________________ >> >> freebsd-hackers@freebsd.org mailing list >> >> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers >> >> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" >> > >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1bd550a01002191027m75657308n8227b738dc64486e>
