From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.devel Subject: Re: emacs-29 3c1693d08b0: Fix Elisp code injection vulnerability in emacsclient-mail.desktop Date: Wed, 08 Mar 2023 11:37:06 +0100 Message-ID: <87ilfbpm0d.fsf@gmail.com> References: <167821009581.14664.5608674978571454819@vcs2.savannah.gnu.org> <20230307172816.2D56BC13915@vcs2.savannah.gnu.org> <877cvsozn5.fsf@yahoo.com> <87zg8onfob.fsf@yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33069"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Po Lu , emacs-devel@gnu.org To: Ulrich Mueller Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Mar 08 11:37:56 2023 Return-path: Envelope-to: ged-emacs-devel@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 1pZrBE-0008P5-F5 for ged-emacs-devel@m.gmane-mx.org; Wed, 08 Mar 2023 11:37:56 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pZrAW-0004Xp-Iw; Wed, 08 Mar 2023 05:37:12 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pZrAV-0004Xg-Ng for emacs-devel@gnu.org; Wed, 08 Mar 2023 05:37:11 -0500 Original-Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pZrAT-0006dz-VD for emacs-devel@gnu.org; Wed, 08 Mar 2023 05:37:11 -0500 Original-Received: by mail-wm1-x332.google.com with SMTP id ay29-20020a05600c1e1d00b003e9f4c2b623so929250wmb.3 for ; Wed, 08 Mar 2023 02:37:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678271828; h=content-transfer-encoding:mime-version:message-id:date :gmane-reply-to-list:references:in-reply-to:subject:cc:to:from:from :to:cc:subject:date:message-id:reply-to; bh=ZeAkVqiY7zEbUEHkf5WKo3lrvHG9Ag0PmUCbIGvpxdQ=; b=CmwVQmiTtFFZXigzx1WtLcz3XpuT7qbl99vhdvsEm6aFtg9IrFOjNhFaIakUPQ3Cmt Gu7YBsk8vZC+WzGt4FIWwwF4sFf1Kli9noOYNo8w6TMlZjHuvHC0LqQg0z9hqUoWDs8x sKfhrGub8QGSTAAYFf+8HrXqQe7fi44h61pGeurclJRADv48q+ZF5LWM1Ixx83x94riL RqRg5iEScE5+EfReEql07WUbZvYWpYuCTClXt1GiJvrBt1LtS7F1iGQZ5atH320o+dv0 WlIHCyyNXU/9neLIlEDBYVE1kQ9DdtdIuwIIHkA7/DMxXkhSD7N8rgeQY2+xqshRvPlP M20Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678271828; h=content-transfer-encoding:mime-version:message-id:date :gmane-reply-to-list:references:in-reply-to:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZeAkVqiY7zEbUEHkf5WKo3lrvHG9Ag0PmUCbIGvpxdQ=; b=SdPqMcqB4EbTTBBPWD7RvPIJzaLJfKf+v2dBg3x0leFB7whELaK4kcFFjN0obTvUGB DQAL1KlZLjnlwJE2O0eAufqBBi2ugcXClda1mpjcak5J+xLo3pIexCUzvaHDftGPKEQC hopjnDtEGPvNk6DafvXiGAsjvT7eZX8nnyikfQhUgheFFgNJwZg7kOXt1HarWQaQjZ4s imKqNnRD9RSHvLHq21cfBehbVavNIDlJmoHeec2KRuyqPkWrQdtNDrk6+tRuOiZyyvjc h30tr5C7UUrcOvQ5kFkvTazz4uG1Zr9sNosb12mh6snyrbw03TWppKwZcOysGiW50DWm twmA== X-Gm-Message-State: AO0yUKUeBYY2aJ8Eubzdg6u529s0HEifbn2qXI9dI8OOMWFiW4yFCQrF NIi2qDjcTFZGevRwbpm5ZWU57fBKVFw= X-Google-Smtp-Source: AK7set++61c0+NMU4jGcArHVBvBow/C7+wkSlBwtnoH4uZ6itcq9mtF2CBssfnBmey2ovd1CXgQWDg== X-Received: by 2002:a05:600c:3b11:b0:3df:fbc7:5b10 with SMTP id m17-20020a05600c3b1100b003dffbc75b10mr15418904wms.0.1678271827959; Wed, 08 Mar 2023 02:37:07 -0800 (PST) Original-Received: from rltb ([82.66.8.55]) by smtp.gmail.com with ESMTPSA id h6-20020a1ccc06000000b003e118684d56sm19826585wmb.45.2023.03.08.02.37.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Mar 2023 02:37:07 -0800 (PST) In-Reply-To: (Ulrich Mueller's message of "Wed, 08 Mar 2023 08:15:48 +0100") Gmane-Reply-To-List: yes Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=rpluim@gmail.com; helo=mail-wm1-x332.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:304115 Archived-At: >>>>> On Wed, 08 Mar 2023 08:15:48 +0100, Ulrich Mueller s= aid: >>>>> On Wed, 08 Mar 2023, Po Lu wrote: >> Ulrich Mueller writes: >>> Then the desktop file won't work, obviously. The problem is that >>> ${PARAMETER//PATTERN/STRING} substitution is not available in POSIX >>> parameter expansion. So with POSIX sh, an external program (e.g. se= d) >>> would have to be called. >>>=20 >>> The long term solution (suggested by Stefan Monnier) might be to add >>> a --funcall option to emacsclient. Then there would be no need for a >>> shell wrapper, in the first place. >>>=20 >>> Should the Makefile skip installation of emacsclient-mail.desktop >>> when bash isn't available on the system? Then you=CA=BCd require every distro builder to have bash available in their build setup >> Could we install this change not on emacs-29, but on master? >> I don't think the problem it solves is severe, nor a regression from >> Emacs 28. It is rather a minor nusiance with certain URLs. Ulrich> Seriously? It is a vulnerability that allows remote injection of Ulrich> arbitrary Elisp code through a crafted "mailto" URI. It=CA=BCs certainly not a regression, but it is fairly serious. We could mitigate it somewhat by adding '--funcall', I guess. The last time --funcall was discussed, there was no consensus on how arguments should be handled, so I=CA=BCve just gone ahead and implemented one variant. We could add any restrictions we like on the server side, it currently just disallows direct `eval' Not for emacs-29, I think. Robert --=20 diff --git c/lib-src/emacsclient.c i/lib-src/emacsclient.c index 698bf9b50ae..d408af6658f 100644 --- c/lib-src/emacsclient.c +++ i/lib-src/emacsclient.c @@ -113,6 +113,9 @@ #define DEFAULT_TIMEOUT (30) /* True means don't print values returned from emacs. --suppress-output. = */ static bool suppress_output; =20 +/* True means arg is a function to be called. --funcall. */ +static bool funcall; + /* True means args are expressions to be evaluated. --eval. */ static bool eval; =20 @@ -168,6 +171,7 @@ #define DEFAULT_TIMEOUT (30) { "no-wait", no_argument, NULL, 'n' }, { "quiet", no_argument, NULL, 'q' }, { "suppress-output", no_argument, NULL, 'u' }, + { "funcall", no_argument, NULL, 'l' }, { "eval", no_argument, NULL, 'e' }, { "help", no_argument, NULL, 'H' }, { "version", no_argument, NULL, 'V' }, @@ -191,7 +195,7 @@ #define DEFAULT_TIMEOUT (30) /* Short options, in the same order as the corresponding long options. There is no '-p' short option. */ static char const shortopts[] =3D - "nqueHVtca:F:w:" + "nquleHVtca:F:w:" #ifdef SOCKETS_IN_FILE_SYSTEM "s:" #endif @@ -548,6 +552,10 @@ decode_options (int argc, char **argv) } break; =20 + case 'l': + funcall =3D true; + break; + case 'e': eval =3D true; break; @@ -689,6 +697,7 @@ print_help_and_exit (void) ", "\ -F ALIST, --frame-parameters=3DALIST\n\ Set the parameters of a new frame\n\ +-l, --funcall Evaluate the FILE argument as function to call\n\ -e, --eval Evaluate the FILE arguments as ELisp expressions\n\ -n, --no-wait Don't wait for the server to return\n\ -w, --timeout=3DSECONDS Seconds to wait before timing out\n\ @@ -2067,11 +2076,28 @@ main (int argc, char **argv) if (create_frame && !tty) send_to_emacs (emacs_socket, "-window-system "); =20 + bool funcall_sent =3D false; + if (optind < argc) { for (int i =3D optind; i < argc; i++) { =20 + if (funcall) + { + /* funcall applies the function to all subsequent + arguments, unlike eval, which evaluates each + expression individually. */ + if (!funcall_sent) + { + send_to_emacs (emacs_socket, "-funcall "); + funcall_sent =3D true; + } + quote_argument (emacs_socket, argv[i]); + send_to_emacs (emacs_socket, " "); + continue; + } + if (eval) { /* Don't prepend cwd or anything like that. */ @@ -2139,7 +2165,7 @@ main (int argc, char **argv) send_to_emacs (emacs_socket, "\n"); =20 /* Wait for an answer. */ - if (!eval && !tty && !nowait && !quiet && 0 <=3D process_grouping ()) + if (!funcall && !eval && !tty && !nowait && !quiet && 0 <=3D process_gro= uping ()) { printf ("Waiting for Emacs..."); skiplf =3D false; diff --git c/lisp/server.el i/lisp/server.el index eaf24a770e4..e5ea2b14b3b 100644 --- c/lisp/server.el +++ i/lisp/server.el @@ -1295,6 +1295,29 @@ server-process-filter proc)) (setq filepos nil)) =20 + ;; -funcall FUNCTION: Call the function, and pass it any = subsequent command line args + ("-funcall" + (if use-current-frame + (setq use-current-frame 'always)) + (let ((fun (pop args-left)) + args real-fun) + (if coding-system + (setq fun (decode-coding-string fun coding-system))) + (when fun + (setq real-fun (intern-soft fun)) + (when (and (fboundp real-fun) + (not (eq real-fun 'eval))) + (setq args (mapcar + (lambda (a) + (if coding-system + (setq a (decode-coding-string a c= oding-system))) + a) + args-left)) + (setq args-left nil) + (push (lambda () (apply real-fun args)) + commands)))) + (setq filepos nil)) + ;; -eval EXPR: Evaluate a Lisp expression. ("-eval" (if use-current-frame