If this is a training service, so customers just need to test different build code and donโt need to perform operations outside of their program (for example, reading or changing the file system), then another option is to allow only the selected subset of instructions. In particular, do not allow any instructions that can make system calls, and only allow limited instructions for transferring control (for example, without returning, branches only for labels defined in the user code, etc.). You can also provide some limited ways to return output, such as calling a library that prints any value in a specific register. Do not allow data to be declared in the text (code) section, as any machine code can be entered as numeric data.
Although I wrote โanother optionโ, this should be in addition to others that other respondents suggested, such as a sandbox.
This method is error prone and, if used, must be carefully and thoroughly developed. For example, some assemblers allow multiple instructions on the same line. Thus, just ensuring that the text in the first field of the line instruction is acceptable, skip the remaining instructions in the line.
Eric Postpischil
source share