Commit Graph

19 Commits

Author SHA1 Message Date
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 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 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 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 520cc09997 include caller in sandboxing messages 2022-03-04 21:25:38 -08:00
Kartik K. Agaram a8dfea1d3c drop io.lines()
I'd already dropped the variant without a filename. But even the variant
with a filename is very easy to use in a way that is confusing to use in
the presence of sandboxing:

* call io.lines()
* Sandboxing saves an error, io.lines() returns nil
* Caller (usually a loop) raises an error.
* We show the error and not the sandboxing failure.
* Worse, there's no way to adjust permissions from within Teliva,
  because we can't ever get to that menu while there's an error.

Best solution I can come up with: encourage a separate step for
translating filename to file handle. That way it's more obvious that we
need to check for errors.
2022-02-02 23:44:25 -08:00
Kartik K. Agaram 8f8a0e5a18 tweak an entry in the audit log 2022-02-02 23:38:45 -08:00
Kartik K. Agaram 90904f344a file permissions: decide based on calling function 2022-02-01 20:59:53 -08:00
Kartik K. Agaram b97291602b instrument some obvious syscalls 2022-01-02 22:36:33 -08:00
Kartik K. Agaram a901203227 start on a view of audit events 2022-01-02 22:13:47 -08:00
Kartik K. Agaram d0111f1839 editable file permissions
Extremely cruddy implementation:
- I'm still unclear on how to represent the advice function:
  - How to handle errors when loading user configuration?
    Currently I refuse to start.
  - Whole function? More errors to handle in header and so on. What if
    the function is renamed?
  - Just body? Needs more structured editing support.
- Lots of duplication, particularly between the permissions in the menu
  and the permissions screen.

I don't know how to show the hostname at the time of connect() or
bind(), so networking is going to remain a boolean for now. It's also
unclear what effective constraints we can impose on what gets discussed
with a specific hostname. Everything outside the computer is out of
one's control.

One trick I learned is for consistently grabbing ASan logs on abort:
It's always safe to redirect stderr with ncurses!
2022-01-02 19:59:30 -08:00
Kartik K. Agaram df5cd41637 rename 2022-01-02 15:46:46 -08:00
Kartik K. Agaram 16d949e259 file open() is now sandboxed
In the process we now also have a mechanism for Teliva to overlay errors
while apps run. Might make sense to make that available to apps as well.
But I'm starting to realize that any app access to the Teliva areas of
the screen is fraught with risk.
2021-12-25 18:55:01 -08:00
Kartik K. Agaram 1e63a579d7 drop stdin/stdout/stderr and Lua default files
This isn't necessarily for sandboxing, but they don't really work right
now in the presence of ncurses, and it seems better to not include
broken stuff. Maybe we can get them to coexist with ncurses down the
road.
2021-12-25 11:35:50 -08:00
Kartik K. Agaram 917646fc9f sandbox: no popen
Again, too difficult to sandbox for now.
2021-12-25 11:04:23 -08:00
Kartik K. Agaram 74f8cd15bb new fork of Lua 5.1
https://www.lua.org
2021-10-22 19:24:44 -07:00