Untrusted environment: Difference between revisions
Content deleted Content added
+J |
|||
Line 3: | Line 3: | ||
The intention is that the definition is to be interpreted broadly; different languages will solve this task in very different ways and with (generally) incomparable results. |
The intention is that the definition is to be interpreted broadly; different languages will solve this task in very different ways and with (generally) incomparable results. |
||
=={{header|J}}== |
|||
J has some security mechanisms built in, and they are detailed below. But to understand their scope (and limitations), it's probably helpful to provide some context first. |
|||
J is a [[wp:Function-level programming|function-level]] language, expressed with composition of primitive words, like <tt>+</tt> for plus and <tt>!</tt> for factorial and <tt>@</tt> for function-composition and <tt>/</tt> for reduce, etc. |
|||
Because J is also (mostly) [[wp:Functional programming|functional]], almost all of these primitive words are also "native": that is, they stay within the bounds of the execution environment, and cannot reach outside of it to the host system. They cannot even effect J's own memory space, except through assigning variables. |
|||
In fact, there is only one word which reach outside the execution environment (the functional scope of the program): '''<tt>!:</tt>''', the aptly named "foreign" operator. This one operator encapsulates all access to the outside world, and even the "behind the scenes world" of J's own memory space. |
|||
The operator takes two arguments and derives a function, which specifies which kind of foreign interface you want. For example, <tt>1'''!:'''1</tt> is the specific function to read a file, and <tt>1'''!:'''2</tt> is the function to write one (as in <tt>1'''!:'''1 'filename'</tt> and <tt>some_data 1'''!:'''2 'filename'</tt>, respectively). The foreign function <tt>15'''!:'''0</tt> allows the J programmer to call a shared library (dll, so, dylib, etc), <tt>2'''!:'''5</tt> reads environment variables (e.g. <tt>2'''!:'''5'PATH'</tt>), and <tt>2'''!:'''55</tt> will terminate the program (quit, die: the mnemonic is that <tt>255</tt> is the "last" value of a byte, and <tt>2'''!:'''55</tt> is the "last" thing you want to do in a J program). |
|||
But the key thing is that this one operator, <tt>'''!:'''</tt> controls all the dangerous stuff, so if we want to prevent dangerous stuff, we only have to put guards in one place. And, in fact, we have "foreign controls": foreign functions which themselves control which foreign functions are allowed. In other words, there's only one "door" to J, and we can lock it. |
|||
From the J documentation: |
|||
:<tt>9'''!:'''25 y</tt> '''Security Level''': The security level is either <tt>0</tt> or <tt>1</tt>. It is initially <tt>0</tt>, and may be set to <tt>1</tt> (and can not be reset to <tt>0</tt>). When the security level is <tt>1</tt>, executing Window driver commands and certain foreigns (<tt>'''!:'''</tt>) that can alter the external state cause a ''“security violation”'' error to be signalled. The following foreigns are prohibited: dyads <tt>0'''!:'''n</tt> , <tt>1'''!:'''n</tt> except <tt>1'''!:'''40</tt> , <tt>1'''!:'''41</tt>, and <tt>1'''!:'''42</tt> , <tt>2'''!:'''n</tt> , and <tt>16'''!:'''n</tt> . |
|||
There are further foreign controls on how much space, or time, a single execution is allowed to take: |
|||
:<tt>9'''!:'''33 y</tt> '''Execution Time Limit''': The execution time limit is a single non-negative (possibly non-integral) number of seconds. The limit is reduced for every line of immediate execution that exceeds a minimum granularity, and execution is interrupted with a ''“time limit error”'' if a non-zero limit is set and goes to 0. |
|||
:<tt>9'''!:'''21 y</tt> '''Memory Limit''': An upper bound on the size of any one memory allocation. The memory limit is initially <tt>2^30</tt> on 32-bit systems and <tt>2^62</tt> on 64-bit systems. |
|||
With all that said, the language has seen limited use in contexts where code injection is a concern, so these mechanisms are rarely exercised (and somewhat [[J:System/Interpreter/Bugs#security_level_out_of_date|dated]]). |
|||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |