Date: Thu, 18 Feb 2010 18:48:35 +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: <1bd550a01002180948r48300f8em15efca184d99ed98@mail.gmail.com> In-Reply-To: <20100217191156.GP50403@deviant.kiev.zoral.com.ua> References: <1bd550a01002171051n7117895avb5cf57fb7fbb9388@mail.gmail.com> <20100217191156.GP50403@deviant.kiev.zoral.com.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Feb 17, 2010 at 8:11 PM, Kostik Belousov <kostikbel@gmail.com> wrot= e: > 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=3DXXXX the /compat/linux/proc/pid/environ for the child proces= s does not show the VAR variable. >> >> Don't we have a 'kernel newbies'-like list? >> >> Thanks in advance. >> >> [1] http://forums.freebsd.org/showthread.php?t=3D11329 >> >> --- sys/compat/linprocfs/linprocfs.c.orig =A0 =A0 2009-10-25 02:10:29.00= 0000000 +0100 >> +++ sys/compat/linprocfs/linprocfs.c =A02010-02-16 19:38:36.000000000 +0= 100 >> @@ -939,8 +939,38 @@ >> =A0static int >> =A0linprocfs_doprocenviron(PFS_FILL_ARGS) >> =A0{ >> + =A0 =A0 int i, error; >> + =A0 =A0 struct ps_strings pss; >> + =A0 =A0 char **ps_envstr; >> >> - =A0 =A0 sbuf_printf(sb, "doprocenviron\n%c", '\0'); >> + =A0 =A0 PROC_LOCK(p); >> + =A0 =A0 if (p_cansee(td, p) !=3D 0) >> + =A0 =A0 =A0 =A0 =A0 =A0 return (0); >> + =A0 =A0 PROC_UNLOCK(p); >> + >> + =A0 =A0 error =3D copyin((void *)p->p_sysent->sv_psstrings, &pss, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 sizeof(pss)); >> + =A0 =A0 if (error) >> + =A0 =A0 =A0 =A0 =A0 =A0 return (error); >> + >> + =A0 =A0 ps_envstr =3D malloc(pss.ps_nenvstr * sizeof(char *), >> + =A0 =A0 =A0 =A0 M_TEMP, M_WAITOK); > This is essentially "panic me" code. =A0ps_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. > >> + >> + =A0 =A0 error =3D copyin((void *)pss.ps_envstr, ps_envstr, >> + =A0 =A0 =A0 =A0 pss.ps_nenvstr * sizeof(char *)); >> + >> + =A0 =A0 if (error) { >> + =A0 =A0 =A0 =A0 =A0 =A0 free(ps_envstr, M_TEMP); >> + =A0 =A0 =A0 =A0 =A0 =A0 return (error); >> + =A0 =A0 } >> + >> + =A0 =A0 /* NULL separated list of variable=3Dvalue pairs */ >> + >> + =A0 =A0 for (i =3D 0; i < pss.ps_nenvstr; i++) { >> + =A0 =A0 =A0 =A0 =A0 =A0 sbuf_copyin(sb, ps_envstr[i], 0); >> + =A0 =A0 } >> + >> + =A0 =A0 free(ps_envstr, M_TEMP); >> =A0 =A0 =A0 return (0); >> =A0} >> _______________________________________________ >> freebsd-hackers@freebsd.org mailing list >> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers >> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.or= g" >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1bd550a01002180948r48300f8em15efca184d99ed98>