Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 Feb 2010 22:21:43 +0200
From:      Kostik Belousov <kostikbel@gmail.com>
To:        Fernando Apestegu?a <fernando.apesteguia@gmail.com>
Cc:        FreeBSD Hackers <freebsd-hackers@freebsd.org>
Subject:   Re: linprocfs proc/pid/environ patch & list question
Message-ID:  <20100218202143.GT50403@deviant.kiev.zoral.com.ua>
In-Reply-To: <1bd550a01002180948r48300f8em15efca184d99ed98@mail.gmail.com>
References:  <1bd550a01002171051n7117895avb5cf57fb7fbb9388@mail.gmail.com> <20100217191156.GP50403@deviant.kiev.zoral.com.ua> <1bd550a01002180948r48300f8em15efca184d99ed98@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--LbN0412894TjpI52
Content-Type: text/plain; charset=koi8-r
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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> wr=
ote:
> > 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.
>=20
> 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 proc=
ess
> 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().

>=20
> >>
> >> 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 =9A =9A 2009-10-25 02:10:29.=
000000000 +0100
> >> +++ sys/compat/linprocfs/linprocfs.c =9A2010-02-16 19:38:36.000000000 =
+0100
> >> @@ -939,8 +939,38 @@
> >> =9Astatic int
> >> =9Alinprocfs_doprocenviron(PFS_FILL_ARGS)
> >> =9A{
> >> + =9A =9A int i, error;
> >> + =9A =9A struct ps_strings pss;
> >> + =9A =9A char **ps_envstr;
> >>
> >> - =9A =9A sbuf_printf(sb, "doprocenviron\n%c", '\0');
> >> + =9A =9A PROC_LOCK(p);
> >> + =9A =9A if (p_cansee(td, p) !=3D 0)
> >> + =9A =9A =9A =9A =9A =9A return (0);
> >> + =9A =9A PROC_UNLOCK(p);
> >> +
> >> + =9A =9A error =3D copyin((void *)p->p_sysent->sv_psstrings, &pss,
> >> + =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =
=9A =9A =9A sizeof(pss));
> >> + =9A =9A if (error)
> >> + =9A =9A =9A =9A =9A =9A return (error);
> >> +
> >> + =9A =9A ps_envstr =3D malloc(pss.ps_nenvstr * sizeof(char *),
> >> + =9A =9A =9A =9A M_TEMP, M_WAITOK);
> > This is essentially "panic me" code. =9Aps_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.
>=20
> Thanks for the comment. If I want to check ps_envstr, which threshold wou=
ld be
> reasonable? PAGE_SIZE maybe?
>=20
> Thanks again.
>=20
> >
> >> +
> >> + =9A =9A error =3D copyin((void *)pss.ps_envstr, ps_envstr,
> >> + =9A =9A =9A =9A pss.ps_nenvstr * sizeof(char *));
> >> +
> >> + =9A =9A if (error) {
> >> + =9A =9A =9A =9A =9A =9A free(ps_envstr, M_TEMP);
> >> + =9A =9A =9A =9A =9A =9A return (error);
> >> + =9A =9A }
> >> +
> >> + =9A =9A /* NULL separated list of variable=3Dvalue pairs */
> >> +
> >> + =9A =9A for (i =3D 0; i < pss.ps_nenvstr; i++) {
> >> + =9A =9A =9A =9A =9A =9A sbuf_copyin(sb, ps_envstr[i], 0);
> >> + =9A =9A }
> >> +
> >> + =9A =9A free(ps_envstr, M_TEMP);
> >> =9A =9A =9A return (0);
> >> =9A}
> >> _______________________________________________
> >> 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"
> >

--LbN0412894TjpI52
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (FreeBSD)

iEYEARECAAYFAkt9oVcACgkQC3+MBN1Mb4jl4ACeNQtZwvxExzWHtZFca3rKekf5
sy4AoK6b7vJU0WoX1ns60AmRgvLsM4P0
=HlgO
-----END PGP SIGNATURE-----

--LbN0412894TjpI52--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100218202143.GT50403>