Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 May 2020 00:46:11 +0300
From:      Konstantin Belousov <kib@freebsd.org>
To:        Damjan Jovanovic <damjan.jov@gmail.com>
Cc:        Hackers freeBSD <freebsd-hackers@freebsd.org>
Subject:   Re: Allow procstat to view current working directory? [xfce4-terminal, linprocfs, ...]
Message-ID:  <20200506214611.GD3866@kib.kiev.ua>
In-Reply-To: <CAJm2B-=ja7u30xhVbT_8EX96ieBm%2BkqfTaT=1qfBD2B%2BZ9cCWg@mail.gmail.com>
References:  <CAJm2B-=ja7u30xhVbT_8EX96ieBm%2BkqfTaT=1qfBD2B%2BZ9cCWg@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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/<pid>/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"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20200506214611.GD3866>