all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Avoiding arbitrary code execution with macroexpansion
@ 2018-08-15 21:52 Wilfred Hughes
  2018-08-16 20:52 ` Paul Eggert
  2018-08-20  3:04 ` Richard Stallman
  0 siblings, 2 replies; 5+ messages in thread
From: Wilfred Hughes @ 2018-08-15 21:52 UTC (permalink / raw)
  To: emacs-devel

Hi emacs-devel

Today I realised that macroexpand-all isn't safe to call on arbitrary elisp:

(macroexpand-all '(eval-when-compile (debug)))

Using a macro that calls eval, such as eval-when-compile,
eval-and-compile, c-lang-defconst-eval-immediately (undoubtedly others
too), means anything can happen at macroexpansion time.

Unfortunately, some emacs packages assume this is a safe thing to do.
I used to think so, because macroexpand-all only executes macros that
are loaded (and therefore trusted) in the current Emacs instance.
Macros that eval code break this.

Even elisp-mode.el assumes this:

(let ((fooo (eval-when-compile (progn (debug)))))
  foo ;; <- put point here and M-x completion-at-point
  )

This means that I can get arbitrary code execution by you opening and
calling code completion a maliciously crafted elisp file!

Is this a security bug in Emacs?

In any case, is there a safe way to do macroexpansion? The best I can
think of is this:

(let ((macro-whitelist '(when pcase))
      all-macros
      safe-env)
  (mapatoms
   (lambda (sym)
     (when (macrop sym)
       (push sym all-macros))))
  (mapc
   (lambda (sym)
     (unless (memq sym macro-whitelist)
       (push (cons sym (symbol-function 'ignore))
             safe-env)))
   all-macros)

  (macroexpand-all
   arbitrary-form-here
   safe-env))

Thanks
Wilfred



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-08-22 23:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-15 21:52 Avoiding arbitrary code execution with macroexpansion Wilfred Hughes
2018-08-16 20:52 ` Paul Eggert
2018-08-20  3:04 ` Richard Stallman
2018-08-22  0:15   ` Wilfred Hughes
2018-08-22 23:57     ` Richard Stallman

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.