From owner-freebsd-hackers@FreeBSD.ORG Thu Feb 18 17:48:36 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 82FE5106566B for ; Thu, 18 Feb 2010 17:48:36 +0000 (UTC) (envelope-from fernando.apesteguia@gmail.com) Received: from mail-ew0-f211.google.com (mail-ew0-f211.google.com [209.85.219.211]) by mx1.freebsd.org (Postfix) with ESMTP id 17AE18FC14 for ; Thu, 18 Feb 2010 17:48:35 +0000 (UTC) Received: by mail-ew0-f211.google.com with SMTP id 3so9237795ewy.13 for ; Thu, 18 Feb 2010 09:48:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=UK0ja8T1yzv1BLk0xKlNp1wwq2Cm71t2VgH6XWuQ9kc=; b=SUn6GUyfs66NYJVSeN8Pg8Yr9GxnE469Q6HGUyg+hnmgBMfEZrZWnoISFotZ7Ef3dC mc+5kvMgUCN75zlFDmmYdMGUjA9r8BSB4Fr5vZPHaZCMQnVg08tOAuE9GFWs/bW9lfmr NH7k4pgySPE/3rfsaE8b4g/m6pBT2MnuKjkog= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=Gc4JdqW0xZ82utFurqNY/bd8i70f5Gj3cCi0OfJLcZHWnNM/964f+955OWZrYv535Q YrUU83IqfL7AkAfK4o5qeaoMGTCLpRUf393xWNeKdRyE4oLHUce+DV39F/a5jH44pYLd TKP96q3OaylzI4PFovNoSL1GqVZvvj/iNtwOQ= MIME-Version: 1.0 Received: by 10.213.109.143 with SMTP id j15mr6773279ebp.84.1266515315664; Thu, 18 Feb 2010 09:48:35 -0800 (PST) In-Reply-To: <20100217191156.GP50403@deviant.kiev.zoral.com.ua> References: <1bd550a01002171051n7117895avb5cf57fb7fbb9388@mail.gmail.com> <20100217191156.GP50403@deviant.kiev.zoral.com.ua> Date: Thu, 18 Feb 2010 18:48:35 +0100 Message-ID: <1bd550a01002180948r48300f8em15efca184d99ed98@mail.gmail.com> From: =?ISO-8859-1?Q?Fernando_Apestegu=EDa?= To: Kostik Belousov Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 17:48:36 -0000 On Wed, Feb 17, 2010 at 8:11 PM, Kostik Belousov 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" >