unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* How much do we care about undefined behavior triggered by invalid bytecode?
@ 2018-05-22 13:31 Philipp Stephani
  2018-05-22 13:42 ` Noam Postavsky
  0 siblings, 1 reply; 10+ messages in thread
From: Philipp Stephani @ 2018-05-22 13:31 UTC (permalink / raw)
  To: Emacs developers

[-- Attachment #1: Type: text/plain, Size: 235 bytes --]

It's pretty easy to find examples of (printed representations of) invalid
bytecode that trigger C-level assertions or undefined behavior ("crashes").
Should these be reported as bugs, or do we assume that any bytecode object
is valid?

[-- Attachment #2: Type: text/html, Size: 271 bytes --]

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

* Re: How much do we care about undefined behavior triggered by invalid bytecode?
  2018-05-22 13:31 How much do we care about undefined behavior triggered by invalid bytecode? Philipp Stephani
@ 2018-05-22 13:42 ` Noam Postavsky
  2018-05-22 14:01   ` Andreas Schwab
  2018-05-22 14:04   ` Philipp Stephani
  0 siblings, 2 replies; 10+ messages in thread
From: Noam Postavsky @ 2018-05-22 13:42 UTC (permalink / raw)
  To: Philipp Stephani; +Cc: Emacs developers

On 22 May 2018 at 09:31, Philipp Stephani <p.stephani2@gmail.com> wrote:
> It's pretty easy to find examples of (printed representations of) invalid
> bytecode that trigger C-level assertions or undefined behavior ("crashes").
> Should these be reported as bugs, or do we assume that any bytecode object
> is valid?

The latter, according to the manual (elisp) Byte-Code Objects:

   You should not try to come up with the elements for a byte-code
function yourself, because if they are inconsistent, Emacs may crash
when you call the function.  Always leave it to the byte compiler to
create these objects; it makes the elements consistent (we hope).



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

* Re: How much do we care about undefined behavior triggered by invalid bytecode?
  2018-05-22 13:42 ` Noam Postavsky
@ 2018-05-22 14:01   ` Andreas Schwab
  2018-05-23  3:28     ` Richard Stallman
  2018-05-22 14:04   ` Philipp Stephani
  1 sibling, 1 reply; 10+ messages in thread
From: Andreas Schwab @ 2018-05-22 14:01 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: Philipp Stephani, Emacs developers

On Mai 22 2018, Noam Postavsky <npostavs@gmail.com> wrote:

> On 22 May 2018 at 09:31, Philipp Stephani <p.stephani2@gmail.com> wrote:
>> It's pretty easy to find examples of (printed representations of) invalid
>> bytecode that trigger C-level assertions or undefined behavior ("crashes").
>> Should these be reported as bugs, or do we assume that any bytecode object
>> is valid?
>
> The latter, according to the manual (elisp) Byte-Code Objects:
>
>    You should not try to come up with the elements for a byte-code
> function yourself, because if they are inconsistent, Emacs may crash
> when you call the function.  Always leave it to the byte compiler to
> create these objects; it makes the elements consistent (we hope).

Nevertheless, IMHO the bytecode interpreter should be made robust where
possible.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



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

* Re: How much do we care about undefined behavior triggered by invalid bytecode?
  2018-05-22 13:42 ` Noam Postavsky
  2018-05-22 14:01   ` Andreas Schwab
@ 2018-05-22 14:04   ` Philipp Stephani
  2018-05-22 14:40     ` Noam Postavsky
  1 sibling, 1 reply; 10+ messages in thread
From: Philipp Stephani @ 2018-05-22 14:04 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: Emacs developers

[-- Attachment #1: Type: text/plain, Size: 973 bytes --]

Noam Postavsky <npostavs@gmail.com> schrieb am Di., 22. Mai 2018 um
15:42 Uhr:

> On 22 May 2018 at 09:31, Philipp Stephani <p.stephani2@gmail.com> wrote:
> > It's pretty easy to find examples of (printed representations of) invalid
> > bytecode that trigger C-level assertions or undefined behavior
> ("crashes").
> > Should these be reported as bugs, or do we assume that any bytecode
> object
> > is valid?
>
> The latter, according to the manual (elisp) Byte-Code Objects:
>
>    You should not try to come up with the elements for a byte-code
> function yourself, because if they are inconsistent, Emacs may crash
> when you call the function.  Always leave it to the byte compiler to
> create these objects; it makes the elements consistent (we hope).
>

That refers only to calling bytecode objects, not to e.g. reading their
printed representation. Would it also apply to reading or other forms of
handling bytecode objects? If so, the documentation should say so.

[-- Attachment #2: Type: text/html, Size: 1370 bytes --]

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

* Re: How much do we care about undefined behavior triggered by invalid bytecode?
  2018-05-22 14:04   ` Philipp Stephani
@ 2018-05-22 14:40     ` Noam Postavsky
  2018-05-22 14:51       ` Paul Eggert
  2018-05-22 17:30       ` Philipp Stephani
  0 siblings, 2 replies; 10+ messages in thread
From: Noam Postavsky @ 2018-05-22 14:40 UTC (permalink / raw)
  To: Philipp Stephani; +Cc: Emacs developers

On 22 May 2018 at 10:04, Philipp Stephani <p.stephani2@gmail.com> wrote:

> That refers only to calling bytecode objects, not to e.g. reading their
> printed representation. Would it also apply to reading or other forms of
> handling bytecode objects? If so, the documentation should say so.

Oh, you meant just reading the object causes a crash? That sounds like a bug.



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

* Re: How much do we care about undefined behavior triggered by invalid bytecode?
  2018-05-22 14:40     ` Noam Postavsky
@ 2018-05-22 14:51       ` Paul Eggert
  2018-05-22 15:37         ` Philipp Stephani
  2018-05-25  0:30         ` Tom Tromey
  2018-05-22 17:30       ` Philipp Stephani
  1 sibling, 2 replies; 10+ messages in thread
From: Paul Eggert @ 2018-05-22 14:51 UTC (permalink / raw)
  To: Noam Postavsky, Philipp Stephani; +Cc: Emacs developers

Noam Postavsky wrote:
> Oh, you meant just reading the object causes a crash?

I doubt he meant that. Surely he meant that if you read and then execute a 
bytecode object, you can easily crash Emacs.

We could fix this problem by verifying that a series of bytecodes cannot make 
Emacs crash, before allowing the bytecodes to be executed. But wouldn't that be 
a reasonably large project?



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

* Re: How much do we care about undefined behavior triggered by invalid bytecode?
  2018-05-22 14:51       ` Paul Eggert
@ 2018-05-22 15:37         ` Philipp Stephani
  2018-05-25  0:30         ` Tom Tromey
  1 sibling, 0 replies; 10+ messages in thread
From: Philipp Stephani @ 2018-05-22 15:37 UTC (permalink / raw)
  To: Paul Eggert; +Cc: Noam Postavsky, Emacs developers

[-- Attachment #1: Type: text/plain, Size: 567 bytes --]

Paul Eggert <eggert@cs.ucla.edu> schrieb am Di., 22. Mai 2018 um 16:51 Uhr:

> Noam Postavsky wrote:
> > Oh, you meant just reading the object causes a crash?
>
> I doubt he meant that. Surely he meant that if you read and then execute a
> bytecode object, you can easily crash Emacs.
>
>
No, I did mean "read." For example, the following triggers an assertion:


emacs -Q -batch -eval '(let ((load-force-doc-strings t)) (read "#[0
\"\"]"))'


./lisp.h:1723: Emacs fatal error: assertion failed: 0 <= idx && idx < ASIZE
(array)
Fatal error 6: Abort trapAbort trap: 6

[-- Attachment #2: Type: text/html, Size: 1167 bytes --]

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

* Re: How much do we care about undefined behavior triggered by invalid bytecode?
  2018-05-22 14:40     ` Noam Postavsky
  2018-05-22 14:51       ` Paul Eggert
@ 2018-05-22 17:30       ` Philipp Stephani
  1 sibling, 0 replies; 10+ messages in thread
From: Philipp Stephani @ 2018-05-22 17:30 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: Emacs developers

[-- Attachment #1: Type: text/plain, Size: 498 bytes --]

Noam Postavsky <npostavs@gmail.com> schrieb am Di., 22. Mai 2018 um
16:40 Uhr:

> On 22 May 2018 at 10:04, Philipp Stephani <p.stephani2@gmail.com> wrote:
>
> > That refers only to calling bytecode objects, not to e.g. reading their
> > printed representation. Would it also apply to reading or other forms of
> > handling bytecode objects? If so, the documentation should say so.
>
> Oh, you meant just reading the object causes a crash? That sounds like a
> bug.
>

OK, I've reported it as such.

[-- Attachment #2: Type: text/html, Size: 866 bytes --]

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

* Re: How much do we care about undefined behavior triggered by invalid bytecode?
  2018-05-22 14:01   ` Andreas Schwab
@ 2018-05-23  3:28     ` Richard Stallman
  0 siblings, 0 replies; 10+ messages in thread
From: Richard Stallman @ 2018-05-23  3:28 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: p.stephani2, npostavs, emacs-devel

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > Nevertheless, IMHO the bytecode interpreter should be made robust where
  > possible.

I think it would be an improvement to do check for nonsensical
bytecode when creating a bytecode object.  As long as it doesn't make
reading a compiled file much slower.


-- 
Dr Richard Stallman
President, Free Software Foundation (https://gnu.org, https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)





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

* Re: How much do we care about undefined behavior triggered by invalid bytecode?
  2018-05-22 14:51       ` Paul Eggert
  2018-05-22 15:37         ` Philipp Stephani
@ 2018-05-25  0:30         ` Tom Tromey
  1 sibling, 0 replies; 10+ messages in thread
From: Tom Tromey @ 2018-05-25  0:30 UTC (permalink / raw)
  To: Paul Eggert; +Cc: Philipp Stephani, Noam Postavsky, Emacs developers

>>>>> "Paul" == Paul Eggert <eggert@cs.ucla.edu> writes:

Paul> We could fix this problem by verifying that a series of bytecodes
Paul> cannot make Emacs crash, before allowing the bytecodes to be
Paul> executed. But wouldn't that be a reasonably large project?

FWIW on my more experiment JIT branch, I have a small bytecode verifier.
I needed it for the JIT, so it only does what I needed there, namely:

* Checking that the bytecode doesn't fall off the end
* Checking that the stack doesn't over- or underflow
* Checking that the stack depth at any given PC is a constant
* Checking that only valid opcodes are used
* Checking that the hash table given to Bswitch has only integer PC
  values and that they are in range

I don't know how hard it would be to extract this from the JIT.  Not too
bad maybe.

The other issue would be when to run it.  Maybe it would work to do it
the first time a bit of bytecode is executed.

Tom



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

end of thread, other threads:[~2018-05-25  0:30 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-22 13:31 How much do we care about undefined behavior triggered by invalid bytecode? Philipp Stephani
2018-05-22 13:42 ` Noam Postavsky
2018-05-22 14:01   ` Andreas Schwab
2018-05-23  3:28     ` Richard Stallman
2018-05-22 14:04   ` Philipp Stephani
2018-05-22 14:40     ` Noam Postavsky
2018-05-22 14:51       ` Paul Eggert
2018-05-22 15:37         ` Philipp Stephani
2018-05-25  0:30         ` Tom Tromey
2018-05-22 17:30       ` Philipp Stephani

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).