From owner-freebsd-hackers@FreeBSD.ORG Fri Feb 19 18:27:35 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 0D67B106566B for ; Fri, 19 Feb 2010 18:27:35 +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 944BB8FC17 for ; Fri, 19 Feb 2010 18:27:34 +0000 (UTC) Received: by ewy3 with SMTP id 3so392580ewy.13 for ; Fri, 19 Feb 2010 10:27:33 -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=2WceeSA+RS9FEO8SwpQMZixr88g8RqgpIT/tzqxmgKg=; b=WuykgMAYxyOcuVITqm5wFIzPg4VBPF71Pbd+zMtE4Y6jEFQSv1aBDO3rzX48KzAkHL w+cRrAu/D0vs+VwCH0Ur5a294ewq3CoJNuAM7eHxLTXmoxkIECA5z127z8+8YCFjx05s c5bZMW/GK+R4cRKeUG4JpozAhGAJl+R4nank0= 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=PUYVF06w1chvu3yqSR/fadCSffKPYWA+wR3zVfcy//zlqDjEXr0rymqvy5jJGxajYi 2DfJHAYCax+7tsq0R7lkyE4k7cxO8HZCAhuVvrPVKnLfUiCr8ZAx7sYryw2L6l4906BC CfKiwNPMNpLbNq7YKtgYJ/oZJSogYWBy6btMI= MIME-Version: 1.0 Received: by 10.213.1.24 with SMTP id 24mr1039118ebd.57.1266604052721; Fri, 19 Feb 2010 10:27:32 -0800 (PST) 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> Date: Fri, 19 Feb 2010 19:27:32 +0100 Message-ID: <1bd550a01002191027m75657308n8227b738dc64486e@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: Fri, 19 Feb 2010 18:27:35 -0000 2010/2/18 Kostik Belousov : > 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 w= rote: >> > 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 pro= cess >> 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=3D11329 >> >> >> >> --- sys/compat/linprocfs/linprocfs.c.orig =A0 =A0 2009-10-25 02:10:29= .000000000 +0100 >> >> +++ sys/compat/linprocfs/linprocfs.c =A02010-02-16 19:38:36.000000000= +0100 >> >> @@ -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 fro= m >> > vm spaces. >> >> Thanks for the comment. If I want to check ps_envstr, which threshold wo= uld 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= .org" >> > >