From owner-freebsd-hackers@freebsd.org Wed May 6 21:46:27 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 AC05E2E0421 for ; Wed, 6 May 2020 21:46:27 +0000 (UTC) (envelope-from kib@freebsd.org) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 49HVXf5q9jz4DXB for ; Wed, 6 May 2020 21:46:26 +0000 (UTC) (envelope-from kib@freebsd.org) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id 046LkBMH073422 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 7 May 2020 00:46:15 +0300 (EEST) (envelope-from kib@freebsd.org) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 046LkBMH073422 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id 046LkBOm073421; Thu, 7 May 2020 00:46:11 +0300 (EEST) (envelope-from kib@freebsd.org) X-Authentication-Warning: tom.home: kostik set sender to kib@freebsd.org using -f Date: Thu, 7 May 2020 00:46:11 +0300 From: Konstantin Belousov To: Damjan Jovanovic Cc: Hackers freeBSD Subject: Re: Allow procstat to view current working directory? [xfce4-terminal, linprocfs, ...] Message-ID: <20200506214611.GD3866@kib.kiev.ua> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on tom.home X-Rspamd-Queue-Id: 49HVXf5q9jz4DXB X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-1.94 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-0.96)[-0.960,0]; NEURAL_HAM_LONG(-0.98)[-0.983,0]; TAGGED_RCPT(0.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 May 2020 21:46:27 -0000 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 ? My initial reaction was that linprocfs should be patched to match FreeBSD native behaviour instead. > > 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"