From owner-freebsd-hackers@FreeBSD.ORG Thu Feb 18 20:21:51 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D189D1065694 for ; Thu, 18 Feb 2010 20:21:51 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 462828FC1C for ; Thu, 18 Feb 2010 20:21:50 +0000 (UTC) Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id o1IKLjoR041283 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 18 Feb 2010 22:21:45 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.3/8.14.3) with ESMTP id o1IKLjeF042322; Thu, 18 Feb 2010 22:21:45 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.3/8.14.3/Submit) id o1IKLhT3042321; Thu, 18 Feb 2010 22:21:43 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 18 Feb 2010 22:21:43 +0200 From: Kostik Belousov To: Fernando Apestegu?a Message-ID: <20100218202143.GT50403@deviant.kiev.zoral.com.ua> References: <1bd550a01002171051n7117895avb5cf57fb7fbb9388@mail.gmail.com> <20100217191156.GP50403@deviant.kiev.zoral.com.ua> <1bd550a01002180948r48300f8em15efca184d99ed98@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="LbN0412894TjpI52" Content-Disposition: inline In-Reply-To: <1bd550a01002180948r48300f8em15efca184d99ed98@mail.gmail.com> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: FreeBSD Hackers Subject: Re: linprocfs proc/pid/environ patch & list question X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Feb 2010 20:21:51 -0000 --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 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--