From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: adam plaice Newsgroups: gmane.emacs.devel Subject: bug#37656: 27.0.50; Arbitrary code execution with special `mode:' Date: Tue, 15 Oct 2019 23:05:01 +0200 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="96444"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 37656@debbugs.gnu.org To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 15 23:05:42 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iKU0j-000OvT-EX for ged-emacs-devel@m.gmane.org; Tue, 15 Oct 2019 23:05:41 +0200 Original-Received: from localhost ([::1]:59456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKU0i-0000bE-1y for ged-emacs-devel@m.gmane.org; Tue, 15 Oct 2019 17:05:40 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56073) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKU0R-0000Zw-W4 for emacs-devel@gnu.org; Tue, 15 Oct 2019 17:05:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKU0Q-0004oO-3A for emacs-devel@gnu.org; Tue, 15 Oct 2019 17:05:23 -0400 Original-Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]:37140) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iKU0P-0004n8-Oh for emacs-devel@gnu.org; Tue, 15 Oct 2019 17:05:22 -0400 Original-Received: by mail-lj1-x231.google.com with SMTP id l21so21753746lje.4 for ; Tue, 15 Oct 2019 14:05:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=IIgqrbq4gITi0Wy/qtpu1BXDUG4Kuyu8m2IKhgb91cY=; b=euc9kLw+y3HL/KSa/GmZth6vJInozdn9yJuhK7mN1TkJy8A9eQWzL6QH/flGwIhEf5 bSC8ccw+UY2wpQdDgeBgFKey6grv0a0Wb7y3Ft0y6c/qc635w+XBUIwRPlgC7XzlEKjD /ciHKefMCF6S0yLzB5ztOMSnBZhNPlRf76jaKxoDGphbsK1FDj9Odisfp+4tlZiVof7f Hj0sSdVBPOvi5bqqQV0pKoILXEO0JlnRPMVi3zFpEwXsjbknaLPGFh6eIWMAm7z2LVKw 6j/zSeWKhdv1w/6K8mC5dphpI0ttARsjC2VRl/5Y8vXDnzd0ljG47dRdxgJhiyEt0BCt VKpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=IIgqrbq4gITi0Wy/qtpu1BXDUG4Kuyu8m2IKhgb91cY=; b=nGDR6FjlL2cMBTmkQVpY3vlNy5DIeMNfGQSUztm7aM+ErPjTRfJbb7nj3LNedqz2I/ MqSie2NOmd85+yx61eeCyTBj2C+IY4pKuMqwO0eHKbhvV+Y6i2JWG23M1PFZOju08aIL roU2dGQQ4dJLqqse9mFhOoq+bjy/l5LNKC5sC7RFPT4a/InnaevabDVJ8+TgjbZh52xi jLvY0Ee4e2wryP58iktPyIqxflTnK8L41MJ/g3XKpQKAzLhcfw20EeyylJ7yfZRxaFB5 vbnaQpDCYg+W5AEOG/J3dFewikHosZDo0aewAUPBiVansWD9pmwBnGd4rLcqLQIcmIj4 Y9FQ== X-Gm-Message-State: APjAAAV/aXIGdrX2GmRa6fSL3e6lnEJINXedp7jqeiBK9TFXNZRstg3U 3waH7dBeIvIBXODH6uzNf3hDGS7Kgvzlj8yUgR0NOA== X-Google-Smtp-Source: APXvYqzHtAwMHennez4RYHebuF+Plo0Lyv7NBLcVF4Rb6HVi7m2aACxFjNd7f9Bzr+WcaLnamuheEnAA7vZVihlcn60= X-Received: by 2002:a2e:7e0f:: with SMTP id z15mr21890324ljc.55.1571173512618; Tue, 15 Oct 2019 14:05:12 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::231 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:241065 Archived-At: Since the bug allows an attacker to execute arbitrary code if the victim opens a payload file, and hence opening any file from an untrusted source becomes dangerous, it seems to be rather serious. The bug relies on the fact that flymake-mode can execute arbitrary code, that minor modes (in particular, flymake-mode) can be set with local variables (with `mode:') and that when a minor-mode is set in this way, the major-mode is not unset. (See the linked bug or below for details.) I'm not sure whether I should be bringing greater attention to it, but given that it's already in the open, and malicious actors can find it (or just come up with it themselves, as it's not a particularly complex idea), increasing the likelihood of getting it fixed hopefully outweighs the disadvantages. I'd offer to provide a patch, but I'm neither very proficient with Emacs lisp, nor a security expert. I also haven't signed any copyright papers. Some thoughts on potential solutions (from a well-intentioned, but possibly misguided layman): AFAICT the easiest way to prevent this specific bug would be to prevent more than one mode being set by the file and directory local-variables machinery. Perhaps also only allowing major modes to be set with `mode' in local variables (and only allowing minor-modes to be set with `eval', as is already encouraged in the manual), might decrease the "attack surface" for similar such attacks. I'm not sure whether any major modes are "unsafe" (in the way flymake is), but possibly it might make sense to mark major modes as safe, similarly to the way variables are, though that would be a far more extensive change. Thank you, Adam PS Should Emacs have some policies on reporting security issues? I was encouraged (via an earlier e-mail exchange) to post the bug to debbugs, as normal, but it might perhaps be useful if the process (specifically for security vulnerabilities, not bugs in general) were mentioned in the manual. > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=37656 > > * To reproduce: > > 1. Create a file, say `~/foobar', (it could have an arbitrary > extension) with the following contents: > > -*- mode: emacs-lisp; mode: flymake -*- > > (eval-when-compile > (with-temp-file "~/emacs_flymake_security_bug" > (insert "Could have also executed any code."))) > > 2. Open the file with emacs: > > emacs -Q ~/foobar > > 3. Inspect ~/emacs_flymake_security_bug: > > cat ~/emacs_flymake_security_bug > > * Expected result > > ~/emacs_flymake_security_bug does not exist. > > * Actual result > > ~/emacs_flymake_security_bug does exist. > > * Further information > > This relies on the "deprecated" feature of allowing `mode: ' to be > repeated more than once, to also specify minor modes. Just having: > > -*- mode: flymake -*- > > in, say, `~/foobar.el' would not trigger the security bug. There may, > however, be alternative ways of triggering it, that I haven't come up > with. > > > This was "inspired" by a very similar bug (concerning an external > package, editorconfig), described here: > > https://illikainen.dev/blog/2019-10-06-editorconfig > > Thank you and best regards, > Adam > >