iotjs icon indicating copy to clipboard operation
iotjs copied to clipboard

JavaScript callbacks in iotjs (security issue)

Open zherczeg opened this issue 11 years ago • 5 comments

Currently there are no input validations and error checks in the current code. As a result, JS calls like

process.binding("fg");

cause a segmentation fault in release (or an attacker could redirect control). The current coding style is quite Duktape like, where error handling is automatically done, but in JerryScript, all return values must be explicitly checked and actions need to be done according to the result.

zherczeg avatar Aug 25 '15 13:08 zherczeg

@zherczeg Right. Currently, native side of IoT.js checks invariants by using IOTJS_ASSERT macro that abort in debug mode but do nothing on release mode resulting segmentation fault in some cases.

I think it should throw an Error where IOTJS_ASSERT fails in release mode that it can be treated in exception handler or devise other mechanism. For debug mode I think aborting would be best option so that we can check what was wrong for IOTJS_ASSERT should be used where something must be in expected value.

For example process.binding() is not an exposed API rather it is used internally so it is expected that the arguments of the method should be ID for a builtin module and aborting in debug when unexpected value comes help us find the problem. Surely user application could also call the method in unexpected way but I think we don't need to give a guarantee graceful exception handling for that kind of miss using of API, but we must prevent segmentation fault in release mode.

ILyoan avatar Aug 27 '15 01:08 ILyoan

We definitely need to do something with this, since intentional misusing of the API can allow taking over the control of the device by a cracker.

zherczeg avatar Sep 01 '15 09:09 zherczeg

@zherczeg Agree with you.

Let me summarize what we have to count:

  • We are checking whether arguments are in expected range using IOTJS_ASSERT().
  • IOTJS_ASSERT() aborts if given predicate evaluates false in debug mode but do nothing on release mode that might lead security vulnerability.
  • I see the problem can be mainly caused by hijacking builtin module for purpose of abusing it. There are no way to prevent such hijacking.
  • In case of user had no intention to abuse buitin, just misusing API. Javascript module implementation must check arguments before passing it to builtin.
  • I thought that we can throw an 'Error' back to Javascript in release mode. But not all place where IOTJS_ASSERT() locates are able to throw Error object to Javascript engine.
  • I think we don't need to guarantee graceful exception handling even if it is caused by abusing builtin.
  • Just exiting program in release mode for that situation is also considerable.

What do you think?

ILyoan avatar Sep 02 '15 03:09 ILyoan

@zherczeg On second thought, one of the problem is that, checking parameter's types and range in builtin native handler is done with IOTJS_ASSERT() which do nothing on release mode. We may introduce another policy for it like checking parameter on native module and throwing exception if it there are unexpected value given.

ILyoan avatar Sep 03 '15 01:09 ILyoan

I belive this issue is fixed by 29af2f4ba49e549459fa1df58b47e6337e477cc3 Feel free to reopen if needed.

Closing.

ILyoan avatar Sep 14 '15 05:09 ILyoan