Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 May 2020 20:32:08 +0200
From:      Damjan Jovanovic <damjan.jov@gmail.com>
To:        Hackers freeBSD <freebsd-hackers@freebsd.org>
Subject:   Allow procstat to view current working directory? [xfce4-terminal, linprocfs, ...]
Message-ID:  <CAJm2B-=ja7u30xhVbT_8EX96ieBm%2BkqfTaT=1qfBD2B%2BZ9cCWg@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
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.

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJm2B-=ja7u30xhVbT_8EX96ieBm%2BkqfTaT=1qfBD2B%2BZ9cCWg>