From owner-freebsd-hackers@freebsd.org Fri May 8 17:37:05 2020 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C6AF62DD325 for ; Fri, 8 May 2020 17:37:05 +0000 (UTC) (envelope-from freebsd-rwg@gndrsh.dnsmgr.net) Received: from gndrsh.dnsmgr.net (br1.CN84in.dnsmgr.net [69.59.192.140]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 49Jcw06LBSz45lW; Fri, 8 May 2020 17:37:04 +0000 (UTC) (envelope-from freebsd-rwg@gndrsh.dnsmgr.net) Received: from gndrsh.dnsmgr.net (localhost [127.0.0.1]) by gndrsh.dnsmgr.net (8.13.3/8.13.3) with ESMTP id 048Hb2TX053937; Fri, 8 May 2020 10:37:02 -0700 (PDT) (envelope-from freebsd-rwg@gndrsh.dnsmgr.net) Received: (from freebsd-rwg@localhost) by gndrsh.dnsmgr.net (8.13.3/8.13.3/Submit) id 048Hb2CA053936; Fri, 8 May 2020 10:37:02 -0700 (PDT) (envelope-from freebsd-rwg) From: "Rodney W. Grimes" Message-Id: <202005081737.048Hb2CA053936@gndrsh.dnsmgr.net> Subject: Re: Allow procstat to view current working directory? [xfce4-terminal, linprocfs, ...] In-Reply-To: To: Damjan Jovanovic Date: Fri, 8 May 2020 10:37:02 -0700 (PDT) CC: Konstantin Belousov , Hackers freeBSD X-Mailer: ELM [version 2.4ME+ PL121h (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Rspamd-Queue-Id: 49Jcw06LBSz45lW X-Spamd-Bar: + Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=none (mx1.freebsd.org: domain of freebsd-rwg@gndrsh.dnsmgr.net has no SPF policy when checking 69.59.192.140) smtp.mailfrom=freebsd-rwg@gndrsh.dnsmgr.net X-Spamd-Result: default: False [1.86 / 15.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_TLS_LAST(0.00)[]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[dnsmgr.net]; AUTH_NA(1.00)[]; NEURAL_SPAM_MEDIUM(0.29)[0.291,0]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; IP_SCORE(0.03)[ip: (0.12), ipnet: 69.59.192.0/19(0.06), asn: 13868(0.03), country: US(-0.05)]; NEURAL_SPAM_LONG(0.63)[0.633,0]; R_SPF_NA(0.00)[]; FREEMAIL_TO(0.00)[gmail.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:13868, ipnet:69.59.192.0/19, country:US]; MID_RHS_MATCH_FROM(0.00)[]; SUBJECT_HAS_QUESTION(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.32 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 May 2020 17:37:05 -0000 > On Wed, May 6, 2020 at 11:46 PM Konstantin Belousov wrote: > > > On Wed, May 06, 2020 at 08:32:08PM +0200, Damjan Jovanovic wrote: > > > Hi > > > > > > Currently "procstat fd [pid]" cannot view anything, even for other > > > processes owned by the user making the call, not even their current > > working > > > directory (CWD), unless it has PGET_CANDEBUG permission. > > > > > > linprocfs however allows reading the CWD for any process because it > > doesn't > > > perform that check (sys/compat/linprocfs/linprocfs.c, function > > > linprocfs_doproccwd()). > > > > > > Applications use this, eg. xfce4-terminal relies on > > > /compat/linux/proc//cwd to find the shell's CWD, so that when you > > open > > > a new tab, it starts in the same CWD as the tab you opened it from ( > > > > > https://github.com/xfce-mirror/xfce4-terminal/blob/master/terminal/terminal-screen.c#L2343 > > ). > > > I would like to patch xfce4-terminal to use libprocstat for that instead > > of > > > needing linprocfs to be mounted, but since procstat is more restrictive, > > it > > > will break it. > > > > > > Can we please downgrade PGET_CANDEBUG to at least PGET_CANSEE, so you can > > > view the CWD for processes you own? Maybe other open files still need to > > be > > > hidden, but the CWD doesn't seem like a major security concern. > > Can you explain why CANDEBUG vs CANSEE matters for your case ? > > Or better, why xfce4-terminal cannot debug shells it spawns ? > > Is it suid ? > > > > > xfce4-terminal is a normal process, no suid. It wants to read CWD of the > current tab so the new tab opens in the same directory, which is often what > you want. On Linux /proc//cwd is lrwxrwxrwx for all processes. On > FreeBSD /compat/linux/proc//cwd is lrwxrwxrwx for all procesess. It > works as intended at present, as long as you have linprocfs mounted. > > But I'd rather not have to mount linprocfs. If I patch xfce4-terminal to > use libprocstat instead, then it will break, as it needs CANDEBUG to see > the CWD, a restriction that seems extreme. > > > > > > My initial reaction was that linprocfs should be patched to match FreeBSD > > native behaviour instead. > > > > Why does Linux allow everyone to see CWD for all processes? Does that include a path that I should not even be able to see via file system protections? If so I would classify that as a data xfiltration security concern. > > > > > > > > > > Linux's own /proc filesystem never hides the CWD (lrwxrwxrwx), and only > > > hides file descriptors for processes you don't own. > > > > > > A patch along the following lines could be a start: > > > > > > diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c > > > index 423968b2e1cc..f487232d2cff 100644 > > > --- a/sys/kern/kern_descrip.c > > > +++ b/sys/kern/kern_descrip.c > > > @@ -3692,7 +3692,7 @@ sysctl_kern_proc_filedesc(SYSCTL_HANDLER_ARGS) > > > > > > sbuf_new_for_sysctl(&sb, NULL, FILEDESC_SBUF_SIZE, req); > > > sbuf_clear_flags(&sb, SBUF_INCLUDENUL); > > > - error = pget((pid_t)name[0], PGET_CANDEBUG | PGET_NOTWEXIT, &p); > > > + error = pget((pid_t)name[0], PGET_CANSEE | PGET_NOTWEXIT, &p); > > > if (error != 0) { > > > sbuf_delete(&sb); > > > return (error); > > > @@ -3768,7 +3768,7 @@ sysctl_kern_proc_ofiledesc(SYSCTL_HANDLER_ARGS) > > > struct proc *p; > > > > > > name = (int *)arg1; > > > - error = pget((pid_t)name[0], PGET_CANDEBUG | PGET_NOTWEXIT, &p); > > > + error = pget((pid_t)name[0], PGET_CANSEE | PGET_NOTWEXIT, &p); > > > if (error != 0) > > > return (error); > > > fdp = fdhold(p); > > > > > > > > > > > > > > > Thank you > > > Damjan > > > _______________________________________________ > > > freebsd-hackers@freebsd.org mailing list > > > https://lists.freebsd.org/mailman/listinfo/freebsd-hackers > > > To unsubscribe, send any mail to " > > freebsd-hackers-unsubscribe@freebsd.org" > > > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" > -- Rod Grimes rgrimes@freebsd.org