Commit Graph

527 Commits

Author SHA1 Message Date
Kartik K. Agaram 618b49fbf3 use markdown syntax for images
Now they render right on non-Github forges.
2023-11-26 18:06:52 -08:00
Kartik K. Agaram e5b5a82970 a sharp edge in Lua's dorequire()
You can't call it on a file that isn't a module, i.e. that doesn't
return something at the end. Use dofile() instead.
2022-04-11 23:32:56 -07:00
Kartik K. Agaram 98e657d6e2 actually _use_ the ask permission 2022-04-07 09:19:55 -07:00
Kartik K. Agaram dad78ac424 new perm: files under dir specified at commandline
I think we can now use a file browser app with relative safety. Just
give it inargs permissions, and provide a top-level directory at the
commandline to gain access to everything under it.
2022-04-05 22:49:43 -07:00
Kartik K. Agaram 9d81974a31 new permission: any file specified at commandline 2022-04-05 22:39:17 -07:00
Kartik K. Agaram 6099fa7fb2 experiment: ask for permission on file operations
I'm not quite sure how to think about asking for permissions with
respect to my red/orange/green color codes. On the one hand, it seems
safer than many alternatives. On the other hand, it's liable to lead to
fatigue and blindly allowing apps to do stuff. For now I consider ask to
be orange. Ask + network allowed = red in summary, though it's orange on
the permissions screen since there's more space to convey nuance. Then
again, nobody may heed the nuance. The summary up top on the permissions
screen is definitely still a work in progress. And there's a
chicken-and-egg problem here: I can't really get a good feel for
real-world bugs in the permissions screen until _other programmers_ are
building apps to use the permissions screen, but they're almost certain
to have a crappy time of it.

I considered introducing a primitive called ask() in the Lua
interpreter, but it doesn't really make sense to validate it and so on.
I'm also not really supporting mixing Ask with other features so far.

This is a major step towards turning my permissions screen into
spaghetti; monitoring closely.
2022-04-05 22:26:43 -07:00
Kartik K. Agaram 5b64c4b3bc show common suggestions when editing permissions
Computer owners shouldn't get in the habit of trusting app authors
regarding permissions. But they have to trust somebody, and they already
trust the Teliva platform if they are running it.
2022-04-05 20:50:51 -07:00
Kartik K. Agaram 455870d114 reorg 2022-03-20 18:00:42 -07:00
Kartik K. Agaram 9ec94aa982 disallow all relative paths (./ or ../)
Teliva's model doesn't include any way to change directory. We just have
relative paths and absolute paths. Relative paths should not be able to
reach into parent directories.

The current test is a bit hacky; it also disallows directories ending in
a period. Hopefully not an issue.
2022-03-20 17:58:14 -07:00
Kartik K. Agaram 824705f770 fix a warning 2022-03-18 17:49:26 -07:00
Kartik K. Agaram 0374e82aa5 show current definition being edited
This serves two purposes:
- Things get confusing if function being defined doesn't match the
  definition name. Displaying the current definition helps diagnose this
  situation.
- We're already able to see callers at a glance even if the cursor is
  below the fold. The name of the current definition is arguably more
  important in that situation.
2022-03-18 10:39:56 -07:00
Kartik K. Agaram af8d3addd2 stale references to caller 2022-03-18 10:39:56 -07:00
Kartik K. Agaram 4a90a28a15 fake to stand in for start_reading in tests 2022-03-18 09:24:53 -07:00
Kartik K. Agaram 56f1b97b9c sandbox os.remove 2022-03-17 15:38:50 -07:00
Kartik K. Agaram 1d3101507e fix some warnings 2022-03-17 00:15:16 -07:00
Kartik K. Agaram 5380817ce6 function names from globals rather than debug info
This reclaims all the slowdown in sieve.tlv, and it also is now smart
enough to detect calls to global bindings that pass through variables.

On the flip side, we lose names for non-globals. But that's not very
useful anyway in Teliva's context.

This is still not enough to detect callers through coroutines
(intervening anonymous functions), though.
2022-03-16 23:53:08 -07:00
Kartik K. Agaram 76d1dda240 bring back hack when caller is main
Partially undoes commit f2d29c22f8.
2022-03-16 23:45:42 -07:00
Kartik K. Agaram 785dfaa1ec cache function names
This brings down the slowdown in sieve.tlv from 50% to 25% (15s).
2022-03-16 23:45:38 -07:00
Kartik K. Agaram 155f6a8027 standardize some names 2022-03-16 21:48:41 -07:00
Kartik K. Agaram fffcc8b9ab stop running task.scheduler by default
sieve.tlv is 50% slower (18s vs 12s) with the new function call
instrumentation.
2022-03-16 21:38:34 -07:00
Kartik K. Agaram d6554919b1 delete dead code 2022-03-16 21:28:58 -07:00
Kartik K. Agaram ef5195dee9 simplify function call instrumentation
src/ldo.c now has a minimal diff with Lua 5.1.

It might be a bit slower than it was before, but not noticeably so..

This approach doesn't support indirect calls.
2022-03-16 21:19:19 -07:00
Kartik K. Agaram 182408ec54 drop a header 2022-03-16 20:33:28 -07:00
Kartik K. Agaram ed5efcd8a0 drop a forward decl 2022-03-16 20:31:43 -07:00
Kartik K. Agaram 709cc25130 start cleaning up function call instrumentation
It's a mess. I calculate call-graph depth one way and calculate caller
names another way. At least one of the ways fails to work with indirect
calls. Hopefully the other way works?
2022-03-16 20:29:50 -07:00
Kartik K. Agaram b9c187d259 stop using tasks in start_reading/start_writing
We just need queues/streams for file I/O. No need to complect
concurrency concerns with them.
2022-03-16 17:03:38 -07:00
Kartik K. Agaram ab89be1ed3 Teliva's been broken 2 days while I mess with docs 2022-03-15 16:00:08 -07:00
Kartik K. Agaram 5e976554dd drop the lfs library
I can't feel confident about its sandboxing story yet. And if we can't
build a file navigator, what are we even doing with it.
2022-03-14 17:26:13 -07:00
Kartik K. Agaram b68405fe31 delete debug library
There's security issues here, and they're subtle. Dropping for now until
I or someone else finds a need for them.
2022-03-13 17:36:01 -07:00
Kartik K. Agaram ee7f893a7e drop string.dump, clean up docs around it 2022-03-13 14:41:41 -07:00
Kartik K. Agaram 1017e80fe5 less confusing error when apps get past main 2022-03-13 12:12:19 -07:00
Kartik K. Agaram 04a65e05f8 leak check 2022-03-10 09:56:37 -08:00
Kartik K. Agaram 0fa83e1d94 support fixing >1 test failure from within Teliva
This bug was caused by me forgetting that lua_setglobal affects the
stack.
2022-03-10 09:47:10 -08:00
Kartik K. Agaram e627114751 zet.tlv: first screen tests
In the process I found a couple of bugs in fake screen primitives.
2022-03-10 04:30:58 -08:00
Kartik K. Agaram 08c49b5a0a protect framework files from apps
There's a separate open question here of where Teliva should store files
like teliva_editor_state and teliva_editor_buffer. One school of thought
is that apps should never be dropping crud into people's directories. On
the other hand, I'm kinda encouraging people so far to just run apps
from Teliva's directory. Perhaps that makes it ok?
2022-03-08 19:20:53 -08:00
Kartik K. Agaram 2b47f76308 just always temp files to be created
Implication: os.rename now needs to be sandboxed. Hopefully it's
tractable to treat it as conceptually identical to opening two files.
2022-03-07 21:57:11 -08:00
Kartik K. Agaram 2d393bfb80 stop loading libraries after app code
This whole approach of disallowing overriding is suspect.
2022-03-07 21:43:00 -08:00
Kartik K. Agaram dd8730920a purge all support for per-function permissions
We're now back to the problem of how to transparently allow Teliva to
create temporary filenames without every app having to explicitly allow
them.

I think I may need to define start_writing in C, so that it can use a
non-sandboxed version of io.open.
2022-03-07 20:50:41 -08:00
Kartik K. Agaram a0674f7b85 hokey primitive to create temporary file
The trouble with os.tmpname() is that it always creates in /tmp.
If /tmp is in a different volume from our real filename, os.rename()
will fail.

This new primitive doesn't support primitive paths yet.

I'm also again nervous about the security implications of my whole
approach. What if we create an inner function called start_writing?
Would we be able to do anything inside it? I'm starting to suspect this
whole approach of going by caller name is broken. An app could also
create inner functions called 'main'..
2022-03-07 19:14:02 -08:00
Kartik K. Agaram 88827db20d slightly firm up phases in pmain 2022-03-07 16:01:19 -08:00
Kartik K. Agaram f268015ac0 fix the security vulnerability
We now have a notion of libraries that we load after app code, to
prevent them from getting overridden.

Should I just load all libraries after the app? There might be value in
allowing apps to override library functions. Disallowing that too much
may be going against Lua's dynamic nature.
2022-03-07 15:40:28 -08:00
Kartik K. Agaram cfb7cff4c1 call app's main() from within Lua pmain 2022-03-07 15:34:20 -08:00
Kartik K. Agaram 38063812b6 zet.tlv: switch file writes to new API
The interface for apps looks much nicer now, see 'main' in zet.tlv.
However there are some open issues:

- It can still be confusing to the computer owner that an app tries to
  write to some temporary file that isn't mentioned anywhere.

- File renames can fail if /tmp is on a different volume.

- What happens if an app overrides start_writing()? The computer owner
  may think they've audited the caller of start_writing and give it
  blanket file permissions. Teliva tunnels through start_writing when
  computing the caller. If the app can control what start_writing does,
  the app could be performing arbitrary malicious file operations.

  Right now things actually seem perfectly secure. Overriding
  start_writing has no effect. Our approach for loading .tlv files (in
  reverse chronological order, preventing older versions from overriding
  newer ones) has the accidentally _great_ property that Teliva apps can
  never override system definitions.

  So we have a new reason to put standard libraries in a .lua file: if
  we need to prevent apps from overriding it.

  This feels like something that needs an automated test, both to make
  sure I'm running the right experiment and to ensure I don't
  accidentally cause a regression in the future. I can totally imagine a
  future rewrite that tried a different approach than
  reverse-chronological.
2022-03-07 10:55:18 -08:00
Kartik K. Agaram 7a315e3d9f extract a common function call 2022-03-07 08:52:41 -08:00
Kartik K. Agaram 503ad706fb zet.tlv: switch file reads to new API
In the process I found a couple of bugs in parsing JSON string escapes.
2022-03-07 08:22:37 -08:00
Kartik K. Agaram d388cc1f22 decode json from channels 2022-03-06 23:50:58 -08:00
Kartik K. Agaram 6a3098d0e9 use method syntax where possible
Perhaps this is a bad idea. It feels arbitrary, what methods Lua happens
to include in string and table objects without having to go through the
respective modules.
2022-03-06 16:38:49 -08:00
Kartik K. Agaram 5758f6c082 reading from file a character at a time 2022-03-06 09:52:37 -08:00
Kartik K. Agaram f07eb03492 local functions broke start_reading/start_writing
Looks like Lua's local functions lose access to outer scopes (upvalues)
or something like that..
2022-03-06 09:49:33 -08:00
Kartik K. Agaram 38ff2ddf11 move start_reading/start_writing out of template
When should code go in the template used by new apps vs the .lua files
distributed with Teliva?

- from a privilege perspective there's no difference
- from a compatibility perspective stuff in .tlv will not get upgraded
  with Teliva.
- for me the maintainer, functions in .lua files are easier to upgrade
  in a single place.
- for the reader of an app, functions in .lua files will not show up to
  be edited. They can still be overloaded, but the current version isn't
  as discoverable. Putting something in the app is a slight nudge to
  readers that they're encouraged to mess with it.
- Stuff in .lua files can use local functions and so have more internal
  complexity. Apps can also hide details within functions, but that'll
  make them more likely to run into limitations with Teliva's editing
  environment.

I'm not yet sure how to reason about the second point in practice.
  - Stuff in .tlv files I don't have to worry about compatibility
    guarantees for.
  - Stuff in .lua files I _do_ have to worry about compatibility
    guarantees for.

Perhaps this means I'm doing things exactly wrong in this commit?
Functions like map/reduce/filter/append seem more timeless, whereas I'm
still just feeling my way around with start_reading and start_writing.

We'll see. For now I'm ruled by the fourth point. Messing with tasks and
the scheduler is much more advanced than anything else in template.tlv;
it seems to make sense to add some friction to modifying them.

Bottomline: Complex sub-systems go in .lua files. Simple, self-contained
definitions go into apps. Both are probably equally burdensome now from
a compatibility perspective.
2022-03-06 09:21:32 -08:00