From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#45198: 28.0.50; Sandbox mode Date: Fri, 17 Sep 2021 14:13:48 +0200 Message-ID: References: Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.21\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_75BBA58D-B918-40D7-B1FE-10C494228A76" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7814"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Alan Third , 45198@debbugs.gnu.org, Stefan Kangas , =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= , Stefan Monnier To: Philipp Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 17 14:19:26 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mRCpy-0001oi-1D for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 17 Sep 2021 14:19:26 +0200 Original-Received: from localhost ([::1]:50218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRCpx-0004ib-0h for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 17 Sep 2021 08:19:25 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37142) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRCkk-0007kt-HN for bug-gnu-emacs@gnu.org; Fri, 17 Sep 2021 08:14:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47141) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mRCkk-0002tU-9m for bug-gnu-emacs@gnu.org; Fri, 17 Sep 2021 08:14:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mRCkk-0001Oz-3J for bug-gnu-emacs@gnu.org; Fri, 17 Sep 2021 08:14:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 17 Sep 2021 12:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45198 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 45198-submit@debbugs.gnu.org id=B45198.16318808405373 (code B ref 45198); Fri, 17 Sep 2021 12:14:02 +0000 Original-Received: (at 45198) by debbugs.gnu.org; 17 Sep 2021 12:14:00 +0000 Original-Received: from localhost ([127.0.0.1]:58687 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mRCkh-0001Oa-QE for submit@debbugs.gnu.org; Fri, 17 Sep 2021 08:14:00 -0400 Original-Received: from mail18c50.megamailservers.eu ([91.136.10.28]:40944) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mRCkc-0001OM-2m for 45198@debbugs.gnu.org; Fri, 17 Sep 2021 08:13:58 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1631880831; bh=zdOhtTAeZaVdWo1v/MJiaZgMz9u8APKlXKfO9uFY/vc=; h=From:Subject:Date:Cc:To:From; b=T5y+qW+A/AdccwImx9+NXTVr6TzwBz/+dDxApLHYRv1nsdetA3mTzSpAV9hpwppVc 1PlFv/tMMugd+zRpirkwXQ/CJSYo2IpPubfk6fh+ezZdfedjMe8irsv4X9nfqZaPx/ Gd3U96MVm5hUcMdQTU/ysDBi9xeh69W2EZy+ZIuA= Feedback-ID: mattiase@acm.or Original-Received: from [192.168.0.4] (c188-150-171-71.bredband.tele2.se [188.150.171.71]) (authenticated bits=0) by mail18c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 18HCDmuw001024; Fri, 17 Sep 2021 12:13:50 +0000 X-Mailer: Apple Mail (2.3445.104.21) X-CTCH-RefID: str=0001.0A742F1A.6144867F.0062, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.4 cv=etO8cqlX c=1 sm=1 tr=0 ts=6144867f a=SF+I6pRkHZhrawxbOkkvaA==:117 a=SF+I6pRkHZhrawxbOkkvaA==:17 a=M51BFTxLslgA:10 a=_WudpDD8Swmy5rFBtbIA:9 a=CjuIK1q_8ugA:10 a=2YU-EQram26tckInahMA:9 a=B2y7HmGcmWMA:10 a=tclcd6dtLQvEqt9_mmAA:9 X-Origin-Country: SE X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:214534 Archived-At: --Apple-Mail=_75BBA58D-B918-40D7-B1FE-10C494228A76 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii So far the discussion has been focussed on platform-dependent low-level = sandbox implementation. I took a stab at writing something that can be = used by portable code. It's basically versions of `call-process` and `make-process` specialised = for running batch-mode Emacs in a sandbox. The attached patch is a straw = man proposal but that should serve as a starting point for agreement on = what the interface might look like. It's only been "tested" on macOS, and there will of course be ERT tests = as well before it's ready. Everything can be changed. The idea is to have something that could be used from alpa-admin.el or = similar, and for running background Elisp byte-compilation. It uses `make-process` rather than the simpler `start-process` for = running an asynchronous Emacs because the former seemed to give greater = control. There is currently only one sandbox parameter: the list of = directories to make available for reading. Maybe there should be a list = of writable directories as well? We could also consider higher-level primitives, for example something = that takes a Lisp expression to evaluate and returns the Lisp result, = taking care of the intermediate printing and reading. --Apple-Mail=_75BBA58D-B918-40D7-B1FE-10C494228A76 Content-Disposition: attachment; filename=0001-platform-independent-sandbox-interface.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-platform-independent-sandbox-interface.patch" Content-Transfer-Encoding: quoted-printable =46rom=201dfea4588286ec4177619bd5d20502803a98c4c0=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Fri,=2017=20Sep=202021=2009:30:53=20+0200=0A= Subject:=20[PATCH]=20platform-independent=20sandbox=20interface=0A=0A---=0A= =20lisp/sandbox.el=20|=2077=20= +++++++++++++++++++++++++++++++++++++++++++++++++=0A=201=20file=20= changed,=2077=20insertions(+)=0A=20create=20mode=20100644=20= lisp/sandbox.el=0A=0Adiff=20--git=20a/lisp/sandbox.el=20= b/lisp/sandbox.el=0Anew=20file=20mode=20100644=0Aindex=20= 0000000000..a8069d59c7=0A---=20/dev/null=0A+++=20b/lisp/sandbox.el=0A@@=20= -0,0=20+1,77=20@@=0A+;;;=20-*-=20lexical-binding:=20t=20-*-=0A+=0A= +(defconst=20sandbox-mechanism=0A+=20=20;;=20FIXME:=20make=20it=20a=20= defcustom?=20What=20about=20other=20systems?=0A+=20=20(cond=20((eq=20= system-type=20'darwin)=20'darwin)=0A+=20=20=20=20=20=20=20=20((eq=20= system-type=20'gnu/linux)=20'bwrap)))=0A+=0A+(defun=20= sandbox-available-p=20()=0A+=20=20"Non-nil=20if=20a=20sandboxing=20= mechanism=20is=20available."=0A+=20=20;;=20FIXME:=20We=20should=20check=20= for=20availability=20of=20bwrap=20etc.=0A+=20=20(not=20(null=20= sandbox-mechanism)))=0A+=0A+(defun=20sandbox--program-args=20= (sandbox-spec=20prog)=0A+=20=20"Return=20(PROGRAM=20.=20ARGS)=20for=20= running=20PROG=20according=20to=20SANDBOX-SPEC."=0A+=20=20(let=20= ((allow-read-dirs=20(plist-get=20sandbox-spec=20:allow-read-dirs)))=0A+=20= =20=20=20;;=20FIXME:=20Would=20`:allow-write-dirs'=20make=20sense=20and=20= be=20useful?=0A+=20=20=20=20(pcase-exhaustive=20sandbox-mechanism=0A+=20=20= =20=20=20=20('darwin=0A+=20=20=20=20=20=20=20(list=20prog=20"--eval"=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20(prin1-to-string=20= `(darwin-sandbox-enter=20',allow-read-dirs))))=0A+=20=20=20=20=20=20= ('bwrap=0A+=20=20=20=20=20=20=20;;=20FIXME:=20with=20seccomp?=0A+=20=20=20= =20=20=20=20`("bwrap"=0A+=20=20=20=20=20=20=20=20=20"--unshare-all"=0A+=20= =20=20=20=20=20=20=20=20"--dev"=20"/dev"=0A+=20=20=20=20=20=20=20=20=20= "--proc"=20"/proc"=0A+=20=20=20=20=20=20=20=20=20"--tmpfs"=20"/tmp"=0A+=20= =20=20=20=20=20=20=20=20,@(mapcan=20(lambda=20(dir)=20(let=20((d=20= (expand-file-name=20dir)))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(list=20= "--ro-bind"=20d=20d)))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20allow-read-dirs)=0A+=20=20=20=20=20=20=20=20=20,prog)))))=0A+=0A= +(defun=20sandbox--emacs-command=20(sandbox-spec=20args)=0A+=20=20(let*=20= ((emacs=20(expand-file-name=20invocation-name=20invocation-directory))=0A= +=20=20=20=20=20=20=20=20=20(program-args=20(sandbox--program-args=20= sandbox-spec=20emacs)))=0A+=20=20=20=20`(,@program-args=20"--batch"=20= ,@args)))=0A+=0A+(defun=20sandbox-run-emacs=20(sandbox-spec=20= destination=20args)=0A+=20=20"Run=20sandboxed=20Emacs=20in=20batch=20= mode,=20synchronously.=0A+SANDBOX-SPEC=20is=20a=20sandbox=20= specification=20plist.=20=20Currently=20defined=20key:=0A+=20= `:allow-read-dirs'=20--=20the=20value=20is=20a=20list=20of=20directories=20= that=20can=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20be=20read=20from=20(but=20not=20written=20to).=0A+DESTINATION=20= is=20as=20in=20`call-process'.=0A+ARGS=20is=20a=20list=20of=20= command-line=20arguments=20passed=20to=20the=20sandboxed=20Emacs.=0A= +Return=20value=20is=20as=20in=20`call-process'.=0A+=0A+Depending=20on=20= the=20platform,=20the=20sandbox=20restrictions=20do=20not=20necessarily=0A= +take=20effect=20until=20Emacs=20has=20been=20initialised=20and=20loaded=20= the=20site=20and=20user=0A+init=20files.=20=20If=20that=20is=20not=20= desirable,=20suppress=20their=20use=20by=20adding=20the=0A+corresponding=20= flags=20(eg=20\"-Q\")=20to=20ARGS."=0A+=20=20(let=20((command=20= (sandbox--emacs-command=20sandbox-spec=20args)))=0A+=20=20=20=20(apply=20= #'call-process=20(car=20command)=20nil=20destination=20nil=20(cdr=20= command))))=0A+=0A+(defun=20sandbox-start-emacs=20(sandbox-spec=20params=20= args)=0A+=20=20"Run=20sandboxed=20Emacs=20in=20batch=20mode,=20= asynchronously.=0A+SANDBOX-SPEC=20is=20a=20sandbox=20specification=20= plist.=20=20Currently=20defined=20key:=0A+=20`:allow-read-dirs'=20--=20= the=20value=20is=20a=20list=20of=20directories=20that=20can=0A+=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20be=20read=20= from=20(but=20not=20written=20to).=0A+ARGS=20is=20a=20list=20of=20= command-line=20arguments=20passed=20to=20the=20sandboxed=20Emacs.=0A= +PARAMS=20is=20a=20plist=20of=20parameters=20passed=20to=20= `make-process'.=20=20Do=20not=0A+=20=20supply=20`:command';=20it=20will=20= be=20overridden=20by=20ARGS.=0A+Return=20value=20is=20as=20in=20= `make-process'.=0A+=0A+Depending=20on=20the=20platform,=20the=20sandbox=20= restrictions=20do=20not=20necessarily=0A+take=20effect=20until=20Emacs=20= has=20been=20initialised=20and=20loaded=20the=20site=20and=20user=0A= +init=20files.=20=20If=20that=20is=20not=20desirable,=20suppress=20their=20= use=20by=20adding=20the=0A+corresponding=20flags=20(eg=20\"-Q\")=20to=20= ARGS."=0A+=20=20(let*=20((command=20(sandbox--emacs-command=20= sandbox-spec=20args))=0A+=20=20=20=20=20=20=20=20=20(params=20= (copy-sequence=20params))=0A+=20=20=20=20=20=20=20=20=20(params=20= (plist-put=20params=20:command=20command)))=0A+=20=20=20=20(unless=20= (plist-member=20params=20:name)=0A+=20=20=20=20=20=20(setq=20params=20= (plist-put=20params=20:name=20"emacs")))=0A+=20=20=20=20(unless=20= (plist-member=20params=20:connection-type)=0A+=20=20=20=20=20=20(setq=20= params=20(plist-put=20params=20:connection-type=20'pipe)))=0A+=20=20=20=20= (apply=20#'make-process=20params)))=0A+=0A+(provide=20'sandbox)=0A--=20=0A= 2.21.1=20(Apple=20Git-122.3)=0A=0A= --Apple-Mail=_75BBA58D-B918-40D7-B1FE-10C494228A76 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail=_75BBA58D-B918-40D7-B1FE-10C494228A76--