From owner-freebsd-hackers@freebsd.org Fri May 8 17:50:09 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 72EAD2DD8D1 for ; Fri, 8 May 2020 17:50:09 +0000 (UTC) (envelope-from damjan.jov@gmail.com) Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49JdC44jF1z46sm; Fri, 8 May 2020 17:50:08 +0000 (UTC) (envelope-from damjan.jov@gmail.com) Received: by mail-io1-xd44.google.com with SMTP id w4so2630069ioc.6; Fri, 08 May 2020 10:50:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NEjosk1I0dEZKSs7TvLZlkwRClKz7uIMARgp1NLXEmE=; b=UufcFRVpoNEht5iBJF1nQekaWSq6fX6D4FVcD+amOpEUf/ujkykLJKPqIupeoTqsQw C4rD26ENpFIUy5pdosFNvod3gryVtlf0JGVgRegi0h5zWgQX+k9NxOscq9x+CO/40e2e 6EmD5Wxpu/sebeUT83TbmdDZckQ8OczAw/3+dGuKF/W08WCfIkvp05OnK/xt/7u0THJY NbDIRpA5TGdLEj3IQ63yis7VqjfbCeLSp7PL4cjj3Yc212SLOCmX3lCd7zarBmFT22/d 2QOEGG/12jLw1nOLgULtfsTzMxyWiDMHTvpBureyhAYOhb5EoPJEiNcLGwa07e5yNICe +IjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NEjosk1I0dEZKSs7TvLZlkwRClKz7uIMARgp1NLXEmE=; b=LsmcMcUPjMXgIVUsBrCwVTd5BedJyX/gKLipNgh5/09OamatXip1gpHxeJAsSYPTl7 Qc7V1kRAKl9Dzk4Ule8DXFWPAya9/Log275RNVWnyINwnze7+pJ/sFDr8clrQ8O55oru rhfV6tBN+gFylfqnvk2n0nivfKyhxqK5FDePhGkWmZfKyOODrwnNWf5FHrw32zos9Hbq pOXNzxkQ3KPnznnnFBPMA2Ma7gBZiCP0Ki8+roDB0iWPCv/nLTxNjAnH7SAnDCM+TSkc V0sgKGBifp8l2akvI1AEGRpdFhwR7oIzVLq5IqKuTRiOrJ+BchbW+wfGPmYiBfs1PP/a 2l9Q== X-Gm-Message-State: AGi0PubcTmpT0bW1xAjzbkYmmAqudhiYmM3WG+QCL9pLBc5cy8w6aPe5 FWnxrFjR17jd751Nx4rZAAgmamk4GQCunNFCs8UdSXCk2Fm8xw== X-Google-Smtp-Source: APiQypKqdEKHVZ5jTd+uZPWtO5/bmC066WEQ1N1ckNG3E4P4wakhzWCxrUovHxHKAXJXysdmGiuha067A/QgBkgwnNI= X-Received: by 2002:a05:6638:614:: with SMTP id g20mr3799553jar.85.1588960207834; Fri, 08 May 2020 10:50:07 -0700 (PDT) MIME-Version: 1.0 References: <202005081737.048Hb2CA053936@gndrsh.dnsmgr.net> In-Reply-To: <202005081737.048Hb2CA053936@gndrsh.dnsmgr.net> From: Damjan Jovanovic Date: Fri, 8 May 2020 19:49:41 +0200 Message-ID: Subject: Re: Allow procstat to view current working directory? [xfce4-terminal, linprocfs, ...] To: "Rodney W. Grimes" Cc: Konstantin Belousov , Hackers freeBSD X-Rspamd-Queue-Id: 49JdC44jF1z46sm X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=UufcFRVp; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of damjanjov@gmail.com designates 2607:f8b0:4864:20::d44 as permitted sender) smtp.mailfrom=damjanjov@gmail.com X-Spamd-Result: default: False [-2.00 / 15.00]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36:c]; FREEMAIL_FROM(0.00)[gmail.com]; URI_COUNT_ODD(1.00)[9]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; FROM_EQ_ENVFROM(0.00)[]; IP_SCORE(0.00)[ip: (0.24), ipnet: 2607:f8b0::/32(-0.33), asn: 15169(-0.43), country: US(-0.05)]; MIME_TRACE(0.00)[0:+,1:+,2:~]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; SUBJECT_HAS_QUESTION(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com.dwl.dnswl.org : 127.0.5.0]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; TAGGED_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; IP_SCORE_FREEMAIL(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[4.4.d.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.32 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:50:09 -0000 On Fri, May 8, 2020 at 7:37 PM Rodney W. Grimes < freebsd-rwg@gndrsh.dnsmgr.net> wrote: > > 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. > You're right, on Linux the symlink /proc/1/cwd is there, but the link target is invisible, and "stat cwd" gives: File: 'cwd'stat: cannot read symbolic link 'cwd': Permission denied Size: 0 Blocks: 0 IO Block: 1024 symbolic link Device: 4h/4d Inode: 24821 Links: 1 Access: (0777/lrwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2020-05-08 18:10:45.485582443 +0200 Modify: 2020-05-08 18:10:45.441582441 +0200 Change: 2020-05-08 18:10:45.441582441 +0200 Birth: - > > > > > > > > > > > > > > > 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 >